Salome HOME
Increment version number (prepare SALOME version 7.0.0)
[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     # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2517     # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2518
2519     def GetPointState(self, x, y, z):
2520         return self.editor.GetPointState(x, y, z)
2521
2522     ## Finds the node closest to a point and moves it to a point location
2523     #  @param x  the X coordinate of a point
2524     #  @param y  the Y coordinate of a point
2525     #  @param z  the Z coordinate of a point
2526     #  @return the ID of a moved node
2527     #  @ingroup l2_modif_throughp
2528     def MeshToPassThroughAPoint(self, x, y, z):
2529         return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2530
2531     ## Replaces two neighbour triangles sharing Node1-Node2 link
2532     #  with the triangles built on the same 4 nodes but having other common link.
2533     #  @param NodeID1  the ID of the first node
2534     #  @param NodeID2  the ID of the second node
2535     #  @return false if proper faces were not found
2536     #  @ingroup l2_modif_invdiag
2537     def InverseDiag(self, NodeID1, NodeID2):
2538         return self.editor.InverseDiag(NodeID1, NodeID2)
2539
2540     ## Replaces two neighbour triangles sharing Node1-Node2 link
2541     #  with a quadrangle built on the same 4 nodes.
2542     #  @param NodeID1  the ID of the first node
2543     #  @param NodeID2  the ID of the second node
2544     #  @return false if proper faces were not found
2545     #  @ingroup l2_modif_unitetri
2546     def DeleteDiag(self, NodeID1, NodeID2):
2547         return self.editor.DeleteDiag(NodeID1, NodeID2)
2548
2549     ## Reorients elements by ids
2550     #  @param IDsOfElements if undefined reorients all mesh elements
2551     #  @return True if succeed else False
2552     #  @ingroup l2_modif_changori
2553     def Reorient(self, IDsOfElements=None):
2554         if IDsOfElements == None:
2555             IDsOfElements = self.GetElementsId()
2556         return self.editor.Reorient(IDsOfElements)
2557
2558     ## Reorients all elements of the object
2559     #  @param theObject mesh, submesh or group
2560     #  @return True if succeed else False
2561     #  @ingroup l2_modif_changori
2562     def ReorientObject(self, theObject):
2563         if ( isinstance( theObject, Mesh )):
2564             theObject = theObject.GetMesh()
2565         return self.editor.ReorientObject(theObject)
2566
2567     ## Reorient faces contained in \a the2DObject.
2568     #  @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2569     #  @param theDirection is a desired direction of normal of \a theFace.
2570     #         It can be either a GEOM vector or a list of coordinates [x,y,z].
2571     #  @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2572     #         compared with theDirection. It can be either ID of face or a point
2573     #         by which the face will be found. The point can be given as either
2574     #         a GEOM vertex or a list of point coordinates.
2575     #  @return number of reoriented faces
2576     #  @ingroup l2_modif_changori
2577     def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2578         # check the2DObject
2579         if isinstance( the2DObject, Mesh ):
2580             the2DObject = the2DObject.GetMesh()
2581         if isinstance( the2DObject, list ):
2582             the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2583         # check theDirection
2584         if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2585             theDirection = self.smeshpyD.GetDirStruct( theDirection )
2586         if isinstance( theDirection, list ):
2587             theDirection = self.smeshpyD.MakeDirStruct( *theDirection  )
2588         # prepare theFace and thePoint
2589         theFace = theFaceOrPoint
2590         thePoint = PointStruct(0,0,0)
2591         if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2592             thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2593             theFace = -1
2594         if isinstance( theFaceOrPoint, list ):
2595             thePoint = PointStruct( *theFaceOrPoint )
2596             theFace = -1
2597         if isinstance( theFaceOrPoint, PointStruct ):
2598             thePoint = theFaceOrPoint
2599             theFace = -1
2600         return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2601
2602     ## Fuses the neighbouring triangles into quadrangles.
2603     #  @param IDsOfElements The triangles to be fused,
2604     #  @param theCriterion  is FT_...; used to choose a neighbour to fuse with.
2605     #  @param MaxAngle      is the maximum angle between element normals at which the fusion
2606     #                       is still performed; theMaxAngle is mesured in radians.
2607     #                       Also it could be a name of variable which defines angle in degrees.
2608     #  @return TRUE in case of success, FALSE otherwise.
2609     #  @ingroup l2_modif_unitetri
2610     def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2611         flag = False
2612         if isinstance(MaxAngle,str):
2613             flag = True
2614         MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2615         self.mesh.SetParameters(Parameters)
2616         if not IDsOfElements:
2617             IDsOfElements = self.GetElementsId()
2618         Functor = 0
2619         if ( isinstance( theCriterion, SMESH._objref_NumericalFunctor ) ):
2620             Functor = theCriterion
2621         else:
2622             Functor = self.smeshpyD.GetFunctor(theCriterion)
2623         return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2624
2625     ## Fuses the neighbouring triangles of the object into quadrangles
2626     #  @param theObject is mesh, submesh or group
2627     #  @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2628     #  @param MaxAngle   a max angle between element normals at which the fusion
2629     #                   is still performed; theMaxAngle is mesured in radians.
2630     #  @return TRUE in case of success, FALSE otherwise.
2631     #  @ingroup l2_modif_unitetri
2632     def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2633         MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2634         self.mesh.SetParameters(Parameters)
2635         if ( isinstance( theObject, Mesh )):
2636             theObject = theObject.GetMesh()
2637         return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2638
2639     ## Splits quadrangles into triangles.
2640     #  @param IDsOfElements the faces to be splitted.
2641     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
2642     #  @return TRUE in case of success, FALSE otherwise.
2643     #  @ingroup l2_modif_cutquadr
2644     def QuadToTri (self, IDsOfElements, theCriterion):
2645         if IDsOfElements == []:
2646             IDsOfElements = self.GetElementsId()
2647         return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2648
2649     ## Splits quadrangles into triangles.
2650     #  @param theObject  the object from which the list of elements is taken, this is mesh, submesh or group
2651     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
2652     #  @return TRUE in case of success, FALSE otherwise.
2653     #  @ingroup l2_modif_cutquadr
2654     def QuadToTriObject (self, theObject, theCriterion):
2655         if ( isinstance( theObject, Mesh )):
2656             theObject = theObject.GetMesh()
2657         return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2658
2659     ## Splits quadrangles into triangles.
2660     #  @param IDsOfElements the faces to be splitted
2661     #  @param Diag13        is used to choose a diagonal for splitting.
2662     #  @return TRUE in case of success, FALSE otherwise.
2663     #  @ingroup l2_modif_cutquadr
2664     def SplitQuad (self, IDsOfElements, Diag13):
2665         if IDsOfElements == []:
2666             IDsOfElements = self.GetElementsId()
2667         return self.editor.SplitQuad(IDsOfElements, Diag13)
2668
2669     ## Splits quadrangles into triangles.
2670     #  @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2671     #  @param Diag13    is used to choose a diagonal for splitting.
2672     #  @return TRUE in case of success, FALSE otherwise.
2673     #  @ingroup l2_modif_cutquadr
2674     def SplitQuadObject (self, theObject, Diag13):
2675         if ( isinstance( theObject, Mesh )):
2676             theObject = theObject.GetMesh()
2677         return self.editor.SplitQuadObject(theObject, Diag13)
2678
2679     ## Finds a better splitting of the given quadrangle.
2680     #  @param IDOfQuad   the ID of the quadrangle to be splitted.
2681     #  @param theCriterion  FT_...; a criterion to choose a diagonal for splitting.
2682     #  @return 1 if 1-3 diagonal is better, 2 if 2-4
2683     #          diagonal is better, 0 if error occurs.
2684     #  @ingroup l2_modif_cutquadr
2685     def BestSplit (self, IDOfQuad, theCriterion):
2686         return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2687
2688     ## Splits volumic elements into tetrahedrons
2689     #  @param elemIDs either list of elements or mesh or group or submesh
2690     #  @param method  flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2691     #         Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2692     #  @ingroup l2_modif_cutquadr
2693     def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2694         if isinstance( elemIDs, Mesh ):
2695             elemIDs = elemIDs.GetMesh()
2696         if ( isinstance( elemIDs, list )):
2697             elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2698         self.editor.SplitVolumesIntoTetra(elemIDs, method)
2699
2700     ## Splits quadrangle faces near triangular facets of volumes
2701     #
2702     #  @ingroup l1_auxiliary
2703     def SplitQuadsNearTriangularFacets(self):
2704         faces_array = self.GetElementsByType(SMESH.FACE)
2705         for face_id in faces_array:
2706             if self.GetElemNbNodes(face_id) == 4: # quadrangle
2707                 quad_nodes = self.mesh.GetElemNodes(face_id)
2708                 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2709                 isVolumeFound = False
2710                 for node1_elem in node1_elems:
2711                     if not isVolumeFound:
2712                         if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2713                             nb_nodes = self.GetElemNbNodes(node1_elem)
2714                             if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2715                                 volume_elem = node1_elem
2716                                 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2717                                 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2718                                     if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2719                                         isVolumeFound = True
2720                                         if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2721                                             self.SplitQuad([face_id], False) # diagonal 2-4
2722                                     elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2723                                         isVolumeFound = True
2724                                         self.SplitQuad([face_id], True) # diagonal 1-3
2725                                 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2726                                     if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2727                                         isVolumeFound = True
2728                                         self.SplitQuad([face_id], True) # diagonal 1-3
2729
2730     ## @brief Splits hexahedrons into tetrahedrons.
2731     #
2732     #  This operation uses pattern mapping functionality for splitting.
2733     #  @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2734     #  @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2735     #         pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2736     #         will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2737     #         key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2738     #         The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2739     #  @return TRUE in case of success, FALSE otherwise.
2740     #  @ingroup l1_auxiliary
2741     def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2742         # Pattern:     5.---------.6
2743         #              /|#*      /|
2744         #             / | #*    / |
2745         #            /  |  # * /  |
2746         #           /   |   # /*  |
2747         # (0,0,1) 4.---------.7 * |
2748         #          |#*  |1   | # *|
2749         #          | # *.----|---#.2
2750         #          |  #/ *   |   /
2751         #          |  /#  *  |  /
2752         #          | /   # * | /
2753         #          |/      #*|/
2754         # (0,0,0) 0.---------.3
2755         pattern_tetra = "!!! Nb of points: \n 8 \n\
2756         !!! Points: \n\
2757         0 0 0  !- 0 \n\
2758         0 1 0  !- 1 \n\
2759         1 1 0  !- 2 \n\
2760         1 0 0  !- 3 \n\
2761         0 0 1  !- 4 \n\
2762         0 1 1  !- 5 \n\
2763         1 1 1  !- 6 \n\
2764         1 0 1  !- 7 \n\
2765         !!! Indices of points of 6 tetras: \n\
2766         0 3 4 1 \n\
2767         7 4 3 1 \n\
2768         4 7 5 1 \n\
2769         6 2 5 7 \n\
2770         1 5 2 7 \n\
2771         2 3 1 7 \n"
2772
2773         pattern = self.smeshpyD.GetPattern()
2774         isDone  = pattern.LoadFromFile(pattern_tetra)
2775         if not isDone:
2776             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2777             return isDone
2778
2779         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2780         isDone = pattern.MakeMesh(self.mesh, False, False)
2781         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2782
2783         # split quafrangle faces near triangular facets of volumes
2784         self.SplitQuadsNearTriangularFacets()
2785
2786         return isDone
2787
2788     ## @brief Split hexahedrons into prisms.
2789     #
2790     #  Uses the pattern mapping functionality for splitting.
2791     #  @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2792     #  @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2793     #         pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2794     #         will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2795     #         will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2796     #         Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2797     #  @return TRUE in case of success, FALSE otherwise.
2798     #  @ingroup l1_auxiliary
2799     def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2800         # Pattern:     5.---------.6
2801         #              /|#       /|
2802         #             / | #     / |
2803         #            /  |  #   /  |
2804         #           /   |   # /   |
2805         # (0,0,1) 4.---------.7   |
2806         #          |    |    |    |
2807         #          |   1.----|----.2
2808         #          |   / *   |   /
2809         #          |  /   *  |  /
2810         #          | /     * | /
2811         #          |/       *|/
2812         # (0,0,0) 0.---------.3
2813         pattern_prism = "!!! Nb of points: \n 8 \n\
2814         !!! Points: \n\
2815         0 0 0  !- 0 \n\
2816         0 1 0  !- 1 \n\
2817         1 1 0  !- 2 \n\
2818         1 0 0  !- 3 \n\
2819         0 0 1  !- 4 \n\
2820         0 1 1  !- 5 \n\
2821         1 1 1  !- 6 \n\
2822         1 0 1  !- 7 \n\
2823         !!! Indices of points of 2 prisms: \n\
2824         0 1 3 4 5 7 \n\
2825         2 3 1 6 7 5 \n"
2826
2827         pattern = self.smeshpyD.GetPattern()
2828         isDone  = pattern.LoadFromFile(pattern_prism)
2829         if not isDone:
2830             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2831             return isDone
2832
2833         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2834         isDone = pattern.MakeMesh(self.mesh, False, False)
2835         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2836
2837         # Splits quafrangle faces near triangular facets of volumes
2838         self.SplitQuadsNearTriangularFacets()
2839
2840         return isDone
2841
2842     ## Smoothes elements
2843     #  @param IDsOfElements the list if ids of elements to smooth
2844     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2845     #  Note that nodes built on edges and boundary nodes are always fixed.
2846     #  @param MaxNbOfIterations the maximum number of iterations
2847     #  @param MaxAspectRatio varies in range [1.0, inf]
2848     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2849     #  @return TRUE in case of success, FALSE otherwise.
2850     #  @ingroup l2_modif_smooth
2851     def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2852                MaxNbOfIterations, MaxAspectRatio, Method):
2853         if IDsOfElements == []:
2854             IDsOfElements = self.GetElementsId()
2855         MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2856         self.mesh.SetParameters(Parameters)
2857         return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2858                                   MaxNbOfIterations, MaxAspectRatio, Method)
2859
2860     ## Smoothes elements which belong to the given object
2861     #  @param theObject the object to smooth
2862     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2863     #  Note that nodes built on edges and boundary nodes are always fixed.
2864     #  @param MaxNbOfIterations the maximum number of iterations
2865     #  @param MaxAspectRatio varies in range [1.0, inf]
2866     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2867     #  @return TRUE in case of success, FALSE otherwise.
2868     #  @ingroup l2_modif_smooth
2869     def SmoothObject(self, theObject, IDsOfFixedNodes,
2870                      MaxNbOfIterations, MaxAspectRatio, Method):
2871         if ( isinstance( theObject, Mesh )):
2872             theObject = theObject.GetMesh()
2873         return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2874                                         MaxNbOfIterations, MaxAspectRatio, Method)
2875
2876     ## Parametrically smoothes the given elements
2877     #  @param IDsOfElements the list if ids of elements to smooth
2878     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2879     #  Note that nodes built on edges and boundary nodes are always fixed.
2880     #  @param MaxNbOfIterations the maximum number of iterations
2881     #  @param MaxAspectRatio varies in range [1.0, inf]
2882     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2883     #  @return TRUE in case of success, FALSE otherwise.
2884     #  @ingroup l2_modif_smooth
2885     def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2886                          MaxNbOfIterations, MaxAspectRatio, Method):
2887         if IDsOfElements == []:
2888             IDsOfElements = self.GetElementsId()
2889         MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2890         self.mesh.SetParameters(Parameters)
2891         return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2892                                             MaxNbOfIterations, MaxAspectRatio, Method)
2893
2894     ## Parametrically smoothes the elements which belong to the given object
2895     #  @param theObject the object to smooth
2896     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2897     #  Note that nodes built on edges and boundary nodes are always fixed.
2898     #  @param MaxNbOfIterations the maximum number of iterations
2899     #  @param MaxAspectRatio varies in range [1.0, inf]
2900     #  @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2901     #  @return TRUE in case of success, FALSE otherwise.
2902     #  @ingroup l2_modif_smooth
2903     def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2904                                MaxNbOfIterations, MaxAspectRatio, Method):
2905         if ( isinstance( theObject, Mesh )):
2906             theObject = theObject.GetMesh()
2907         return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2908                                                   MaxNbOfIterations, MaxAspectRatio, Method)
2909
2910     ## Converts the mesh to quadratic, deletes old elements, replacing
2911     #  them with quadratic with the same id.
2912     #  @param theForce3d new node creation method:
2913     #         0 - the medium node lies at the geometrical entity from which the mesh element is built
2914     #         1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2915     #  @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2916     #  @ingroup l2_modif_tofromqu
2917     def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2918         if theSubMesh:
2919             self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2920         else:
2921             self.editor.ConvertToQuadratic(theForce3d)
2922
2923     ## Converts the mesh from quadratic to ordinary,
2924     #  deletes old quadratic elements, \n replacing
2925     #  them with ordinary mesh elements with the same id.
2926     #  @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2927     #  @ingroup l2_modif_tofromqu
2928     def ConvertFromQuadratic(self, theSubMesh=None):
2929         if theSubMesh:
2930             self.editor.ConvertFromQuadraticObject(theSubMesh)
2931         else:
2932             return self.editor.ConvertFromQuadratic()
2933
2934     ## Creates 2D mesh as skin on boundary faces of a 3D mesh
2935     #  @return TRUE if operation has been completed successfully, FALSE otherwise
2936     #  @ingroup l2_modif_edit
2937     def  Make2DMeshFrom3D(self):
2938         return self.editor. Make2DMeshFrom3D()
2939
2940     ## Creates missing boundary elements
2941     #  @param elements - elements whose boundary is to be checked:
2942     #                    mesh, group, sub-mesh or list of elements
2943     #   if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
2944     #  @param dimension - defines type of boundary elements to create:
2945     #                     SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
2946     #    SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
2947     #  @param groupName - a name of group to store created boundary elements in,
2948     #                     "" means not to create the group
2949     #  @param meshName - a name of new mesh to store created boundary elements in,
2950     #                     "" means not to create the new mesh
2951     #  @param toCopyElements - if true, the checked elements will be copied into
2952     #     the new mesh else only boundary elements will be copied into the new mesh
2953     #  @param toCopyExistingBondary - if true, not only new but also pre-existing
2954     #     boundary elements will be copied into the new mesh
2955     #  @return tuple (mesh, group) where bondary elements were added to
2956     #  @ingroup l2_modif_edit
2957     def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
2958                          toCopyElements=False, toCopyExistingBondary=False):
2959         if isinstance( elements, Mesh ):
2960             elements = elements.GetMesh()
2961         if ( isinstance( elements, list )):
2962             elemType = SMESH.ALL
2963             if elements: elemType = self.GetElementType( elements[0], iselem=True)
2964             elements = self.editor.MakeIDSource(elements, elemType)
2965         mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
2966                                                    toCopyElements,toCopyExistingBondary)
2967         if mesh: mesh = self.smeshpyD.Mesh(mesh)
2968         return mesh, group
2969
2970     ##
2971     # @brief Creates missing boundary elements around either the whole mesh or 
2972     #    groups of 2D elements
2973     #  @param dimension - defines type of boundary elements to create
2974     #  @param groupName - a name of group to store all boundary elements in,
2975     #    "" means not to create the group
2976     #  @param meshName - a name of a new mesh, which is a copy of the initial 
2977     #    mesh + created boundary elements; "" means not to create the new mesh
2978     #  @param toCopyAll - if true, the whole initial mesh will be copied into
2979     #    the new mesh else only boundary elements will be copied into the new mesh
2980     #  @param groups - groups of 2D elements to make boundary around
2981     #  @retval tuple( long, mesh, groups )
2982     #                 long - number of added boundary elements
2983     #                 mesh - the mesh where elements were added to
2984     #                 group - the group of boundary elements or None
2985     #
2986     def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
2987                              toCopyAll=False, groups=[]):
2988         nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
2989                                                            toCopyAll,groups)
2990         if mesh: mesh = self.smeshpyD.Mesh(mesh)
2991         return nb, mesh, group
2992
2993     ## Renumber mesh nodes
2994     #  @ingroup l2_modif_renumber
2995     def RenumberNodes(self):
2996         self.editor.RenumberNodes()
2997
2998     ## Renumber mesh elements
2999     #  @ingroup l2_modif_renumber
3000     def RenumberElements(self):
3001         self.editor.RenumberElements()
3002
3003     ## Generates new elements by rotation of the elements around the axis
3004     #  @param IDsOfElements the list of ids of elements to sweep
3005     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3006     #  @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3007     #  @param NbOfSteps the number of steps
3008     #  @param Tolerance tolerance
3009     #  @param MakeGroups forces the generation of new groups from existing ones
3010     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3011     #                    of all steps, else - size of each step
3012     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3013     #  @ingroup l2_modif_extrurev
3014     def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3015                       MakeGroups=False, TotalAngle=False):
3016         if IDsOfElements == []:
3017             IDsOfElements = self.GetElementsId()
3018         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3019             Axis = self.smeshpyD.GetAxisStruct(Axis)
3020         AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3021         NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3022         Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3023         self.mesh.SetParameters(Parameters)
3024         if TotalAngle and NbOfSteps:
3025             AngleInRadians /= NbOfSteps
3026         if MakeGroups:
3027             return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3028                                                        AngleInRadians, NbOfSteps, Tolerance)
3029         self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3030         return []
3031
3032     ## Generates new elements by rotation of the elements of object around the axis
3033     #  @param theObject object which elements should be sweeped.
3034     #                   It can be a mesh, a sub mesh or a group.
3035     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3036     #  @param AngleInRadians the angle of Rotation
3037     #  @param NbOfSteps number of steps
3038     #  @param Tolerance tolerance
3039     #  @param MakeGroups forces the generation of new groups from existing ones
3040     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3041     #                    of all steps, else - size of each step
3042     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3043     #  @ingroup l2_modif_extrurev
3044     def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3045                             MakeGroups=False, TotalAngle=False):
3046         if ( isinstance( theObject, Mesh )):
3047             theObject = theObject.GetMesh()
3048         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3049             Axis = self.smeshpyD.GetAxisStruct(Axis)
3050         AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3051         NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3052         Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3053         self.mesh.SetParameters(Parameters)
3054         if TotalAngle and NbOfSteps:
3055             AngleInRadians /= NbOfSteps
3056         if MakeGroups:
3057             return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3058                                                              NbOfSteps, Tolerance)
3059         self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3060         return []
3061
3062     ## Generates new elements by rotation of the elements of object around the axis
3063     #  @param theObject object which elements should be sweeped.
3064     #                   It can be a mesh, a sub mesh or a group.
3065     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3066     #  @param AngleInRadians the angle of Rotation
3067     #  @param NbOfSteps number of steps
3068     #  @param Tolerance tolerance
3069     #  @param MakeGroups forces the generation of new groups from existing ones
3070     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3071     #                    of all steps, else - size of each step
3072     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3073     #  @ingroup l2_modif_extrurev
3074     def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3075                               MakeGroups=False, TotalAngle=False):
3076         if ( isinstance( theObject, Mesh )):
3077             theObject = theObject.GetMesh()
3078         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3079             Axis = self.smeshpyD.GetAxisStruct(Axis)
3080         AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3081         NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3082         Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3083         self.mesh.SetParameters(Parameters)
3084         if TotalAngle and NbOfSteps:
3085             AngleInRadians /= NbOfSteps
3086         if MakeGroups:
3087             return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3088                                                                NbOfSteps, Tolerance)
3089         self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3090         return []
3091
3092     ## Generates new elements by rotation of the elements of object around the axis
3093     #  @param theObject object which elements should be sweeped.
3094     #                   It can be a mesh, a sub mesh or a group.
3095     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3096     #  @param AngleInRadians the angle of Rotation
3097     #  @param NbOfSteps number of steps
3098     #  @param Tolerance tolerance
3099     #  @param MakeGroups forces the generation of new groups from existing ones
3100     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3101     #                    of all steps, else - size of each step
3102     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3103     #  @ingroup l2_modif_extrurev
3104     def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3105                               MakeGroups=False, TotalAngle=False):
3106         if ( isinstance( theObject, Mesh )):
3107             theObject = theObject.GetMesh()
3108         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3109             Axis = self.smeshpyD.GetAxisStruct(Axis)
3110         AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3111         NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3112         Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3113         self.mesh.SetParameters(Parameters)
3114         if TotalAngle and NbOfSteps:
3115             AngleInRadians /= NbOfSteps
3116         if MakeGroups:
3117             return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3118                                                              NbOfSteps, Tolerance)
3119         self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3120         return []
3121
3122     ## Generates new elements by extrusion of the elements with given ids
3123     #  @param IDsOfElements the list of elements ids for extrusion
3124     #  @param StepVector vector or DirStruct, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3125     #  @param NbOfSteps the number of steps
3126     #  @param MakeGroups forces the generation of new groups from existing ones
3127     #  @param IsNodes is True if elements with given ids are nodes
3128     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3129     #  @ingroup l2_modif_extrurev
3130     def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3131         if IDsOfElements == []:
3132             IDsOfElements = self.GetElementsId()
3133         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3134             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3135         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3136         Parameters = StepVector.PS.parameters + var_separator + Parameters
3137         self.mesh.SetParameters(Parameters)
3138         if MakeGroups:
3139             if(IsNodes):
3140                 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3141             else:
3142                 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3143         if(IsNodes):
3144             self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3145         else:
3146             self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3147         return []
3148
3149     ## Generates new elements by extrusion of the elements with given ids
3150     #  @param IDsOfElements is ids of elements
3151     #  @param StepVector vector, defining the direction and value of extrusion
3152     #  @param NbOfSteps the number of steps
3153     #  @param ExtrFlags sets flags for extrusion
3154     #  @param SewTolerance uses for comparing locations of nodes if flag
3155     #         EXTRUSION_FLAG_SEW is set
3156     #  @param MakeGroups forces the generation of new groups from existing ones
3157     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3158     #  @ingroup l2_modif_extrurev
3159     def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3160                           ExtrFlags, SewTolerance, MakeGroups=False):
3161         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3162             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3163         if MakeGroups:
3164             return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3165                                                            ExtrFlags, SewTolerance)
3166         self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3167                                       ExtrFlags, SewTolerance)
3168         return []
3169
3170     ## Generates new elements by extrusion of the elements which belong to the object
3171     #  @param theObject the object which elements should be processed.
3172     #                   It can be a mesh, a sub mesh or a group.
3173     #  @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3174     #  @param NbOfSteps the number of steps
3175     #  @param MakeGroups forces the generation of new groups from existing ones
3176     #  @param  IsNodes is True if elements which belong to the object are nodes
3177     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3178     #  @ingroup l2_modif_extrurev
3179     def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3180         if ( isinstance( theObject, Mesh )):
3181             theObject = theObject.GetMesh()
3182         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3183             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3184         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3185         Parameters = StepVector.PS.parameters + var_separator + Parameters
3186         self.mesh.SetParameters(Parameters)
3187         if MakeGroups:
3188             if(IsNodes):
3189                 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3190             else:
3191                 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3192         if(IsNodes):
3193             self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3194         else:
3195             self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3196         return []
3197
3198     ## Generates new elements by extrusion of the elements which belong to the object
3199     #  @param theObject object which elements should be processed.
3200     #                   It can be a mesh, a sub mesh or a group.
3201     #  @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3202     #  @param NbOfSteps the number of steps
3203     #  @param MakeGroups to generate new groups from existing ones
3204     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3205     #  @ingroup l2_modif_extrurev
3206     def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3207         if ( isinstance( theObject, Mesh )):
3208             theObject = theObject.GetMesh()
3209         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3210             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3211         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3212         Parameters = StepVector.PS.parameters + var_separator + Parameters
3213         self.mesh.SetParameters(Parameters)
3214         if MakeGroups:
3215             return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3216         self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3217         return []
3218
3219     ## Generates new elements by extrusion of the elements which belong to the object
3220     #  @param theObject object which elements should be processed.
3221     #                   It can be a mesh, a sub mesh or a group.
3222     #  @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3223     #  @param NbOfSteps the number of steps
3224     #  @param MakeGroups forces the generation of new groups from existing ones
3225     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3226     #  @ingroup l2_modif_extrurev
3227     def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3228         if ( isinstance( theObject, Mesh )):
3229             theObject = theObject.GetMesh()
3230         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3231             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3232         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3233         Parameters = StepVector.PS.parameters + var_separator + Parameters
3234         self.mesh.SetParameters(Parameters)
3235         if MakeGroups:
3236             return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3237         self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3238         return []
3239
3240
3241
3242     ## Generates new elements by extrusion of the given elements
3243     #  The path of extrusion must be a meshed edge.
3244     #  @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3245     #  @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3246     #  @param NodeStart the start node from Path. Defines the direction of extrusion
3247     #  @param HasAngles allows the shape to be rotated around the path
3248     #                   to get the resulting mesh in a helical fashion
3249     #  @param Angles list of angles in radians
3250     #  @param LinearVariation forces the computation of rotation angles as linear
3251     #                         variation of the given Angles along path steps
3252     #  @param HasRefPoint allows using the reference point
3253     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3254     #         The User can specify any point as the Reference Point.
3255     #  @param MakeGroups forces the generation of new groups from existing ones
3256     #  @param ElemType type of elements for extrusion (if param Base is a mesh)
3257     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3258     #          only SMESH::Extrusion_Error otherwise
3259     #  @ingroup l2_modif_extrurev
3260     def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3261                             HasAngles, Angles, LinearVariation,
3262                             HasRefPoint, RefPoint, MakeGroups, ElemType):
3263         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3264             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3265             pass
3266         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3267         Parameters = AnglesParameters + var_separator + RefPoint.parameters
3268         self.mesh.SetParameters(Parameters)
3269
3270         if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3271
3272         if isinstance(Base, list):
3273             IDsOfElements = []
3274             if Base == []: IDsOfElements = self.GetElementsId()
3275             else: IDsOfElements = Base
3276             return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3277                                                    HasAngles, Angles, LinearVariation,
3278                                                    HasRefPoint, RefPoint, MakeGroups, ElemType)
3279         else:
3280             if isinstance(Base, Mesh): Base = Base.GetMesh()
3281             if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3282                 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3283                                                           HasAngles, Angles, LinearVariation,
3284                                                           HasRefPoint, RefPoint, MakeGroups, ElemType)
3285             else:
3286                 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3287
3288
3289     ## Generates new elements by extrusion of the given elements
3290     #  The path of extrusion must be a meshed edge.
3291     #  @param IDsOfElements ids of elements
3292     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3293     #  @param PathShape shape(edge) defines the sub-mesh for the path
3294     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3295     #  @param HasAngles allows the shape to be rotated around the path
3296     #                   to get the resulting mesh in a helical fashion
3297     #  @param Angles list of angles in radians
3298     #  @param HasRefPoint allows using the reference point
3299     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3300     #         The User can specify any point as the Reference Point.
3301     #  @param MakeGroups forces the generation of new groups from existing ones
3302     #  @param LinearVariation forces the computation of rotation angles as linear
3303     #                         variation of the given Angles along path steps
3304     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3305     #          only SMESH::Extrusion_Error otherwise
3306     #  @ingroup l2_modif_extrurev
3307     def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3308                            HasAngles, Angles, HasRefPoint, RefPoint,
3309                            MakeGroups=False, LinearVariation=False):
3310         if IDsOfElements == []:
3311             IDsOfElements = self.GetElementsId()
3312         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3313             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3314             pass
3315         if ( isinstance( PathMesh, Mesh )):
3316             PathMesh = PathMesh.GetMesh()
3317         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3318         Parameters = AnglesParameters + var_separator + RefPoint.parameters
3319         self.mesh.SetParameters(Parameters)
3320         if HasAngles and Angles and LinearVariation:
3321             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3322             pass
3323         if MakeGroups:
3324             return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3325                                                             PathShape, NodeStart, HasAngles,
3326                                                             Angles, HasRefPoint, RefPoint)
3327         return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3328                                               NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3329
3330     ## Generates new elements by extrusion of the elements which belong to the object
3331     #  The path of extrusion must be a meshed edge.
3332     #  @param theObject the object which elements should be processed.
3333     #                   It can be a mesh, a sub mesh or a group.
3334     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3335     #  @param PathShape shape(edge) defines the sub-mesh for the path
3336     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3337     #  @param HasAngles allows the shape to be rotated around the path
3338     #                   to get the resulting mesh in a helical fashion
3339     #  @param Angles list of angles
3340     #  @param HasRefPoint allows using the reference point
3341     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3342     #         The User can specify any point as the Reference Point.
3343     #  @param MakeGroups forces the generation of new groups from existing ones
3344     #  @param LinearVariation forces the computation of rotation angles as linear
3345     #                         variation of the given Angles along path steps
3346     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3347     #          only SMESH::Extrusion_Error otherwise
3348     #  @ingroup l2_modif_extrurev
3349     def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3350                                  HasAngles, Angles, HasRefPoint, RefPoint,
3351                                  MakeGroups=False, LinearVariation=False):
3352         if ( isinstance( theObject, Mesh )):
3353             theObject = theObject.GetMesh()
3354         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3355             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3356         if ( isinstance( PathMesh, Mesh )):
3357             PathMesh = PathMesh.GetMesh()
3358         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3359         Parameters = AnglesParameters + var_separator + RefPoint.parameters
3360         self.mesh.SetParameters(Parameters)
3361         if HasAngles and Angles and LinearVariation:
3362             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3363             pass
3364         if MakeGroups:
3365             return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3366                                                                   PathShape, NodeStart, HasAngles,
3367                                                                   Angles, HasRefPoint, RefPoint)
3368         return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3369                                                     NodeStart, HasAngles, Angles, HasRefPoint,
3370                                                     RefPoint)
3371
3372     ## Generates new elements by extrusion of the elements which belong to the object
3373     #  The path of extrusion must be a meshed edge.
3374     #  @param theObject the object which elements should be processed.
3375     #                   It can be a mesh, a sub mesh or a group.
3376     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3377     #  @param PathShape shape(edge) defines the sub-mesh for the path
3378     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3379     #  @param HasAngles allows the shape to be rotated around the path
3380     #                   to get the resulting mesh in a helical fashion
3381     #  @param Angles list of angles
3382     #  @param HasRefPoint allows using the reference point
3383     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3384     #         The User can specify any point as the Reference Point.
3385     #  @param MakeGroups forces the generation of new groups from existing ones
3386     #  @param LinearVariation forces the computation of rotation angles as linear
3387     #                         variation of the given Angles along path steps
3388     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3389     #          only SMESH::Extrusion_Error otherwise
3390     #  @ingroup l2_modif_extrurev
3391     def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3392                                    HasAngles, Angles, HasRefPoint, RefPoint,
3393                                    MakeGroups=False, LinearVariation=False):
3394         if ( isinstance( theObject, Mesh )):
3395             theObject = theObject.GetMesh()
3396         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3397             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3398         if ( isinstance( PathMesh, Mesh )):
3399             PathMesh = PathMesh.GetMesh()
3400         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3401         Parameters = AnglesParameters + var_separator + RefPoint.parameters
3402         self.mesh.SetParameters(Parameters)
3403         if HasAngles and Angles and LinearVariation:
3404             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3405             pass
3406         if MakeGroups:
3407             return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3408                                                                     PathShape, NodeStart, HasAngles,
3409                                                                     Angles, HasRefPoint, RefPoint)
3410         return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3411                                                       NodeStart, HasAngles, Angles, HasRefPoint,
3412                                                       RefPoint)
3413
3414     ## Generates new elements by extrusion of the elements which belong to the object
3415     #  The path of extrusion must be a meshed edge.
3416     #  @param theObject the object which elements should be processed.
3417     #                   It can be a mesh, a sub mesh or a group.
3418     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3419     #  @param PathShape shape(edge) defines the sub-mesh for the path
3420     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3421     #  @param HasAngles allows the shape to be rotated around the path
3422     #                   to get the resulting mesh in a helical fashion
3423     #  @param Angles list of angles
3424     #  @param HasRefPoint allows using the reference point
3425     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3426     #         The User can specify any point as the Reference Point.
3427     #  @param MakeGroups forces the generation of new groups from existing ones
3428     #  @param LinearVariation forces the computation of rotation angles as linear
3429     #                         variation of the given Angles along path steps
3430     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3431     #          only SMESH::Extrusion_Error otherwise
3432     #  @ingroup l2_modif_extrurev
3433     def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3434                                    HasAngles, Angles, HasRefPoint, RefPoint,
3435                                    MakeGroups=False, LinearVariation=False):
3436         if ( isinstance( theObject, Mesh )):
3437             theObject = theObject.GetMesh()
3438         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3439             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3440         if ( isinstance( PathMesh, Mesh )):
3441             PathMesh = PathMesh.GetMesh()
3442         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3443         Parameters = AnglesParameters + var_separator + RefPoint.parameters
3444         self.mesh.SetParameters(Parameters)
3445         if HasAngles and Angles and LinearVariation:
3446             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3447             pass
3448         if MakeGroups:
3449             return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3450                                                                     PathShape, NodeStart, HasAngles,
3451                                                                     Angles, HasRefPoint, RefPoint)
3452         return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3453                                                       NodeStart, HasAngles, Angles, HasRefPoint,
3454                                                       RefPoint)
3455
3456     ## Creates a symmetrical copy of mesh elements
3457     #  @param IDsOfElements list of elements ids
3458     #  @param Mirror is AxisStruct or geom object(point, line, plane)
3459     #  @param theMirrorType is  POINT, AXIS or PLANE
3460     #  If the Mirror is a geom object this parameter is unnecessary
3461     #  @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3462     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3463     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3464     #  @ingroup l2_modif_trsf
3465     def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3466         if IDsOfElements == []:
3467             IDsOfElements = self.GetElementsId()
3468         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3469             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3470         self.mesh.SetParameters(Mirror.parameters)
3471         if Copy and MakeGroups:
3472             return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3473         self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3474         return []
3475
3476     ## Creates a new mesh by a symmetrical copy of mesh elements
3477     #  @param IDsOfElements the list of elements ids
3478     #  @param Mirror is AxisStruct or geom object (point, line, plane)
3479     #  @param theMirrorType is  POINT, AXIS or PLANE
3480     #  If the Mirror is a geom object this parameter is unnecessary
3481     #  @param MakeGroups to generate new groups from existing ones
3482     #  @param NewMeshName a name of the new mesh to create
3483     #  @return instance of Mesh class
3484     #  @ingroup l2_modif_trsf
3485     def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3486         if IDsOfElements == []:
3487             IDsOfElements = self.GetElementsId()
3488         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3489             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3490         self.mesh.SetParameters(Mirror.parameters)
3491         mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3492                                           MakeGroups, NewMeshName)
3493         return Mesh(self.smeshpyD,self.geompyD,mesh)
3494
3495     ## Creates a symmetrical copy of the object
3496     #  @param theObject mesh, submesh or group
3497     #  @param Mirror AxisStruct or geom object (point, line, plane)
3498     #  @param theMirrorType is  POINT, AXIS or PLANE
3499     #  If the Mirror is a geom object this parameter is unnecessary
3500     #  @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3501     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3502     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3503     #  @ingroup l2_modif_trsf
3504     def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3505         if ( isinstance( theObject, Mesh )):
3506             theObject = theObject.GetMesh()
3507         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3508             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3509         self.mesh.SetParameters(Mirror.parameters)
3510         if Copy and MakeGroups:
3511             return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3512         self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3513         return []
3514
3515     ## Creates a new mesh by a symmetrical copy of the object
3516     #  @param theObject mesh, submesh or group
3517     #  @param Mirror AxisStruct or geom object (point, line, plane)
3518     #  @param theMirrorType POINT, AXIS or PLANE
3519     #  If the Mirror is a geom object this parameter is unnecessary
3520     #  @param MakeGroups forces the generation of new groups from existing ones
3521     #  @param NewMeshName the name of the new mesh to create
3522     #  @return instance of Mesh class
3523     #  @ingroup l2_modif_trsf
3524     def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3525         if ( isinstance( theObject, Mesh )):
3526             theObject = theObject.GetMesh()
3527         if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3528             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3529         self.mesh.SetParameters(Mirror.parameters)
3530         mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3531                                                 MakeGroups, NewMeshName)
3532         return Mesh( self.smeshpyD,self.geompyD,mesh )
3533
3534     ## Translates the elements
3535     #  @param IDsOfElements list of elements ids
3536     #  @param Vector the direction of translation (DirStruct or vector)
3537     #  @param Copy allows copying the translated elements
3538     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3539     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3540     #  @ingroup l2_modif_trsf
3541     def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3542         if IDsOfElements == []:
3543             IDsOfElements = self.GetElementsId()
3544         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3545             Vector = self.smeshpyD.GetDirStruct(Vector)
3546         self.mesh.SetParameters(Vector.PS.parameters)
3547         if Copy and MakeGroups:
3548             return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3549         self.editor.Translate(IDsOfElements, Vector, Copy)
3550         return []
3551
3552     ## Creates a new mesh of translated elements
3553     #  @param IDsOfElements list of elements ids
3554     #  @param Vector the direction of translation (DirStruct or vector)
3555     #  @param MakeGroups forces the generation of new groups from existing ones
3556     #  @param NewMeshName the name of the newly created mesh
3557     #  @return instance of Mesh class
3558     #  @ingroup l2_modif_trsf
3559     def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3560         if IDsOfElements == []:
3561             IDsOfElements = self.GetElementsId()
3562         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3563             Vector = self.smeshpyD.GetDirStruct(Vector)
3564         self.mesh.SetParameters(Vector.PS.parameters)
3565         mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3566         return Mesh ( self.smeshpyD, self.geompyD, mesh )
3567
3568     ## Translates the object
3569     #  @param theObject the object to translate (mesh, submesh, or group)
3570     #  @param Vector direction of translation (DirStruct or geom vector)
3571     #  @param Copy allows copying the translated elements
3572     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3573     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3574     #  @ingroup l2_modif_trsf
3575     def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3576         if ( isinstance( theObject, Mesh )):
3577             theObject = theObject.GetMesh()
3578         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3579             Vector = self.smeshpyD.GetDirStruct(Vector)
3580         self.mesh.SetParameters(Vector.PS.parameters)
3581         if Copy and MakeGroups:
3582             return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3583         self.editor.TranslateObject(theObject, Vector, Copy)
3584         return []
3585
3586     ## Creates a new mesh from the translated object
3587     #  @param theObject the object to translate (mesh, submesh, or group)
3588     #  @param Vector the direction of translation (DirStruct or geom vector)
3589     #  @param MakeGroups forces the generation of new groups from existing ones
3590     #  @param NewMeshName the name of the newly created mesh
3591     #  @return instance of Mesh class
3592     #  @ingroup l2_modif_trsf
3593     def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3594         if (isinstance(theObject, Mesh)):
3595             theObject = theObject.GetMesh()
3596         if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3597             Vector = self.smeshpyD.GetDirStruct(Vector)
3598         self.mesh.SetParameters(Vector.PS.parameters)
3599         mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3600         return Mesh( self.smeshpyD, self.geompyD, mesh )
3601
3602
3603
3604     ## Scales the object
3605     #  @param theObject - the object to translate (mesh, submesh, or group)
3606     #  @param thePoint - base point for scale
3607     #  @param theScaleFact - list of 1-3 scale factors for axises
3608     #  @param Copy - allows copying the translated elements
3609     #  @param MakeGroups - forces the generation of new groups from existing
3610     #                      ones (if Copy)
3611     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3612     #          empty list otherwise
3613     def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3614         if ( isinstance( theObject, Mesh )):
3615             theObject = theObject.GetMesh()
3616         if ( isinstance( theObject, list )):
3617             theObject = self.GetIDSource(theObject, SMESH.ALL)
3618
3619         self.mesh.SetParameters(thePoint.parameters)
3620
3621         if Copy and MakeGroups:
3622             return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3623         self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3624         return []
3625
3626     ## Creates a new mesh from the translated object
3627     #  @param theObject - the object to translate (mesh, submesh, or group)
3628     #  @param thePoint - base point for scale
3629     #  @param theScaleFact - list of 1-3 scale factors for axises
3630     #  @param MakeGroups - forces the generation of new groups from existing ones
3631     #  @param NewMeshName - the name of the newly created mesh
3632     #  @return instance of Mesh class
3633     def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3634         if (isinstance(theObject, Mesh)):
3635             theObject = theObject.GetMesh()
3636         if ( isinstance( theObject, list )):
3637             theObject = self.GetIDSource(theObject,SMESH.ALL)
3638
3639         self.mesh.SetParameters(thePoint.parameters)
3640         mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3641                                          MakeGroups, NewMeshName)
3642         return Mesh( self.smeshpyD, self.geompyD, mesh )
3643
3644
3645
3646     ## Rotates the elements
3647     #  @param IDsOfElements list of elements ids
3648     #  @param Axis the axis of rotation (AxisStruct or geom line)
3649     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3650     #  @param Copy allows copying the rotated elements
3651     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3652     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3653     #  @ingroup l2_modif_trsf
3654     def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3655         if IDsOfElements == []:
3656             IDsOfElements = self.GetElementsId()
3657         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3658             Axis = self.smeshpyD.GetAxisStruct(Axis)
3659         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3660         Parameters = Axis.parameters + var_separator + Parameters
3661         self.mesh.SetParameters(Parameters)
3662         if Copy and MakeGroups:
3663             return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3664         self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3665         return []
3666
3667     ## Creates a new mesh of rotated elements
3668     #  @param IDsOfElements list of element ids
3669     #  @param Axis the axis of rotation (AxisStruct or geom line)
3670     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3671     #  @param MakeGroups forces the generation of new groups from existing ones
3672     #  @param NewMeshName the name of the newly created mesh
3673     #  @return instance of Mesh class
3674     #  @ingroup l2_modif_trsf
3675     def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3676         if IDsOfElements == []:
3677             IDsOfElements = self.GetElementsId()
3678         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3679             Axis = self.smeshpyD.GetAxisStruct(Axis)
3680         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3681         Parameters = Axis.parameters + var_separator + Parameters
3682         self.mesh.SetParameters(Parameters)
3683         mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3684                                           MakeGroups, NewMeshName)
3685         return Mesh( self.smeshpyD, self.geompyD, mesh )
3686
3687     ## Rotates the object
3688     #  @param theObject the object to rotate( mesh, submesh, or group)
3689     #  @param Axis the axis of rotation (AxisStruct or geom line)
3690     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3691     #  @param Copy allows copying the rotated elements
3692     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3693     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3694     #  @ingroup l2_modif_trsf
3695     def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3696         if (isinstance(theObject, Mesh)):
3697             theObject = theObject.GetMesh()
3698         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3699             Axis = self.smeshpyD.GetAxisStruct(Axis)
3700         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3701         Parameters = Axis.parameters + ":" + Parameters
3702         self.mesh.SetParameters(Parameters)
3703         if Copy and MakeGroups:
3704             return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3705         self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3706         return []
3707
3708     ## Creates a new mesh from the rotated object
3709     #  @param theObject the object to rotate (mesh, submesh, or group)
3710     #  @param Axis the axis of rotation (AxisStruct or geom line)
3711     #  @param AngleInRadians the angle of rotation (in radians)  or a name of variable which defines angle in degrees
3712     #  @param MakeGroups forces the generation of new groups from existing ones
3713     #  @param NewMeshName the name of the newly created mesh
3714     #  @return instance of Mesh class
3715     #  @ingroup l2_modif_trsf
3716     def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3717         if (isinstance( theObject, Mesh )):
3718             theObject = theObject.GetMesh()
3719         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3720             Axis = self.smeshpyD.GetAxisStruct(Axis)
3721         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3722         Parameters = Axis.parameters + ":" + Parameters
3723         mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3724                                                        MakeGroups, NewMeshName)
3725         self.mesh.SetParameters(Parameters)
3726         return Mesh( self.smeshpyD, self.geompyD, mesh )
3727
3728     ## Finds groups of ajacent nodes within Tolerance.
3729     #  @param Tolerance the value of tolerance
3730     #  @return the list of groups of nodes
3731     #  @ingroup l2_modif_trsf
3732     def FindCoincidentNodes (self, Tolerance):
3733         return self.editor.FindCoincidentNodes(Tolerance)
3734
3735     ## Finds groups of ajacent nodes within Tolerance.
3736     #  @param Tolerance the value of tolerance
3737     #  @param SubMeshOrGroup SubMesh or Group
3738     #  @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3739     #  @return the list of groups of nodes
3740     #  @ingroup l2_modif_trsf
3741     def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3742         if (isinstance( SubMeshOrGroup, Mesh )):
3743             SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3744         if not isinstance( exceptNodes, list):
3745             exceptNodes = [ exceptNodes ]
3746         if exceptNodes and isinstance( exceptNodes[0], int):
3747             exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3748         return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3749
3750     ## Merges nodes
3751     #  @param GroupsOfNodes the list of groups of nodes
3752     #  @ingroup l2_modif_trsf
3753     def MergeNodes (self, GroupsOfNodes):
3754         self.editor.MergeNodes(GroupsOfNodes)
3755
3756     ## Finds the elements built on the same nodes.
3757     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3758     #  @return a list of groups of equal elements
3759     #  @ingroup l2_modif_trsf
3760     def FindEqualElements (self, MeshOrSubMeshOrGroup):
3761         if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3762             MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3763         return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3764
3765     ## Merges elements in each given group.
3766     #  @param GroupsOfElementsID groups of elements for merging
3767     #  @ingroup l2_modif_trsf
3768     def MergeElements(self, GroupsOfElementsID):
3769         self.editor.MergeElements(GroupsOfElementsID)
3770
3771     ## Leaves one element and removes all other elements built on the same nodes.
3772     #  @ingroup l2_modif_trsf
3773     def MergeEqualElements(self):
3774         self.editor.MergeEqualElements()
3775
3776     ## Sews free borders
3777     #  @return SMESH::Sew_Error
3778     #  @ingroup l2_modif_trsf
3779     def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3780                         FirstNodeID2, SecondNodeID2, LastNodeID2,
3781                         CreatePolygons, CreatePolyedrs):
3782         return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3783                                           FirstNodeID2, SecondNodeID2, LastNodeID2,
3784                                           CreatePolygons, CreatePolyedrs)
3785
3786     ## Sews conform free borders
3787     #  @return SMESH::Sew_Error
3788     #  @ingroup l2_modif_trsf
3789     def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3790                                FirstNodeID2, SecondNodeID2):
3791         return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3792                                                  FirstNodeID2, SecondNodeID2)
3793
3794     ## Sews border to side
3795     #  @return SMESH::Sew_Error
3796     #  @ingroup l2_modif_trsf
3797     def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3798                          FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3799         return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3800                                            FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3801
3802     ## Sews two sides of a mesh. The nodes belonging to Side1 are
3803     #  merged with the nodes of elements of Side2.
3804     #  The number of elements in theSide1 and in theSide2 must be
3805     #  equal and they should have similar nodal connectivity.
3806     #  The nodes to merge should belong to side borders and
3807     #  the first node should be linked to the second.
3808     #  @return SMESH::Sew_Error
3809     #  @ingroup l2_modif_trsf
3810     def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3811                          NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3812                          NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3813         return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3814                                            NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3815                                            NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3816
3817     ## Sets new nodes for the given element.
3818     #  @param ide the element id
3819     #  @param newIDs nodes ids
3820     #  @return If the number of nodes does not correspond to the type of element - returns false
3821     #  @ingroup l2_modif_edit
3822     def ChangeElemNodes(self, ide, newIDs):
3823         return self.editor.ChangeElemNodes(ide, newIDs)
3824
3825     ## If during the last operation of MeshEditor some nodes were
3826     #  created, this method returns the list of their IDs, \n
3827     #  if new nodes were not created - returns empty list
3828     #  @return the list of integer values (can be empty)
3829     #  @ingroup l1_auxiliary
3830     def GetLastCreatedNodes(self):
3831         return self.editor.GetLastCreatedNodes()
3832
3833     ## If during the last operation of MeshEditor some elements were
3834     #  created this method returns the list of their IDs, \n
3835     #  if new elements were not created - returns empty list
3836     #  @return the list of integer values (can be empty)
3837     #  @ingroup l1_auxiliary
3838     def GetLastCreatedElems(self):
3839         return self.editor.GetLastCreatedElems()
3840
3841      ## Creates a hole in a mesh by doubling the nodes of some particular elements
3842     #  @param theNodes identifiers of nodes to be doubled
3843     #  @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3844     #         nodes. If list of element identifiers is empty then nodes are doubled but
3845     #         they not assigned to elements
3846     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3847     #  @ingroup l2_modif_edit
3848     def DoubleNodes(self, theNodes, theModifiedElems):
3849         return self.editor.DoubleNodes(theNodes, theModifiedElems)
3850
3851     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3852     #  This method provided for convenience works as DoubleNodes() described above.
3853     #  @param theNodeId identifiers of node to be doubled
3854     #  @param theModifiedElems identifiers of elements to be updated
3855     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3856     #  @ingroup l2_modif_edit
3857     def DoubleNode(self, theNodeId, theModifiedElems):
3858         return self.editor.DoubleNode(theNodeId, theModifiedElems)
3859
3860     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3861     #  This method provided for convenience works as DoubleNodes() described above.
3862     #  @param theNodes group of nodes to be doubled
3863     #  @param theModifiedElems group of elements to be updated.
3864     #  @param theMakeGroup forces the generation of a group containing new nodes.
3865     #  @return TRUE or a created group if operation has been completed successfully,
3866     #          FALSE or None otherwise
3867     #  @ingroup l2_modif_edit
3868     def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3869         if theMakeGroup:
3870             return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3871         return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3872
3873     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3874     #  This method provided for convenience works as DoubleNodes() described above.
3875     #  @param theNodes list of groups of nodes to be doubled
3876     #  @param theModifiedElems list of groups of elements to be updated.
3877     #  @param theMakeGroup forces the generation of a group containing new nodes.
3878     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3879     #  @ingroup l2_modif_edit
3880     def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3881         if theMakeGroup:
3882             return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3883         return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3884
3885     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3886     #  @param theElems - the list of elements (edges or faces) to be replicated
3887     #         The nodes for duplication could be found from these elements
3888     #  @param theNodesNot - list of nodes to NOT replicate
3889     #  @param theAffectedElems - the list of elements (cells and edges) to which the
3890     #         replicated nodes should be associated to.
3891     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3892     #  @ingroup l2_modif_edit
3893     def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3894         return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3895
3896     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3897     #  @param theElems - the list of elements (edges or faces) to be replicated
3898     #         The nodes for duplication could be found from these elements
3899     #  @param theNodesNot - list of nodes to NOT replicate
3900     #  @param theShape - shape to detect affected elements (element which geometric center
3901     #         located on or inside shape).
3902     #         The replicated nodes should be associated to affected elements.
3903     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3904     #  @ingroup l2_modif_edit
3905     def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
3906         return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
3907
3908     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3909     #  This method provided for convenience works as DoubleNodes() described above.
3910     #  @param theElems - group of of elements (edges or faces) to be replicated
3911     #  @param theNodesNot - group of nodes not to replicated
3912     #  @param theAffectedElems - group of elements to which the replicated nodes
3913     #         should be associated to.
3914     #  @param theMakeGroup forces the generation of a group containing new elements.
3915     #  @param theMakeNodeGroup forces the generation of a group containing new nodes.
3916     #  @return TRUE or created groups (one or two) if operation has been completed successfully,
3917     #          FALSE or None otherwise
3918     #  @ingroup l2_modif_edit
3919     def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
3920                              theMakeGroup=False, theMakeNodeGroup=False):
3921         if theMakeGroup or theMakeNodeGroup:
3922             twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
3923                                                             theAffectedElems,
3924                                                             theMakeGroup, theMakeNodeGroup)
3925             if theMakeGroup and theMakeNodeGroup:
3926                 return twoGroups
3927             else:
3928                 return twoGroups[ int(theMakeNodeGroup) ]
3929         return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
3930
3931     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3932     #  This method provided for convenience works as DoubleNodes() described above.
3933     #  @param theElems - group of of elements (edges or faces) to be replicated
3934     #  @param theNodesNot - group of nodes not to replicated
3935     #  @param theShape - shape to detect affected elements (element which geometric center
3936     #         located on or inside shape).
3937     #         The replicated nodes should be associated to affected elements.
3938     #  @ingroup l2_modif_edit
3939     def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
3940         return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
3941
3942     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3943     #  This method provided for convenience works as DoubleNodes() described above.
3944     #  @param theElems - list of groups of elements (edges or faces) to be replicated
3945     #  @param theNodesNot - list of groups of nodes not to replicated
3946     #  @param theAffectedElems - group of elements to which the replicated nodes
3947     #         should be associated to.
3948     #  @param theMakeGroup forces the generation of a group containing new elements.
3949     #  @param theMakeNodeGroup forces the generation of a group containing new nodes.
3950     #  @return TRUE or created groups (one or two) if operation has been completed successfully,
3951     #          FALSE or None otherwise
3952     #  @ingroup l2_modif_edit
3953     def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
3954                              theMakeGroup=False, theMakeNodeGroup=False):
3955         if theMakeGroup or theMakeNodeGroup:
3956             twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
3957                                                              theAffectedElems,
3958                                                              theMakeGroup, theMakeNodeGroup)
3959             if theMakeGroup and theMakeNodeGroup:
3960                 return twoGroups
3961             else:
3962                 return twoGroups[ int(theMakeNodeGroup) ]
3963         return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
3964
3965     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3966     #  This method provided for convenience works as DoubleNodes() described above.
3967     #  @param theElems - list of groups of elements (edges or faces) to be replicated
3968     #  @param theNodesNot - list of groups of nodes not to replicated
3969     #  @param theShape - shape to detect affected elements (element which geometric center
3970     #         located on or inside shape).
3971     #         The replicated nodes should be associated to affected elements.
3972     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3973     #  @ingroup l2_modif_edit
3974     def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
3975         return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
3976
3977     ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
3978     # The list of groups must describe a partition of the mesh volumes.
3979     # The nodes of the internal faces at the boundaries of the groups are doubled.
3980     # In option, the internal faces are replaced by flat elements.
3981     # Triangles are transformed in prisms, and quadrangles in hexahedrons.
3982     # @param theDomains - list of groups of volumes
3983     # @param createJointElems - if TRUE, create the elements
3984     # @return TRUE if operation has been completed successfully, FALSE otherwise
3985     def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
3986        return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
3987
3988     ## Double nodes on some external faces and create flat elements.
3989     # Flat elements are mainly used by some types of mechanic calculations.
3990     #
3991     # Each group of the list must be constituted of faces.
3992     # Triangles are transformed in prisms, and quadrangles in hexahedrons.
3993     # @param theGroupsOfFaces - list of groups of faces
3994     # @return TRUE if operation has been completed successfully, FALSE otherwise
3995     def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
3996         return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
3997
3998     def _valueFromFunctor(self, funcType, elemId):
3999         fn = self.smeshpyD.GetFunctor(funcType)
4000         fn.SetMesh(self.mesh)
4001         if fn.GetElementType() == self.GetElementType(elemId, True):
4002             val = fn.GetValue(elemId)
4003         else:
4004             val = 0
4005         return val
4006
4007     ## Get length of 1D element.
4008     #  @param elemId mesh element ID
4009     #  @return element's length value
4010     #  @ingroup l1_measurements
4011     def GetLength(self, elemId):
4012         return self._valueFromFunctor(SMESH.FT_Length, elemId)
4013
4014     ## Get area of 2D element.
4015     #  @param elemId mesh element ID
4016     #  @return element's area value
4017     #  @ingroup l1_measurements
4018     def GetArea(self, elemId):
4019         return self._valueFromFunctor(SMESH.FT_Area, elemId)
4020
4021     ## Get volume of 3D element.
4022     #  @param elemId mesh element ID
4023     #  @return element's volume value
4024     #  @ingroup l1_measurements
4025     def GetVolume(self, elemId):
4026         return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4027
4028     ## Get maximum element length.
4029     #  @param elemId mesh element ID
4030     #  @return element's maximum length value
4031     #  @ingroup l1_measurements
4032     def GetMaxElementLength(self, elemId):
4033         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4034             ftype = SMESH.FT_MaxElementLength3D
4035         else:
4036             ftype = SMESH.FT_MaxElementLength2D
4037         return self._valueFromFunctor(ftype, elemId)
4038
4039     ## Get aspect ratio of 2D or 3D element.
4040     #  @param elemId mesh element ID
4041     #  @return element's aspect ratio value
4042     #  @ingroup l1_measurements
4043     def GetAspectRatio(self, elemId):
4044         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4045             ftype = SMESH.FT_AspectRatio3D
4046         else:
4047             ftype = SMESH.FT_AspectRatio
4048         return self._valueFromFunctor(ftype, elemId)
4049
4050     ## Get warping angle of 2D element.
4051     #  @param elemId mesh element ID
4052     #  @return element's warping angle value
4053     #  @ingroup l1_measurements
4054     def GetWarping(self, elemId):
4055         return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4056
4057     ## Get minimum angle of 2D element.
4058     #  @param elemId mesh element ID
4059     #  @return element's minimum angle value
4060     #  @ingroup l1_measurements
4061     def GetMinimumAngle(self, elemId):
4062         return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4063
4064     ## Get taper of 2D element.
4065     #  @param elemId mesh element ID
4066     #  @return element's taper value
4067     #  @ingroup l1_measurements
4068     def GetTaper(self, elemId):
4069         return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4070
4071     ## Get skew of 2D element.
4072     #  @param elemId mesh element ID
4073     #  @return element's skew value
4074     #  @ingroup l1_measurements
4075     def GetSkew(self, elemId):
4076         return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4077
4078 ## The mother class to define algorithm, it is not recommended to use it directly.
4079 #
4080 #  For each meshing algorithm, a python class inheriting from class Mesh_Algorithm
4081 #  should be defined. This descendant class sould have two attributes defining the way
4082 # it is created by class Mesh (see e.g. class StdMeshersDC_Segment in StdMeshersDC.py).
4083 # - meshMethod attribute defines name of method of class Mesh by calling which the
4084 #   python class of algorithm is created. E.g. if in class MyPlugin_Algorithm
4085 #   meshMethod = "MyAlgorithm", then an instance of MyPlugin_Algorithm is created
4086 #   by the following code: my_algo = mesh.MyAlgorithm()
4087 # - algoType defines name of algorithm type and is used mostly to discriminate
4088 #   algorithms that are created by the same method of class Mesh. E.g. if
4089 #   MyPlugin_Algorithm.algoType = "MyPLUGIN" then it's creation code can be:
4090 #   my_algo = mesh.MyAlgorithm(algo="MyPLUGIN")
4091 #  @ingroup l2_algorithms
4092 class Mesh_Algorithm:
4093     #  @class Mesh_Algorithm
4094     #  @brief Class Mesh_Algorithm
4095
4096     #def __init__(self,smesh):
4097     #    self.smesh=smesh
4098     def __init__(self):
4099         self.mesh = None
4100         self.geom = None
4101         self.subm = None
4102         self.algo = None
4103
4104     ## Finds a hypothesis in the study by its type name and parameters.
4105     #  Finds only the hypotheses created in smeshpyD engine.
4106     #  @return SMESH.SMESH_Hypothesis
4107     def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
4108         study = smeshpyD.GetCurrentStudy()
4109         #to do: find component by smeshpyD object, not by its data type
4110         scomp = study.FindComponent(smeshpyD.ComponentDataType())
4111         if scomp is not None:
4112             res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
4113             # Check if the root label of the hypotheses exists
4114             if res and hypRoot is not None:
4115                 iter = study.NewChildIterator(hypRoot)
4116                 # Check all published hypotheses
4117                 while iter.More():
4118                     hypo_so_i = iter.Value()
4119                     attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
4120                     if attr is not None:
4121                         anIOR = attr.Value()
4122                         hypo_o_i = salome.orb.string_to_object(anIOR)
4123                         if hypo_o_i is not None:
4124                             # Check if this is a hypothesis
4125                             hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
4126                             if hypo_i is not None:
4127                                 # Check if the hypothesis belongs to current engine
4128                                 if smeshpyD.GetObjectId(hypo_i) > 0:
4129                                     # Check if this is the required hypothesis
4130                                     if hypo_i.GetName() == hypname:
4131                                         # Check arguments
4132                                         if CompareMethod(hypo_i, args):
4133                                             # found!!!
4134                                             return hypo_i
4135                                         pass
4136                                     pass
4137                                 pass
4138                             pass
4139                         pass
4140                     iter.Next()
4141                     pass
4142                 pass
4143             pass
4144         return None
4145
4146     ## Finds the algorithm in the study by its type name.
4147     #  Finds only the algorithms, which have been created in smeshpyD engine.
4148     #  @return SMESH.SMESH_Algo
4149     def FindAlgorithm (self, algoname, smeshpyD):
4150         study = smeshpyD.GetCurrentStudy()
4151         if not study: return None
4152         #to do: find component by smeshpyD object, not by its data type
4153         scomp = study.FindComponent(smeshpyD.ComponentDataType())
4154         if scomp is not None:
4155             res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
4156             # Check if the root label of the algorithms exists
4157             if res and hypRoot is not None:
4158                 iter = study.NewChildIterator(hypRoot)
4159                 # Check all published algorithms
4160                 while iter.More():
4161                     algo_so_i = iter.Value()
4162                     attr = algo_so_i.FindAttribute("AttributeIOR")[1]
4163                     if attr is not None:
4164                         anIOR = attr.Value()
4165                         algo_o_i = salome.orb.string_to_object(anIOR)
4166                         if algo_o_i is not None:
4167                             # Check if this is an algorithm
4168                             algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
4169                             if algo_i is not None:
4170                                 # Checks if the algorithm belongs to the current engine
4171                                 if smeshpyD.GetObjectId(algo_i) > 0:
4172                                     # Check if this is the required algorithm
4173                                     if algo_i.GetName() == algoname:
4174                                         # found!!!
4175                                         return algo_i
4176                                     pass
4177                                 pass
4178                             pass
4179                         pass
4180                     iter.Next()
4181                     pass
4182                 pass
4183             pass
4184         return None
4185
4186     ## If the algorithm is global, returns 0; \n
4187     #  else returns the submesh associated to this algorithm.
4188     def GetSubMesh(self):
4189         return self.subm
4190
4191     ## Returns the wrapped mesher.
4192     def GetAlgorithm(self):
4193         return self.algo
4194
4195     ## Gets the list of hypothesis that can be used with this algorithm
4196     def GetCompatibleHypothesis(self):
4197         mylist = []
4198         if self.algo:
4199             mylist = self.algo.GetCompatibleHypothesis()
4200         return mylist
4201
4202     ## Gets the name of the algorithm
4203     def GetName(self):
4204         GetName(self.algo)
4205
4206     ## Sets the name to the algorithm
4207     def SetName(self, name):
4208         self.mesh.smeshpyD.SetName(self.algo, name)
4209
4210     ## Gets the id of the algorithm
4211     def GetId(self):
4212         return self.algo.GetId()
4213
4214     ## Private method.
4215     def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
4216         if geom is None:
4217             raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
4218         algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
4219         if algo is None:
4220             algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
4221             pass
4222         self.Assign(algo, mesh, geom)
4223         return self.algo
4224
4225     ## Private method
4226     def Assign(self, algo, mesh, geom):
4227         if geom is None:
4228             raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
4229         self.mesh = mesh
4230         name = ""
4231         if not geom:
4232             self.geom = mesh.geom
4233         else:
4234             self.geom = geom
4235             AssureGeomPublished( mesh, geom )
4236             try:
4237                 name = GetName(geom)
4238                 pass
4239             except:
4240                 pass
4241             self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
4242         self.algo = algo
4243         status = mesh.mesh.AddHypothesis(self.geom, self.algo)
4244         TreatHypoStatus( status, algo.GetName(), name, True )
4245         return
4246
4247     def CompareHyp (self, hyp, args):
4248         print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
4249         return False
4250
4251     def CompareEqualHyp (self, hyp, args):
4252         return True
4253
4254     ## Private method
4255     def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
4256                     UseExisting=0, CompareMethod=""):
4257         hypo = None
4258         if UseExisting:
4259             if CompareMethod == "": CompareMethod = self.CompareHyp
4260             hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
4261             pass
4262         if hypo is None:
4263             hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
4264             a = ""
4265             s = "="
4266             for arg in args:
4267                 argStr = str(arg)
4268                 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4269                     argStr = arg.GetStudyEntry()
4270                     if not argStr: argStr = "GEOM_Obj_%s", arg.GetEntry()
4271                 if len( argStr ) > 10:
4272                     argStr = argStr[:7]+"..."
4273                     if argStr[0] == '[': argStr += ']'
4274                 a = a + s + argStr
4275                 s = ","
4276                 pass
4277             if len(a) > 50:
4278                 a = a[:47]+"..."
4279             self.mesh.smeshpyD.SetName(hypo, hyp + a)
4280             pass
4281         geomName=""
4282         if self.geom:
4283             geomName = GetName(self.geom)
4284         status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
4285         TreatHypoStatus( status, GetName(hypo), geomName, 0 )
4286         return hypo
4287
4288     ## Returns entry of the shape to mesh in the study
4289     def MainShapeEntry(self):
4290         if not self.mesh or not self.mesh.GetMesh(): return ""
4291         if not self.mesh.GetMesh().HasShapeToMesh(): return ""
4292         shape = self.mesh.GetShape()
4293         return shape.GetStudyEntry()
4294
4295     ## Defines "ViscousLayers" hypothesis to give parameters of layers of prisms to build
4296     #  near mesh boundary. This hypothesis can be used by several 3D algorithms:
4297     #  NETGEN 3D, GHS3D, Hexahedron(i,j,k)
4298     #  @param thickness total thickness of layers of prisms
4299     #  @param numberOfLayers number of layers of prisms
4300     #  @param stretchFactor factor (>1.0) of growth of layer thickness towards inside of mesh
4301     #  @param ignoreFaces list of geometrical faces (or their ids) not to generate layers on
4302     #  @ingroup l3_hypos_additi
4303     def ViscousLayers(self, thickness, numberOfLayers, stretchFactor, ignoreFaces=[]):
4304         if not isinstance(self.algo, SMESH._objref_SMESH_3D_Algo):
4305             raise TypeError, "ViscousLayers are supported by 3D algorithms only"
4306         if not "ViscousLayers" in self.GetCompatibleHypothesis():
4307             raise TypeError, "ViscousLayers are not supported by %s"%self.algo.GetName()
4308         if ignoreFaces and isinstance( ignoreFaces[0], geompyDC.GEOM._objref_GEOM_Object ):
4309             ignoreFaces = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f) for f in ignoreFaces ]
4310         hyp = self.Hypothesis("ViscousLayers",
4311                               [thickness, numberOfLayers, stretchFactor, ignoreFaces])
4312         hyp.SetTotalThickness(thickness)
4313         hyp.SetNumberLayers(numberOfLayers)
4314         hyp.SetStretchFactor(stretchFactor)
4315         hyp.SetIgnoreFaces(ignoreFaces)
4316         return hyp
4317
4318     ## Transform a list of ether edges or tuples (edge, 1st_vertex_of_edge)
4319     #  into a list acceptable to SetReversedEdges() of some 1D hypotheses
4320     #  @ingroup l3_hypos_1dhyps
4321     def ReversedEdgeIndices(self, reverseList):
4322         resList = []
4323         geompy = self.mesh.geompyD
4324         for i in reverseList:
4325             if isinstance( i, int ):
4326                 s = geompy.SubShapes(self.mesh.geom, [i])[0]
4327                 if s.GetShapeType() != geompyDC.GEOM.EDGE:
4328                     raise TypeError, "Not EDGE index given"
4329                 resList.append( i )
4330             elif isinstance( i, geompyDC.GEOM._objref_GEOM_Object ):
4331                 if i.GetShapeType() != geompyDC.GEOM.EDGE:
4332                     raise TypeError, "Not an EDGE given"
4333                 resList.append( geompy.GetSubShapeID(self.mesh.geom, i ))
4334             elif len( i ) > 1:
4335                 e = i[0]
4336                 v = i[1]
4337                 if not isinstance( e, geompyDC.GEOM._objref_GEOM_Object ) or \
4338                    not isinstance( v, geompyDC.GEOM._objref_GEOM_Object ):
4339                     raise TypeError, "A list item must be a tuple (edge, 1st_vertex_of_edge)"
4340                 if v.GetShapeType() == geompyDC.GEOM.EDGE and \
4341                    e.GetShapeType() == geompyDC.GEOM.VERTEX:
4342                     v,e = e,v
4343                 if e.GetShapeType() != geompyDC.GEOM.EDGE or \
4344                    v.GetShapeType() != geompyDC.GEOM.VERTEX:
4345                     raise TypeError, "A list item must be a tuple (edge, 1st_vertex_of_edge)"
4346                 vFirst = FirstVertexOnCurve( e )
4347                 tol    = geompy.Tolerance( vFirst )[-1]
4348                 if geompy.MinDistance( v, vFirst ) > 1.5*tol:
4349                     resList.append( geompy.GetSubShapeID(self.mesh.geom, e ))
4350             else:
4351                 raise TypeError, "Item must be either an edge or tuple (edge, 1st_vertex_of_edge)"
4352         return resList
4353
4354
4355 class Pattern(SMESH._objref_SMESH_Pattern):
4356
4357     def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4358         decrFun = lambda i: i-1
4359         theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4360         theMesh.SetParameters(Parameters)
4361         return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4362
4363     def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4364         decrFun = lambda i: i-1
4365         theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4366         theMesh.SetParameters(Parameters)
4367         return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4368
4369 #Registering the new proxy for Pattern
4370 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4371
4372
4373
4374
4375
4376 ## Private class used to bind methods creating algorithms to the class Mesh
4377 #
4378 class algoCreator:
4379     def __init__(self):
4380         self.mesh = None
4381         self.defaultAlgoType = ""
4382         self.algoTypeToClass = {}
4383
4384     # Stores a python class of algorithm
4385     def add(self, algoClass):
4386         if type( algoClass ).__name__ == 'classobj' and \
4387            hasattr( algoClass, "algoType"):
4388             self.algoTypeToClass[ algoClass.algoType ] = algoClass
4389             if not self.defaultAlgoType and \
4390                hasattr( algoClass, "isDefault") and algoClass.isDefault:
4391                 self.defaultAlgoType = algoClass.algoType
4392             #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4393
4394     # creates a copy of self and assign mesh to the copy
4395     def copy(self, mesh):
4396         other = algoCreator()
4397         other.defaultAlgoType = self.defaultAlgoType
4398         other.algoTypeToClass  = self.algoTypeToClass
4399         other.mesh = mesh
4400         return other
4401
4402     # creates an instance of algorithm
4403     def __call__(self,algo="",geom=0,*args):
4404         algoType = self.defaultAlgoType
4405         for arg in args + (algo,geom):
4406             if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4407                 geom = arg
4408             if isinstance( arg, str ) and arg:
4409                 algoType = arg
4410         if not algoType and self.algoTypeToClass:
4411             algoType = self.algoTypeToClass.keys()[0]
4412         if self.algoTypeToClass.has_key( algoType ):
4413             #print "Create algo",algoType
4414             return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4415         raise RuntimeError, "No class found for algo type %s" % algoType
4416         return None
4417
4418 # Private class used to substitute and store variable parameters of hypotheses.
4419 class hypMethodWrapper:
4420     def __init__(self, hyp, method):
4421         self.hyp    = hyp
4422         self.method = method
4423         #print "REBIND:", method.__name__
4424         return
4425
4426     # call a method of hypothesis with calling SetVarParameter() before
4427     def __call__(self,*args):
4428         if not args:
4429             return self.method( self.hyp, *args ) # hypothesis method with no args
4430
4431         #print "MethWrapper.__call__",self.method.__name__, args
4432         try:
4433             parsed = ParseParameters(*args)     # replace variables with their values
4434             self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4435             result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4436         except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4437             # maybe there is a replaced string arg which is not variable
4438             result = self.method( self.hyp, *args )
4439         except ValueError, detail: # raised by ParseParameters()
4440             try:
4441                 result = self.method( self.hyp, *args )
4442             except omniORB.CORBA.BAD_PARAM:
4443                 raise ValueError, detail # wrong variable name
4444
4445         return result