Salome HOME
Fix tests regressions caused by changed behavior of SubShapeAll geom function
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 #  File   : smesh.py
22 #  Author : Francis KLOSS, OCC
23 #  Module : SMESH
24 #
25 """
26  \namespace smesh
27  \brief Module smesh
28 """
29
30 ## @defgroup l1_auxiliary Auxiliary methods and structures
31 ## @defgroup l1_creating  Creating meshes
32 ## @{
33 ##   @defgroup l2_impexp     Importing and exporting meshes
34 ##   @defgroup l2_construct  Constructing meshes
35 ##   @defgroup l2_algorithms Defining Algorithms
36 ##   @{
37 ##     @defgroup l3_algos_basic   Basic meshing algorithms
38 ##     @defgroup l3_algos_proj    Projection Algorithms
39 ##     @defgroup l3_algos_radialp Radial Prism
40 ##     @defgroup l3_algos_segmarv Segments around Vertex
41 ##     @defgroup l3_algos_3dextr  3D extrusion meshing algorithm
42
43 ##   @}
44 ##   @defgroup l2_hypotheses Defining hypotheses
45 ##   @{
46 ##     @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
47 ##     @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
48 ##     @defgroup l3_hypos_maxvol Max Element Volume hypothesis
49 ##     @defgroup l3_hypos_netgen Netgen 2D and 3D hypotheses
50 ##     @defgroup l3_hypos_ghs3dh GHS3D Parameters hypothesis
51 ##     @defgroup l3_hypos_blsurf BLSURF Parameters hypothesis
52 ##     @defgroup l3_hypos_hexotic Hexotic Parameters hypothesis
53 ##     @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
54 ##     @defgroup l3_hypos_additi Additional Hypotheses
55
56 ##   @}
57 ##   @defgroup l2_submeshes Constructing submeshes
58 ##   @defgroup l2_compounds Building Compounds
59 ##   @defgroup l2_editing   Editing Meshes
60
61 ## @}
62 ## @defgroup l1_meshinfo  Mesh Information
63 ## @defgroup l1_controls  Quality controls and Filtering
64 ## @defgroup l1_grouping  Grouping elements
65 ## @{
66 ##   @defgroup l2_grps_create Creating groups
67 ##   @defgroup l2_grps_edit   Editing groups
68 ##   @defgroup l2_grps_operon Using operations on groups
69 ##   @defgroup l2_grps_delete Deleting Groups
70
71 ## @}
72 ## @defgroup l1_modifying Modifying meshes
73 ## @{
74 ##   @defgroup l2_modif_add      Adding nodes and elements
75 ##   @defgroup l2_modif_del      Removing nodes and elements
76 ##   @defgroup l2_modif_edit     Modifying nodes and elements
77 ##   @defgroup l2_modif_renumber Renumbering nodes and elements
78 ##   @defgroup l2_modif_trsf     Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
79 ##   @defgroup l2_modif_movenode Moving nodes
80 ##   @defgroup l2_modif_throughp Mesh through point
81 ##   @defgroup l2_modif_invdiag  Diagonal inversion of elements
82 ##   @defgroup l2_modif_unitetri Uniting triangles
83 ##   @defgroup l2_modif_changori Changing orientation of elements
84 ##   @defgroup l2_modif_cutquadr Cutting quadrangles
85 ##   @defgroup l2_modif_smooth   Smoothing
86 ##   @defgroup l2_modif_extrurev Extrusion and Revolution
87 ##   @defgroup l2_modif_patterns Pattern mapping
88 ##   @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
89
90 ## @}
91 ## @defgroup l1_measurements Measurements
92
93 import salome
94 import geompyDC
95
96 import SMESH # This is necessary for back compatibility
97 from   SMESH import *
98
99 import StdMeshers
100
101 import SALOME
102 import SALOMEDS
103
104 # import NETGENPlugin module if possible
105 noNETGENPlugin = 0
106 try:
107     import NETGENPlugin
108 except ImportError:
109     noNETGENPlugin = 1
110     pass
111
112 # import GHS3DPlugin module if possible
113 noGHS3DPlugin = 0
114 try:
115     import GHS3DPlugin
116 except ImportError:
117     noGHS3DPlugin = 1
118     pass
119
120 # import GHS3DPRLPlugin module if possible
121 noGHS3DPRLPlugin = 0
122 try:
123     import GHS3DPRLPlugin
124 except ImportError:
125     noGHS3DPRLPlugin = 1
126     pass
127
128 # import HexoticPlugin module if possible
129 noHexoticPlugin = 0
130 try:
131     import HexoticPlugin
132 except ImportError:
133     noHexoticPlugin = 1
134     pass
135
136 # import BLSURFPlugin module if possible
137 noBLSURFPlugin = 0
138 try:
139     import BLSURFPlugin
140 except ImportError:
141     noBLSURFPlugin = 1
142     pass
143
144 ## @addtogroup l1_auxiliary
145 ## @{
146
147 # Types of algorithms
148 REGULAR    = 1
149 PYTHON     = 2
150 COMPOSITE  = 3
151 SOLE       = 0
152 SIMPLE     = 1
153
154 MEFISTO       = 3
155 NETGEN        = 4
156 GHS3D         = 5
157 FULL_NETGEN   = 6
158 NETGEN_2D     = 7
159 NETGEN_1D2D   = NETGEN
160 NETGEN_1D2D3D = FULL_NETGEN
161 NETGEN_FULL   = FULL_NETGEN
162 Hexa    = 8
163 Hexotic = 9
164 BLSURF  = 10
165 GHS3DPRL = 11
166 QUADRANGLE = 0
167 RADIAL_QUAD = 1
168
169 # MirrorType enumeration
170 POINT = SMESH_MeshEditor.POINT
171 AXIS =  SMESH_MeshEditor.AXIS
172 PLANE = SMESH_MeshEditor.PLANE
173
174 # Smooth_Method enumeration
175 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
176 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
177
178 # Fineness enumeration (for NETGEN)
179 VeryCoarse = 0
180 Coarse     = 1
181 Moderate   = 2
182 Fine       = 3
183 VeryFine   = 4
184 Custom     = 5
185
186 # Optimization level of GHS3D
187 # V3.1
188 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
189 # V4.1 (partialy redefines V3.1). Issue 0020574
190 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
191
192 # Topology treatment way of BLSURF
193 FromCAD, PreProcess, PreProcessPlus = 0,1,2
194
195 # Element size flag of BLSURF
196 DefaultSize, DefaultGeom, Custom = 0,0,1
197
198 PrecisionConfusion = 1e-07
199
200 # TopAbs_State enumeration
201 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
202
203 # Methods of splitting a hexahedron into tetrahedra
204 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
205
206 # import items of enum QuadType
207 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
208
209 ## Converts an angle from degrees to radians
210 def DegreesToRadians(AngleInDegrees):
211     from math import pi
212     return AngleInDegrees * pi / 180.0
213
214 # Salome notebook variable separator
215 var_separator = ":"
216
217 # Parametrized substitute for PointStruct
218 class PointStructStr:
219
220     x = 0
221     y = 0
222     z = 0
223     xStr = ""
224     yStr = ""
225     zStr = ""
226
227     def __init__(self, xStr, yStr, zStr):
228         self.xStr = xStr
229         self.yStr = yStr
230         self.zStr = zStr
231         if isinstance(xStr, str) and notebook.isVariable(xStr):
232             self.x = notebook.get(xStr)
233         else:
234             self.x = xStr
235         if isinstance(yStr, str) and notebook.isVariable(yStr):
236             self.y = notebook.get(yStr)
237         else:
238             self.y = yStr
239         if isinstance(zStr, str) and notebook.isVariable(zStr):
240             self.z = notebook.get(zStr)
241         else:
242             self.z = zStr
243
244 # Parametrized substitute for PointStruct (with 6 parameters)
245 class PointStructStr6:
246
247     x1 = 0
248     y1 = 0
249     z1 = 0
250     x2 = 0
251     y2 = 0
252     z2 = 0
253     xStr1 = ""
254     yStr1 = ""
255     zStr1 = ""
256     xStr2 = ""
257     yStr2 = ""
258     zStr2 = ""
259
260     def __init__(self, x1Str, x2Str, y1Str, y2Str, z1Str, z2Str):
261         self.x1Str = x1Str
262         self.x2Str = x2Str
263         self.y1Str = y1Str
264         self.y2Str = y2Str
265         self.z1Str = z1Str
266         self.z2Str = z2Str
267         if isinstance(x1Str, str) and notebook.isVariable(x1Str):
268             self.x1 = notebook.get(x1Str)
269         else:
270             self.x1 = x1Str
271         if isinstance(x2Str, str) and notebook.isVariable(x2Str):
272             self.x2 = notebook.get(x2Str)
273         else:
274             self.x2 = x2Str
275         if isinstance(y1Str, str) and notebook.isVariable(y1Str):
276             self.y1 = notebook.get(y1Str)
277         else:
278             self.y1 = y1Str
279         if isinstance(y2Str, str) and notebook.isVariable(y2Str):
280             self.y2 = notebook.get(y2Str)
281         else:
282             self.y2 = y2Str
283         if isinstance(z1Str, str) and notebook.isVariable(z1Str):
284             self.z1 = notebook.get(z1Str)
285         else:
286             self.z1 = z1Str
287         if isinstance(z2Str, str) and notebook.isVariable(z2Str):
288             self.z2 = notebook.get(z2Str)
289         else:
290             self.z2 = z2Str
291
292 # Parametrized substitute for AxisStruct
293 class AxisStructStr:
294
295     x = 0
296     y = 0
297     z = 0
298     dx = 0
299     dy = 0
300     dz = 0
301     xStr = ""
302     yStr = ""
303     zStr = ""
304     dxStr = ""
305     dyStr = ""
306     dzStr = ""
307
308     def __init__(self, xStr, yStr, zStr, dxStr, dyStr, dzStr):
309         self.xStr = xStr
310         self.yStr = yStr
311         self.zStr = zStr
312         self.dxStr = dxStr
313         self.dyStr = dyStr
314         self.dzStr = dzStr
315         if isinstance(xStr, str) and notebook.isVariable(xStr):
316             self.x = notebook.get(xStr)
317         else:
318             self.x = xStr
319         if isinstance(yStr, str) and notebook.isVariable(yStr):
320             self.y = notebook.get(yStr)
321         else:
322             self.y = yStr
323         if isinstance(zStr, str) and notebook.isVariable(zStr):
324             self.z = notebook.get(zStr)
325         else:
326             self.z = zStr
327         if isinstance(dxStr, str) and notebook.isVariable(dxStr):
328             self.dx = notebook.get(dxStr)
329         else:
330             self.dx = dxStr
331         if isinstance(dyStr, str) and notebook.isVariable(dyStr):
332             self.dy = notebook.get(dyStr)
333         else:
334             self.dy = dyStr
335         if isinstance(dzStr, str) and notebook.isVariable(dzStr):
336             self.dz = notebook.get(dzStr)
337         else:
338             self.dz = dzStr
339
340 # Parametrized substitute for DirStruct
341 class DirStructStr:
342
343     def __init__(self, pointStruct):
344         self.pointStruct = pointStruct
345
346 # Returns list of variable values from salome notebook
347 def ParsePointStruct(Point):
348     Parameters = 2*var_separator
349     if isinstance(Point, PointStructStr):
350         Parameters = str(Point.xStr) + var_separator + str(Point.yStr) + var_separator + str(Point.zStr)
351         Point = PointStruct(Point.x, Point.y, Point.z)
352     return Point, Parameters
353
354 # Returns list of variable values from salome notebook
355 def ParseDirStruct(Dir):
356     Parameters = 2*var_separator
357     if isinstance(Dir, DirStructStr):
358         pntStr = Dir.pointStruct
359         if isinstance(pntStr, PointStructStr6):
360             Parameters = str(pntStr.x1Str) + var_separator + str(pntStr.x2Str) + var_separator
361             Parameters += str(pntStr.y1Str) + var_separator + str(pntStr.y2Str) + var_separator 
362             Parameters += str(pntStr.z1Str) + var_separator + str(pntStr.z2Str)
363             Point = PointStruct(pntStr.x2 - pntStr.x1, pntStr.y2 - pntStr.y1, pntStr.z2 - pntStr.z1)
364         else:
365             Parameters = str(pntStr.xStr) + var_separator + str(pntStr.yStr) + var_separator + str(pntStr.zStr)
366             Point = PointStruct(pntStr.x, pntStr.y, pntStr.z)
367         Dir = DirStruct(Point)
368     return Dir, Parameters
369
370 # Returns list of variable values from salome notebook
371 def ParseAxisStruct(Axis):
372     Parameters = 5*var_separator
373     if isinstance(Axis, AxisStructStr):
374         Parameters = str(Axis.xStr) + var_separator + str(Axis.yStr) + var_separator + str(Axis.zStr) + var_separator
375         Parameters += str(Axis.dxStr) + var_separator + str(Axis.dyStr) + var_separator + str(Axis.dzStr)
376         Axis = AxisStruct(Axis.x, Axis.y, Axis.z, Axis.dx, Axis.dy, Axis.dz)
377     return Axis, Parameters
378
379 ## Return list of variable values from salome notebook
380 def ParseAngles(list):
381     Result = []
382     Parameters = ""
383     for parameter in list:
384         if isinstance(parameter,str) and notebook.isVariable(parameter):
385             Result.append(DegreesToRadians(notebook.get(parameter)))
386             pass
387         else:
388             Result.append(parameter)
389             pass
390         
391         Parameters = Parameters + str(parameter)
392         Parameters = Parameters + var_separator
393         pass
394     Parameters = Parameters[:len(Parameters)-1]
395     return Result, Parameters
396     
397 def IsEqual(val1, val2, tol=PrecisionConfusion):
398     if abs(val1 - val2) < tol:
399         return True
400     return False
401
402 NO_NAME = "NoName"
403
404 ## Gets object name
405 def GetName(obj):
406     if obj:
407         # object not null
408         if isinstance(obj, SALOMEDS._objref_SObject):
409             # study object
410             return obj.GetName()
411         ior  = salome.orb.object_to_string(obj)
412         if ior:
413             # CORBA object
414             studies = salome.myStudyManager.GetOpenStudies()
415             for sname in studies:
416                 s = salome.myStudyManager.GetStudyByName(sname)
417                 if not s: continue
418                 sobj = s.FindObjectIOR(ior)
419                 if not sobj: continue
420                 return sobj.GetName()
421             if hasattr(obj, "GetName"):
422                 # unknown CORBA object, having GetName() method
423                 return obj.GetName()
424             else:
425                 # unknown CORBA object, no GetName() method
426                 return NO_NAME
427             pass
428         if hasattr(obj, "GetName"):
429             # unknown non-CORBA object, having GetName() method
430             return obj.GetName()
431         pass
432     raise RuntimeError, "Null or invalid object"
433
434 ## Prints error message if a hypothesis was not assigned.
435 def TreatHypoStatus(status, hypName, geomName, isAlgo):
436     if isAlgo:
437         hypType = "algorithm"
438     else:
439         hypType = "hypothesis"
440         pass
441     if status == HYP_UNKNOWN_FATAL :
442         reason = "for unknown reason"
443     elif status == HYP_INCOMPATIBLE :
444         reason = "this hypothesis mismatches the algorithm"
445     elif status == HYP_NOTCONFORM :
446         reason = "a non-conform mesh would be built"
447     elif status == HYP_ALREADY_EXIST :
448         if isAlgo: return # it does not influence anything
449         reason = hypType + " of the same dimension is already assigned to this shape"
450     elif status == HYP_BAD_DIM :
451         reason = hypType + " mismatches the shape"
452     elif status == HYP_CONCURENT :
453         reason = "there are concurrent hypotheses on sub-shapes"
454     elif status == HYP_BAD_SUBSHAPE :
455         reason = "the shape is neither the main one, nor its subshape, nor a valid group"
456     elif status == HYP_BAD_GEOMETRY:
457         reason = "geometry mismatches the expectation of the algorithm"
458     elif status == HYP_HIDDEN_ALGO:
459         reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
460     elif status == HYP_HIDING_ALGO:
461         reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
462     elif status == HYP_NEED_SHAPE:
463         reason = "Algorithm can't work without shape"
464     else:
465         return
466     hypName = '"' + hypName + '"'
467     geomName= '"' + geomName+ '"'
468     if status < HYP_UNKNOWN_FATAL and not geomName =='""':
469         print hypName, "was assigned to",    geomName,"but", reason
470     elif not geomName == '""':
471         print hypName, "was not assigned to",geomName,":", reason
472     else:
473         print hypName, "was not assigned:", reason
474         pass
475
476 ## Check meshing plugin availability
477 def CheckPlugin(plugin):
478     if plugin == NETGEN and noNETGENPlugin:
479         print "Warning: NETGENPlugin module unavailable"
480         return False
481     elif plugin == GHS3D and noGHS3DPlugin:
482         print "Warning: GHS3DPlugin module unavailable"
483         return False
484     elif plugin == GHS3DPRL and noGHS3DPRLPlugin:
485         print "Warning: GHS3DPRLPlugin module unavailable"
486         return False
487     elif plugin == Hexotic and noHexoticPlugin:
488         print "Warning: HexoticPlugin module unavailable"
489         return False
490     elif plugin == BLSURF and noBLSURFPlugin:
491         print "Warning: BLSURFPlugin module unavailable"
492         return False
493     return True
494     
495 # end of l1_auxiliary
496 ## @}
497
498 # All methods of this class are accessible directly from the smesh.py package.
499 class smeshDC(SMESH._objref_SMESH_Gen):
500
501     ## Sets the current study and Geometry component
502     #  @ingroup l1_auxiliary
503     def init_smesh(self,theStudy,geompyD):
504         self.SetCurrentStudy(theStudy,geompyD)
505
506     ## Creates an empty Mesh. This mesh can have an underlying geometry.
507     #  @param obj the Geometrical object on which the mesh is built. If not defined,
508     #             the mesh will have no underlying geometry.
509     #  @param name the name for the new mesh.
510     #  @return an instance of Mesh class.
511     #  @ingroup l2_construct
512     def Mesh(self, obj=0, name=0):
513         if isinstance(obj,str):
514             obj,name = name,obj
515         return Mesh(self,self.geompyD,obj,name)
516
517     ## Returns a long value from enumeration
518     #  Should be used for SMESH.FunctorType enumeration
519     #  @ingroup l1_controls
520     def EnumToLong(self,theItem):
521         return theItem._v
522
523     ## Returns a string representation of the color.
524     #  To be used with filters.
525     #  @param c color value (SALOMEDS.Color)
526     #  @ingroup l1_controls
527     def ColorToString(self,c):
528         val = ""
529         if isinstance(c, SALOMEDS.Color):
530             val = "%s;%s;%s" % (c.R, c.G, c.B)
531         elif isinstance(c, str):
532             val = c
533         else:
534             raise ValueError, "Color value should be of string or SALOMEDS.Color type"
535         return val
536
537     ## Gets PointStruct from vertex
538     #  @param theVertex a GEOM object(vertex)
539     #  @return SMESH.PointStruct
540     #  @ingroup l1_auxiliary
541     def GetPointStruct(self,theVertex):
542         [x, y, z] = self.geompyD.PointCoordinates(theVertex)
543         return PointStruct(x,y,z)
544
545     ## Gets DirStruct from vector
546     #  @param theVector a GEOM object(vector)
547     #  @return SMESH.DirStruct
548     #  @ingroup l1_auxiliary
549     def GetDirStruct(self,theVector):
550         vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
551         if(len(vertices) != 2):
552             print "Error: vector object is incorrect."
553             return None
554         p1 = self.geompyD.PointCoordinates(vertices[0])
555         p2 = self.geompyD.PointCoordinates(vertices[1])
556         pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
557         dirst = DirStruct(pnt)
558         return dirst
559
560     ## Makes DirStruct from a triplet
561     #  @param x,y,z vector components
562     #  @return SMESH.DirStruct
563     #  @ingroup l1_auxiliary
564     def MakeDirStruct(self,x,y,z):
565         pnt = PointStruct(x,y,z)
566         return DirStruct(pnt)
567
568     ## Get AxisStruct from object
569     #  @param theObj a GEOM object (line or plane)
570     #  @return SMESH.AxisStruct
571     #  @ingroup l1_auxiliary
572     def GetAxisStruct(self,theObj):
573         edges = self.geompyD.ExtractShapes( theObj, geompyDC.ShapeType["EDGE"] )
574         if len(edges) > 1:
575             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
576             vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
577             vertex1 = self.geompyD.PointCoordinates(vertex1)
578             vertex2 = self.geompyD.PointCoordinates(vertex2)
579             vertex3 = self.geompyD.PointCoordinates(vertex3)
580             vertex4 = self.geompyD.PointCoordinates(vertex4)
581             v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
582             v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
583             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] ]
584             axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
585             return axis
586         elif len(edges) == 1:
587             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
588             p1 = self.geompyD.PointCoordinates( vertex1 )
589             p2 = self.geompyD.PointCoordinates( vertex2 )
590             axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
591             return axis
592         return None
593
594     # From SMESH_Gen interface:
595     # ------------------------
596
597     ## Sets the given name to the object
598     #  @param obj the object to rename
599     #  @param name a new object name
600     #  @ingroup l1_auxiliary
601     def SetName(self, obj, name):
602         if isinstance( obj, Mesh ):
603             obj = obj.GetMesh()
604         elif isinstance( obj, Mesh_Algorithm ):
605             obj = obj.GetAlgorithm()
606         ior  = salome.orb.object_to_string(obj)
607         SMESH._objref_SMESH_Gen.SetName(self, ior, name)
608
609     ## Sets the current mode
610     #  @ingroup l1_auxiliary
611     def SetEmbeddedMode( self,theMode ):
612         #self.SetEmbeddedMode(theMode)
613         SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
614
615     ## Gets the current mode
616     #  @ingroup l1_auxiliary
617     def IsEmbeddedMode(self):
618         #return self.IsEmbeddedMode()
619         return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
620
621     ## Sets the current study
622     #  @ingroup l1_auxiliary
623     def SetCurrentStudy( self, theStudy, geompyD = None ):
624         #self.SetCurrentStudy(theStudy)
625         if not geompyD:
626             import geompy
627             geompyD = geompy.geom
628             pass
629         self.geompyD=geompyD
630         self.SetGeomEngine(geompyD)
631         SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
632
633     ## Gets the current study
634     #  @ingroup l1_auxiliary
635     def GetCurrentStudy(self):
636         #return self.GetCurrentStudy()
637         return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
638
639     ## Creates a Mesh object importing data from the given UNV file
640     #  @return an instance of Mesh class
641     #  @ingroup l2_impexp
642     def CreateMeshesFromUNV( self,theFileName ):
643         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
644         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
645         return aMesh
646
647     ## Creates a Mesh object(s) importing data from the given MED file
648     #  @return a list of Mesh class instances
649     #  @ingroup l2_impexp
650     def CreateMeshesFromMED( self,theFileName ):
651         aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
652         aMeshes = []
653         for iMesh in range(len(aSmeshMeshes)) :
654             aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
655             aMeshes.append(aMesh)
656         return aMeshes, aStatus
657
658     ## Creates a Mesh object importing data from the given STL file
659     #  @return an instance of Mesh class
660     #  @ingroup l2_impexp
661     def CreateMeshesFromSTL( self, theFileName ):
662         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
663         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
664         return aMesh
665
666     ## Concatenate the given meshes into one mesh.
667     #  @return an instance of Mesh class
668     #  @param meshes the meshes to combine into one mesh
669     #  @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
670     #  @param mergeNodesAndElements if true, equal nodes and elements aremerged
671     #  @param mergeTolerance tolerance for merging nodes
672     #  @param allGroups forces creation of groups of all elements
673     def Concatenate( self, meshes, uniteIdenticalGroups,
674                      mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
675         mergeTolerance,Parameters = geompyDC.ParseParameters(mergeTolerance)
676         for i,m in enumerate(meshes):
677             if isinstance(m, Mesh):
678                 meshes[i] = m.GetMesh()
679         if allGroups:
680             aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
681                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
682         else:
683             aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
684                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
685         aSmeshMesh.SetParameters(Parameters)
686         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
687         return aMesh
688
689     ## Create a mesh by copying a part of another mesh.
690     #  @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
691     #                  to copy nodes or elements not contained in any mesh object,
692     #                  pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
693     #  @param meshName a name of the new mesh
694     #  @param toCopyGroups to create in the new mesh groups the copied elements belongs to
695     #  @param toKeepIDs to preserve IDs of the copied elements or not
696     #  @return an instance of Mesh class
697     def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
698         if (isinstance( meshPart, Mesh )):
699             meshPart = meshPart.GetMesh()
700         mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
701         return Mesh(self, self.geompyD, mesh)
702
703     ## From SMESH_Gen interface
704     #  @return the list of integer values
705     #  @ingroup l1_auxiliary
706     def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
707         return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
708
709     ## From SMESH_Gen interface. Creates a pattern
710     #  @return an instance of SMESH_Pattern
711     #
712     #  <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
713     #  @ingroup l2_modif_patterns
714     def GetPattern(self):
715         return SMESH._objref_SMESH_Gen.GetPattern(self)
716
717     ## Sets number of segments per diagonal of boundary box of geometry by which
718     #  default segment length of appropriate 1D hypotheses is defined.
719     #  Default value is 10
720     #  @ingroup l1_auxiliary
721     def SetBoundaryBoxSegmentation(self, nbSegments):
722         SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
723
724     # Filtering. Auxiliary functions:
725     # ------------------------------
726
727     ## Creates an empty criterion
728     #  @return SMESH.Filter.Criterion
729     #  @ingroup l1_controls
730     def GetEmptyCriterion(self):
731         Type = self.EnumToLong(FT_Undefined)
732         Compare = self.EnumToLong(FT_Undefined)
733         Threshold = 0
734         ThresholdStr = ""
735         ThresholdID = ""
736         UnaryOp = self.EnumToLong(FT_Undefined)
737         BinaryOp = self.EnumToLong(FT_Undefined)
738         Tolerance = 1e-07
739         TypeOfElement = ALL
740         Precision = -1 ##@1e-07
741         return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
742                                 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
743
744     ## Creates a criterion by the given parameters
745     #  @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
746     #  @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
747     #  @param Compare  belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
748     #  @param Treshold the threshold value (range of ids as string, shape, numeric)
749     #  @param UnaryOp  FT_LogicalNOT or FT_Undefined
750     #  @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
751     #                  FT_Undefined (must be for the last criterion of all criteria)
752     #  @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
753     #         FT_LyingOnGeom, FT_CoplanarFaces criteria
754     #  @return SMESH.Filter.Criterion
755     #  @ingroup l1_controls
756     def GetCriterion(self,elementType,
757                      CritType,
758                      Compare = FT_EqualTo,
759                      Treshold="",
760                      UnaryOp=FT_Undefined,
761                      BinaryOp=FT_Undefined,
762                      Tolerance=1e-07):
763         aCriterion = self.GetEmptyCriterion()
764         aCriterion.TypeOfElement = elementType
765         aCriterion.Type = self.EnumToLong(CritType)
766         aCriterion.Tolerance = Tolerance
767
768         aTreshold = Treshold
769
770         if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
771             aCriterion.Compare = self.EnumToLong(Compare)
772         elif Compare == "=" or Compare == "==":
773             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
774         elif Compare == "<":
775             aCriterion.Compare = self.EnumToLong(FT_LessThan)
776         elif Compare == ">":
777             aCriterion.Compare = self.EnumToLong(FT_MoreThan)
778         else:
779             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
780             aTreshold = Compare
781
782         if CritType in [FT_BelongToGeom,     FT_BelongToPlane, FT_BelongToGenSurface,
783                         FT_BelongToCylinder, FT_LyingOnGeom]:
784             # Checks the treshold
785             if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
786                 aCriterion.ThresholdStr = GetName(aTreshold)
787                 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
788             else:
789                 print "Error: The treshold should be a shape."
790                 return None
791         elif CritType == FT_RangeOfIds:
792             # Checks the treshold
793             if isinstance(aTreshold, str):
794                 aCriterion.ThresholdStr = aTreshold
795             else:
796                 print "Error: The treshold should be a string."
797                 return None
798         elif CritType == FT_CoplanarFaces:
799             # Checks the treshold
800             if isinstance(aTreshold, int):
801                 aCriterion.ThresholdID = "%s"%aTreshold
802             elif isinstance(aTreshold, str):
803                 ID = int(aTreshold)
804                 if ID < 1:
805                     raise ValueError, "Invalid ID of mesh face: '%s'"%aTreshold
806                 aCriterion.ThresholdID = aTreshold
807             else:
808                 raise ValueError,\
809                       "The treshold should be an ID of mesh face and not '%s'"%aTreshold
810         elif CritType == FT_ElemGeomType:
811             # Checks the treshold
812             try:
813                 aCriterion.Threshold = self.EnumToLong(aTreshold)
814             except:
815                 if isinstance(aTreshold, int):
816                     aCriterion.Threshold = aTreshold
817                 else:
818                     print "Error: The treshold should be an integer or SMESH.GeometryType."
819                     return None
820                 pass
821             pass
822         elif CritType == FT_GroupColor:
823             # Checks the treshold
824             try:
825                 aCriterion.ThresholdStr = self.ColorToString(aTreshold)
826             except:
827                 print "Error: The threshold value should be of SALOMEDS.Color type"
828                 return None
829             pass
830         elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume, FT_FreeNodes,
831                           FT_FreeFaces, FT_LinearOrQuadratic,
832                           FT_BareBorderFace, FT_BareBorderVolume,
833                           FT_OverConstrainedFace, FT_OverConstrainedVolume]:
834             # At this point the treshold is unnecessary
835             if aTreshold ==  FT_LogicalNOT:
836                 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
837             elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
838                 aCriterion.BinaryOp = aTreshold
839         else:
840             # Check treshold
841             try:
842                 aTreshold = float(aTreshold)
843                 aCriterion.Threshold = aTreshold
844             except:
845                 print "Error: The treshold should be a number."
846                 return None
847
848         if Treshold ==  FT_LogicalNOT or UnaryOp ==  FT_LogicalNOT:
849             aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
850
851         if Treshold in [FT_LogicalAND, FT_LogicalOR]:
852             aCriterion.BinaryOp = self.EnumToLong(Treshold)
853
854         if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
855             aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
856
857         if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
858             aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
859
860         return aCriterion
861
862     ## Creates a filter with the given parameters
863     #  @param elementType the type of elements in the group
864     #  @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
865     #  @param Compare  belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
866     #  @param Treshold the threshold value (range of id ids as string, shape, numeric)
867     #  @param UnaryOp  FT_LogicalNOT or FT_Undefined
868     #  @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
869     #         FT_LyingOnGeom, FT_CoplanarFaces criteria
870     #  @return SMESH_Filter
871     #  @ingroup l1_controls
872     def GetFilter(self,elementType,
873                   CritType=FT_Undefined,
874                   Compare=FT_EqualTo,
875                   Treshold="",
876                   UnaryOp=FT_Undefined,
877                   Tolerance=1e-07):
878         aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined,Tolerance)
879         aFilterMgr = self.CreateFilterManager()
880         aFilter = aFilterMgr.CreateFilter()
881         aCriteria = []
882         aCriteria.append(aCriterion)
883         aFilter.SetCriteria(aCriteria)
884         aFilterMgr.Destroy()
885         return aFilter
886
887     ## Creates a numerical functor by its type
888     #  @param theCriterion FT_...; functor type
889     #  @return SMESH_NumericalFunctor
890     #  @ingroup l1_controls
891     def GetFunctor(self,theCriterion):
892         aFilterMgr = self.CreateFilterManager()
893         if theCriterion == FT_AspectRatio:
894             return aFilterMgr.CreateAspectRatio()
895         elif theCriterion == FT_AspectRatio3D:
896             return aFilterMgr.CreateAspectRatio3D()
897         elif theCriterion == FT_Warping:
898             return aFilterMgr.CreateWarping()
899         elif theCriterion == FT_MinimumAngle:
900             return aFilterMgr.CreateMinimumAngle()
901         elif theCriterion == FT_Taper:
902             return aFilterMgr.CreateTaper()
903         elif theCriterion == FT_Skew:
904             return aFilterMgr.CreateSkew()
905         elif theCriterion == FT_Area:
906             return aFilterMgr.CreateArea()
907         elif theCriterion == FT_Volume3D:
908             return aFilterMgr.CreateVolume3D()
909         elif theCriterion == FT_MaxElementLength2D:
910             return aFilterMgr.CreateMaxElementLength2D()
911         elif theCriterion == FT_MaxElementLength3D:
912             return aFilterMgr.CreateMaxElementLength3D()
913         elif theCriterion == FT_MultiConnection:
914             return aFilterMgr.CreateMultiConnection()
915         elif theCriterion == FT_MultiConnection2D:
916             return aFilterMgr.CreateMultiConnection2D()
917         elif theCriterion == FT_Length:
918             return aFilterMgr.CreateLength()
919         elif theCriterion == FT_Length2D:
920             return aFilterMgr.CreateLength2D()
921         else:
922             print "Error: given parameter is not numerucal functor type."
923
924     ## Creates hypothesis
925     #  @param theHType mesh hypothesis type (string)
926     #  @param theLibName mesh plug-in library name
927     #  @return created hypothesis instance
928     def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
929         return SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
930
931     ## Gets the mesh stattistic
932     #  @return dictionary type element - count of elements
933     #  @ingroup l1_meshinfo
934     def GetMeshInfo(self, obj):
935         if isinstance( obj, Mesh ):
936             obj = obj.GetMesh()
937         d = {}
938         if hasattr(obj, "_narrow") and obj._narrow(SMESH.SMESH_IDSource):
939             values = obj.GetMeshInfo() 
940             for i in range(SMESH.Entity_Last._v):
941                 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
942             pass
943         return d
944
945     ## Get minimum distance between two objects
946     #
947     #  If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
948     #  If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
949     #
950     #  @param src1 first source object 
951     #  @param src2 second source object
952     #  @param id1 node/element id from the first source
953     #  @param id2 node/element id from the second (or first) source
954     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
955     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
956     #  @return minimum distance value
957     #  @sa GetMinDistance()
958     #  @ingroup l1_measurements
959     def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
960         result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
961         if result is None:
962             result = 0.0
963         else:
964             result = result.value
965         return result
966     
967     ## Get measure structure specifying minimum distance data between two objects
968     #
969     #  If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
970     #  If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
971     #
972     #  @param src1 first source object 
973     #  @param src2 second source object
974     #  @param id1 node/element id from the first source
975     #  @param id2 node/element id from the second (or first) source
976     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
977     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
978     #  @return Measure structure or None if input data is invalid
979     #  @sa MinDistance()
980     #  @ingroup l1_measurements
981     def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
982         if isinstance(src1, Mesh): src1 = src1.mesh
983         if isinstance(src2, Mesh): src2 = src2.mesh
984         if src2 is None and id2 != 0: src2 = src1
985         if not hasattr(src1, "_narrow"): return None
986         src1 = src1._narrow(SMESH.SMESH_IDSource)
987         if not src1: return None
988         if id1 != 0:
989             m = src1.GetMesh()
990             e = m.GetMeshEditor()
991             if isElem1:
992                 src1 = e.MakeIDSource([id1], SMESH.FACE)
993             else:
994                 src1 = e.MakeIDSource([id1], SMESH.NODE)
995             pass
996         if hasattr(src2, "_narrow"):
997             src2 = src2._narrow(SMESH.SMESH_IDSource)
998             if src2 and id2 != 0:
999                 m = src2.GetMesh()
1000                 e = m.GetMeshEditor()
1001                 if isElem2:
1002                     src2 = e.MakeIDSource([id2], SMESH.FACE)
1003                 else:
1004                     src2 = e.MakeIDSource([id2], SMESH.NODE)
1005                 pass
1006             pass
1007         aMeasurements = self.CreateMeasurements()
1008         result = aMeasurements.MinDistance(src1, src2)
1009         aMeasurements.Destroy()
1010         return result
1011     
1012     ## Get bounding box of the specified object(s)
1013     #  @param objects single source object or list of source objects
1014     #  @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1015     #  @sa GetBoundingBox()
1016     #  @ingroup l1_measurements
1017     def BoundingBox(self, objects):
1018         result = self.GetBoundingBox(objects)
1019         if result is None:
1020             result = (0.0,)*6
1021         else:
1022             result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1023         return result
1024
1025     ## Get measure structure specifying bounding box data of the specified object(s)
1026     #  @param objects single source object or list of source objects
1027     #  @return Measure structure
1028     #  @sa BoundingBox()
1029     #  @ingroup l1_measurements
1030     def GetBoundingBox(self, objects):
1031         if isinstance(objects, tuple):
1032             objects = list(objects)
1033         if not isinstance(objects, list):
1034             objects = [objects]
1035         srclist = []
1036         for o in objects:
1037             if isinstance(o, Mesh):
1038                 srclist.append(o.mesh)
1039             elif hasattr(o, "_narrow"):
1040                 src = o._narrow(SMESH.SMESH_IDSource)
1041                 if src: srclist.append(src)
1042                 pass
1043             pass
1044         aMeasurements = self.CreateMeasurements()
1045         result = aMeasurements.BoundingBox(srclist)
1046         aMeasurements.Destroy()
1047         return result
1048
1049 import omniORB
1050 #Registering the new proxy for SMESH_Gen
1051 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
1052
1053
1054 # Public class: Mesh
1055 # ==================
1056
1057 ## This class allows defining and managing a mesh.
1058 #  It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1059 #  It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1060 #  new nodes and elements and by changing the existing entities), to get information
1061 #  about a mesh and to export a mesh into different formats.
1062 class Mesh:
1063
1064     geom = 0
1065     mesh = 0
1066     editor = 0
1067
1068     ## Constructor
1069     #
1070     #  Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1071     #  sets the GUI name of this mesh to \a name.
1072     #  @param smeshpyD an instance of smeshDC class
1073     #  @param geompyD an instance of geompyDC class
1074     #  @param obj Shape to be meshed or SMESH_Mesh object
1075     #  @param name Study name of the mesh
1076     #  @ingroup l2_construct
1077     def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1078         self.smeshpyD=smeshpyD
1079         self.geompyD=geompyD
1080         if obj is None:
1081             obj = 0
1082         if obj != 0:
1083             if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1084                 self.geom = obj
1085                 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1086             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1087                 self.SetMesh(obj)
1088         else:
1089             self.mesh = self.smeshpyD.CreateEmptyMesh()
1090         if name != 0:
1091             self.smeshpyD.SetName(self.mesh, name)
1092         elif obj != 0:
1093             self.smeshpyD.SetName(self.mesh, GetName(obj))
1094
1095         if not self.geom:
1096             self.geom = self.mesh.GetShapeToMesh()
1097
1098         self.editor = self.mesh.GetMeshEditor()
1099
1100     ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1101     #  @param theMesh a SMESH_Mesh object
1102     #  @ingroup l2_construct
1103     def SetMesh(self, theMesh):
1104         self.mesh = theMesh
1105         self.geom = self.mesh.GetShapeToMesh()
1106
1107     ## Returns the mesh, that is an instance of SMESH_Mesh interface
1108     #  @return a SMESH_Mesh object
1109     #  @ingroup l2_construct
1110     def GetMesh(self):
1111         return self.mesh
1112
1113     ## Gets the name of the mesh
1114     #  @return the name of the mesh as a string
1115     #  @ingroup l2_construct
1116     def GetName(self):
1117         name = GetName(self.GetMesh())
1118         return name
1119
1120     ## Sets a name to the mesh
1121     #  @param name a new name of the mesh
1122     #  @ingroup l2_construct
1123     def SetName(self, name):
1124         self.smeshpyD.SetName(self.GetMesh(), name)
1125
1126     ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1127     #  The subMesh object gives access to the IDs of nodes and elements.
1128     #  @param theSubObject a geometrical object (shape)
1129     #  @param theName a name for the submesh
1130     #  @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1131     #  @ingroup l2_submeshes
1132     def GetSubMesh(self, theSubObject, theName):
1133         submesh = self.mesh.GetSubMesh(theSubObject, theName)
1134         return submesh
1135
1136     ## Returns the shape associated to the mesh
1137     #  @return a GEOM_Object
1138     #  @ingroup l2_construct
1139     def GetShape(self):
1140         return self.geom
1141
1142     ## Associates the given shape to the mesh (entails the recreation of the mesh)
1143     #  @param geom the shape to be meshed (GEOM_Object)
1144     #  @ingroup l2_construct
1145     def SetShape(self, geom):
1146         self.mesh = self.smeshpyD.CreateMesh(geom)
1147
1148     ## Returns true if the hypotheses are defined well
1149     #  @param theSubObject a subshape of a mesh shape
1150     #  @return True or False
1151     #  @ingroup l2_construct
1152     def IsReadyToCompute(self, theSubObject):
1153         return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1154
1155     ## Returns errors of hypotheses definition.
1156     #  The list of errors is empty if everything is OK.
1157     #  @param theSubObject a subshape of a mesh shape
1158     #  @return a list of errors
1159     #  @ingroup l2_construct
1160     def GetAlgoState(self, theSubObject):
1161         return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1162
1163     ## Returns a geometrical object on which the given element was built.
1164     #  The returned geometrical object, if not nil, is either found in the
1165     #  study or published by this method with the given name
1166     #  @param theElementID the id of the mesh element
1167     #  @param theGeomName the user-defined name of the geometrical object
1168     #  @return GEOM::GEOM_Object instance
1169     #  @ingroup l2_construct
1170     def GetGeometryByMeshElement(self, theElementID, theGeomName):
1171         return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1172
1173     ## Returns the mesh dimension depending on the dimension of the underlying shape
1174     #  @return mesh dimension as an integer value [0,3]
1175     #  @ingroup l1_auxiliary
1176     def MeshDimension(self):
1177         shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1178         if len( shells ) > 0 :
1179             return 3
1180         elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1181             return 2
1182         elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1183             return 1
1184         else:
1185             return 0;
1186         pass
1187
1188     ## Creates a segment discretization 1D algorithm.
1189     #  If the optional \a algo parameter is not set, this algorithm is REGULAR.
1190     #  \n If the optional \a geom parameter is not set, this algorithm is global.
1191     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1192     #  @param algo the type of the required algorithm. Possible values are:
1193     #     - smesh.REGULAR,
1194     #     - smesh.PYTHON for discretization via a python function,
1195     #     - smesh.COMPOSITE for meshing a set of edges on one face side as a whole.
1196     #  @param geom If defined is the subshape to be meshed
1197     #  @return an instance of Mesh_Segment or Mesh_Segment_Python, or Mesh_CompositeSegment class
1198     #  @ingroup l3_algos_basic
1199     def Segment(self, algo=REGULAR, geom=0):
1200         ## if Segment(geom) is called by mistake
1201         if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1202             algo, geom = geom, algo
1203             if not algo: algo = REGULAR
1204             pass
1205         if algo == REGULAR:
1206             return Mesh_Segment(self,  geom)
1207         elif algo == PYTHON:
1208             return Mesh_Segment_Python(self, geom)
1209         elif algo == COMPOSITE:
1210             return Mesh_CompositeSegment(self, geom)
1211         else:
1212             return Mesh_Segment(self, geom)
1213
1214     ## Creates 1D algorithm importing segments conatined in groups of other mesh.
1215     #  If the optional \a geom parameter is not set, this algorithm is global.
1216     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1217     #  @param geom If defined the subshape is to be meshed
1218     #  @return an instance of Mesh_UseExistingElements class
1219     #  @ingroup l3_algos_basic
1220     def UseExisting1DElements(self, geom=0):
1221         return Mesh_UseExistingElements(1,self, geom)
1222
1223     ## Creates 2D algorithm importing faces conatined in groups of other mesh.
1224     #  If the optional \a geom parameter is not set, this algorithm is global.
1225     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1226     #  @param geom If defined the subshape is to be meshed
1227     #  @return an instance of Mesh_UseExistingElements class
1228     #  @ingroup l3_algos_basic
1229     def UseExisting2DElements(self, geom=0):
1230         return Mesh_UseExistingElements(2,self, geom)
1231
1232     ## Enables creation of nodes and segments usable by 2D algoritms.
1233     #  The added nodes and segments must be bound to edges and vertices by
1234     #  SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
1235     #  If the optional \a geom parameter is not set, this algorithm is global.
1236     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1237     #  @param geom the subshape to be manually meshed
1238     #  @return StdMeshers_UseExisting_1D algorithm that generates nothing
1239     #  @ingroup l3_algos_basic
1240     def UseExistingSegments(self, geom=0):
1241         algo = Mesh_UseExisting(1,self,geom)
1242         return algo.GetAlgorithm()
1243
1244     ## Enables creation of nodes and faces usable by 3D algoritms.
1245     #  The added nodes and faces must be bound to geom faces by SetNodeOnFace()
1246     #  and SetMeshElementOnShape()
1247     #  If the optional \a geom parameter is not set, this algorithm is global.
1248     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1249     #  @param geom the subshape to be manually meshed
1250     #  @return StdMeshers_UseExisting_2D algorithm that generates nothing
1251     #  @ingroup l3_algos_basic
1252     def UseExistingFaces(self, geom=0):
1253         algo = Mesh_UseExisting(2,self,geom)
1254         return algo.GetAlgorithm()
1255
1256     ## Creates a triangle 2D algorithm for faces.
1257     #  If the optional \a geom parameter is not set, this algorithm is global.
1258     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1259     #  @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D || smesh.BLSURF
1260     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
1261     #  @return an instance of Mesh_Triangle algorithm
1262     #  @ingroup l3_algos_basic
1263     def Triangle(self, algo=MEFISTO, geom=0):
1264         ## if Triangle(geom) is called by mistake
1265         if (isinstance(algo, geompyDC.GEOM._objref_GEOM_Object)):
1266             geom = algo
1267             algo = MEFISTO
1268         return Mesh_Triangle(self, algo, geom)
1269
1270     ## Creates a quadrangle 2D algorithm for faces.
1271     #  If the optional \a geom parameter is not set, this algorithm is global.
1272     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1273     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
1274     #  @param algo values are: smesh.QUADRANGLE || smesh.RADIAL_QUAD
1275     #  @return an instance of Mesh_Quadrangle algorithm
1276     #  @ingroup l3_algos_basic
1277     def Quadrangle(self, geom=0, algo=QUADRANGLE):
1278         if algo==RADIAL_QUAD:
1279             return Mesh_RadialQuadrangle1D2D(self,geom)
1280         else:
1281             return Mesh_Quadrangle(self, geom)
1282
1283     ## Creates a tetrahedron 3D algorithm for solids.
1284     #  The parameter \a algo permits to choose the algorithm: NETGEN or GHS3D
1285     #  If the optional \a geom parameter is not set, this algorithm is global.
1286     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1287     #  @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.GHS3DPRL, smesh.FULL_NETGEN
1288     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
1289     #  @return an instance of Mesh_Tetrahedron algorithm
1290     #  @ingroup l3_algos_basic
1291     def Tetrahedron(self, algo=NETGEN, geom=0):
1292         ## if Tetrahedron(geom) is called by mistake
1293         if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1294             algo, geom = geom, algo
1295             if not algo: algo = NETGEN
1296             pass
1297         return Mesh_Tetrahedron(self,  algo, geom)
1298
1299     ## Creates a hexahedron 3D algorithm for solids.
1300     #  If the optional \a geom parameter is not set, this algorithm is global.
1301     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
1302     #  @param algo possible values are: smesh.Hexa, smesh.Hexotic
1303     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
1304     #  @return an instance of Mesh_Hexahedron algorithm
1305     #  @ingroup l3_algos_basic
1306     def Hexahedron(self, algo=Hexa, geom=0):
1307         ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1308         if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
1309             if   geom in [Hexa, Hexotic]: algo, geom = geom, algo
1310             elif geom == 0:               algo, geom = Hexa, algo
1311         return Mesh_Hexahedron(self, algo, geom)
1312
1313     ## Deprecated, used only for compatibility!
1314     #  @return an instance of Mesh_Netgen algorithm
1315     #  @ingroup l3_algos_basic
1316     def Netgen(self, is3D, geom=0):
1317         return Mesh_Netgen(self,  is3D, geom)
1318
1319     ## Creates a projection 1D algorithm for edges.
1320     #  If the optional \a geom parameter is not set, this algorithm is global.
1321     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1322     #  @param geom If defined, the subshape to be meshed
1323     #  @return an instance of Mesh_Projection1D algorithm
1324     #  @ingroup l3_algos_proj
1325     def Projection1D(self, geom=0):
1326         return Mesh_Projection1D(self,  geom)
1327
1328     ## Creates a projection 2D algorithm for faces.
1329     #  If the optional \a geom parameter is not set, this algorithm is global.
1330     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1331     #  @param geom If defined, the subshape to be meshed
1332     #  @return an instance of Mesh_Projection2D algorithm
1333     #  @ingroup l3_algos_proj
1334     def Projection2D(self, geom=0):
1335         return Mesh_Projection2D(self,  geom)
1336
1337     ## Creates a projection 3D algorithm for solids.
1338     #  If the optional \a geom parameter is not set, this algorithm is global.
1339     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1340     #  @param geom If defined, the subshape to be meshed
1341     #  @return an instance of Mesh_Projection3D algorithm
1342     #  @ingroup l3_algos_proj
1343     def Projection3D(self, geom=0):
1344         return Mesh_Projection3D(self,  geom)
1345
1346     ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1347     #  If the optional \a geom parameter is not set, this algorithm is global.
1348     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
1349     #  @param geom If defined, the subshape to be meshed
1350     #  @return an instance of Mesh_Prism3D or Mesh_RadialPrism3D algorithm
1351     #  @ingroup l3_algos_radialp l3_algos_3dextr
1352     def Prism(self, geom=0):
1353         shape = geom
1354         if shape==0:
1355             shape = self.geom
1356         nbSolids = len( self.geompyD.ExtractShapes( shape, geompyDC.ShapeType["SOLID"] ))
1357         nbShells = len( self.geompyD.ExtractShapes( shape, geompyDC.ShapeType["SHELL"] ))
1358         if nbSolids == 0 or nbSolids == nbShells:
1359             return Mesh_Prism3D(self,  geom)
1360         return Mesh_RadialPrism3D(self,  geom)
1361
1362     ## Evaluates size of prospective mesh on a shape
1363     #  @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1364     #  To know predicted number of e.g. edges, inquire it this way
1365     #  Evaluate()[ EnumToLong( Entity_Edge )]
1366     def Evaluate(self, geom=0):
1367         if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1368             if self.geom == 0:
1369                 geom = self.mesh.GetShapeToMesh()
1370             else:
1371                 geom = self.geom
1372         return self.smeshpyD.Evaluate(self.mesh, geom)
1373
1374
1375     ## Computes the mesh and returns the status of the computation
1376     #  @param geom geomtrical shape on which mesh data should be computed
1377     #  @param discardModifs if True and the mesh has been edited since
1378     #         a last total re-compute and that may prevent successful partial re-compute,
1379     #         then the mesh is cleaned before Compute()
1380     #  @return True or False
1381     #  @ingroup l2_construct
1382     def Compute(self, geom=0, discardModifs=False):
1383         if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1384             if self.geom == 0:
1385                 geom = self.mesh.GetShapeToMesh()
1386             else:
1387                 geom = self.geom
1388         ok = False
1389         try:
1390             if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1391                 self.mesh.Clear()
1392             ok = self.smeshpyD.Compute(self.mesh, geom)
1393         except SALOME.SALOME_Exception, ex:
1394             print "Mesh computation failed, exception caught:"
1395             print "    ", ex.details.text
1396         except:
1397             import traceback
1398             print "Mesh computation failed, exception caught:"
1399             traceback.print_exc()
1400         if True:#not ok:
1401             allReasons = ""
1402
1403             # Treat compute errors
1404             computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1405             for err in computeErrors:
1406                 shapeText = ""
1407                 if self.mesh.HasShapeToMesh():
1408                     try:
1409                         mainIOR  = salome.orb.object_to_string(geom)
1410                         for sname in salome.myStudyManager.GetOpenStudies():
1411                             s = salome.myStudyManager.GetStudyByName(sname)
1412                             if not s: continue
1413                             mainSO = s.FindObjectIOR(mainIOR)
1414                             if not mainSO: continue
1415                             if err.subShapeID == 1:
1416                                 shapeText = ' on "%s"' % mainSO.GetName()
1417                             subIt = s.NewChildIterator(mainSO)
1418                             while subIt.More():
1419                                 subSO = subIt.Value()
1420                                 subIt.Next()
1421                                 obj = subSO.GetObject()
1422                                 if not obj: continue
1423                                 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1424                                 if not go: continue
1425                                 ids = go.GetSubShapeIndices()
1426                                 if len(ids) == 1 and ids[0] == err.subShapeID:
1427                                     shapeText = ' on "%s"' % subSO.GetName()
1428                                     break
1429                         if not shapeText:
1430                             shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1431                             if shape:
1432                                 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1433                             else:
1434                                 shapeText = " on subshape #%s" % (err.subShapeID)
1435                     except:
1436                         shapeText = " on subshape #%s" % (err.subShapeID)
1437                 errText = ""
1438                 stdErrors = ["OK",                 #COMPERR_OK            
1439                              "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1440                              "std::exception",     #COMPERR_STD_EXCEPTION 
1441                              "OCC exception",      #COMPERR_OCC_EXCEPTION 
1442                              "SALOME exception",   #COMPERR_SLM_EXCEPTION 
1443                              "Unknown exception",  #COMPERR_EXCEPTION     
1444                              "Memory allocation problem", #COMPERR_MEMORY_PB     
1445                              "Algorithm failed",   #COMPERR_ALGO_FAILED   
1446                              "Unexpected geometry"]#COMPERR_BAD_SHAPE
1447                 if err.code > 0:
1448                     if err.code < len(stdErrors): errText = stdErrors[err.code]
1449                 else:
1450                     errText = "code %s" % -err.code
1451                 if errText: errText += ". "
1452                 errText += err.comment
1453                 if allReasons != "":allReasons += "\n"
1454                 allReasons += '"%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1455                 pass
1456
1457             # Treat hyp errors
1458             errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1459             for err in errors:
1460                 if err.isGlobalAlgo:
1461                     glob = "global"
1462                 else:
1463                     glob = "local"
1464                     pass
1465                 dim = err.algoDim
1466                 name = err.algoName
1467                 if len(name) == 0:
1468                     reason = '%s %sD algorithm is missing' % (glob, dim)
1469                 elif err.state == HYP_MISSING:
1470                     reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1471                               % (glob, dim, name, dim))
1472                 elif err.state == HYP_NOTCONFORM:
1473                     reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1474                 elif err.state == HYP_BAD_PARAMETER:
1475                     reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1476                               % ( glob, dim, name ))
1477                 elif err.state == HYP_BAD_GEOMETRY:
1478                     reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1479                               'geometry' % ( glob, dim, name ))
1480                 else:
1481                     reason = "For unknown reason."+\
1482                              " Revise Mesh.Compute() implementation in smeshDC.py!"
1483                     pass
1484                 if allReasons != "":allReasons += "\n"
1485                 allReasons += reason
1486                 pass
1487             if allReasons != "":
1488                 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1489                 print allReasons
1490                 ok = False
1491             elif not ok:
1492                 print '"' + GetName(self.mesh) + '"',"has not been computed."
1493                 pass
1494             pass
1495         if salome.sg.hasDesktop():
1496             smeshgui = salome.ImportComponentGUI("SMESH")
1497             smeshgui.Init(self.mesh.GetStudyId())
1498             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1499             salome.sg.updateObjBrowser(1)
1500             pass
1501         return ok
1502
1503     ## Return submesh objects list in meshing order
1504     #  @return list of list of submesh objects
1505     #  @ingroup l2_construct
1506     def GetMeshOrder(self):
1507         return self.mesh.GetMeshOrder()
1508
1509     ## Return submesh objects list in meshing order
1510     #  @return list of list of submesh objects
1511     #  @ingroup l2_construct
1512     def SetMeshOrder(self, submeshes):
1513         return self.mesh.SetMeshOrder(submeshes)
1514
1515     ## Removes all nodes and elements
1516     #  @ingroup l2_construct
1517     def Clear(self):
1518         self.mesh.Clear()
1519         if salome.sg.hasDesktop():
1520             smeshgui = salome.ImportComponentGUI("SMESH")
1521             smeshgui.Init(self.mesh.GetStudyId())
1522             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1523             salome.sg.updateObjBrowser(1)
1524
1525     ## Removes all nodes and elements of indicated shape
1526     #  @ingroup l2_construct
1527     def ClearSubMesh(self, geomId):
1528         self.mesh.ClearSubMesh(geomId)
1529         if salome.sg.hasDesktop():
1530             smeshgui = salome.ImportComponentGUI("SMESH")
1531             smeshgui.Init(self.mesh.GetStudyId())
1532             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1533             salome.sg.updateObjBrowser(1)
1534
1535     ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1536     #  @param fineness [0,-1] defines mesh fineness
1537     #  @return True or False
1538     #  @ingroup l3_algos_basic
1539     def AutomaticTetrahedralization(self, fineness=0):
1540         dim = self.MeshDimension()
1541         # assign hypotheses
1542         self.RemoveGlobalHypotheses()
1543         self.Segment().AutomaticLength(fineness)
1544         if dim > 1 :
1545             self.Triangle().LengthFromEdges()
1546             pass
1547         if dim > 2 :
1548             self.Tetrahedron(NETGEN)
1549             pass
1550         return self.Compute()
1551
1552     ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1553     #  @param fineness [0,-1] defines mesh fineness
1554     #  @return True or False
1555     #  @ingroup l3_algos_basic
1556     def AutomaticHexahedralization(self, fineness=0):
1557         dim = self.MeshDimension()
1558         # assign the hypotheses
1559         self.RemoveGlobalHypotheses()
1560         self.Segment().AutomaticLength(fineness)
1561         if dim > 1 :
1562             self.Quadrangle()
1563             pass
1564         if dim > 2 :
1565             self.Hexahedron()
1566             pass
1567         return self.Compute()
1568
1569     ## Assigns a hypothesis
1570     #  @param hyp a hypothesis to assign
1571     #  @param geom a subhape of mesh geometry
1572     #  @return SMESH.Hypothesis_Status
1573     #  @ingroup l2_hypotheses
1574     def AddHypothesis(self, hyp, geom=0):
1575         if isinstance( hyp, Mesh_Algorithm ):
1576             hyp = hyp.GetAlgorithm()
1577             pass
1578         if not geom:
1579             geom = self.geom
1580             if not geom:
1581                 geom = self.mesh.GetShapeToMesh()
1582             pass
1583         status = self.mesh.AddHypothesis(geom, hyp)
1584         isAlgo = hyp._narrow( SMESH_Algo )
1585         hyp_name = GetName( hyp )
1586         geom_name = ""
1587         if geom:
1588             geom_name = GetName( geom )
1589         TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1590         return status
1591
1592     ## Unassigns a hypothesis
1593     #  @param hyp a hypothesis to unassign
1594     #  @param geom a subshape of mesh geometry
1595     #  @return SMESH.Hypothesis_Status
1596     #  @ingroup l2_hypotheses
1597     def RemoveHypothesis(self, hyp, geom=0):
1598         if isinstance( hyp, Mesh_Algorithm ):
1599             hyp = hyp.GetAlgorithm()
1600             pass
1601         if not geom:
1602             geom = self.geom
1603             pass
1604         status = self.mesh.RemoveHypothesis(geom, hyp)
1605         return status
1606
1607     ## Gets the list of hypotheses added on a geometry
1608     #  @param geom a subshape of mesh geometry
1609     #  @return the sequence of SMESH_Hypothesis
1610     #  @ingroup l2_hypotheses
1611     def GetHypothesisList(self, geom):
1612         return self.mesh.GetHypothesisList( geom )
1613
1614     ## Removes all global hypotheses
1615     #  @ingroup l2_hypotheses
1616     def RemoveGlobalHypotheses(self):
1617         current_hyps = self.mesh.GetHypothesisList( self.geom )
1618         for hyp in current_hyps:
1619             self.mesh.RemoveHypothesis( self.geom, hyp )
1620             pass
1621         pass
1622
1623     ## Creates a mesh group based on the geometric object \a grp
1624     #  and gives a \a name, \n if this parameter is not defined
1625     #  the name is the same as the geometric group name \n
1626     #  Note: Works like GroupOnGeom().
1627     #  @param grp  a geometric group, a vertex, an edge, a face or a solid
1628     #  @param name the name of the mesh group
1629     #  @return SMESH_GroupOnGeom
1630     #  @ingroup l2_grps_create
1631     def Group(self, grp, name=""):
1632         return self.GroupOnGeom(grp, name)
1633
1634     ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1635     #  Exports the mesh in a file in MED format and chooses the \a version of MED format
1636     ## allowing to overwrite the file if it exists or add the exported data to its contents
1637     #  @param f the file name
1638     #  @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1639     #  @param opt boolean parameter for creating/not creating
1640     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1641     #  @param overwrite boolean parameter for overwriting/not overwriting the file
1642     #  @ingroup l2_impexp
1643     def ExportToMED(self, f, version, opt=0, overwrite=1):
1644         self.mesh.ExportToMEDX(f, opt, version, overwrite)
1645
1646     ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1647     ## allowing to overwrite the file if it exists or add the exported data to its contents
1648     #  @param f is the file name
1649     #  @param auto_groups boolean parameter for creating/not creating
1650     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1651     #  the typical use is auto_groups=false.
1652     #  @param version MED format version(MED_V2_1 or MED_V2_2)
1653     #  @param overwrite boolean parameter for overwriting/not overwriting the file
1654     #  @ingroup l2_impexp
1655     def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1):
1656         self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1657
1658     ## Exports the mesh in a file in DAT format
1659     #  @param f the file name
1660     #  @ingroup l2_impexp
1661     def ExportDAT(self, f):
1662         self.mesh.ExportDAT(f)
1663
1664     ## Exports the mesh in a file in UNV format
1665     #  @param f the file name
1666     #  @ingroup l2_impexp
1667     def ExportUNV(self, f):
1668         self.mesh.ExportUNV(f)
1669
1670     ## Export the mesh in a file in STL format
1671     #  @param f the file name
1672     #  @param ascii defines the file encoding
1673     #  @ingroup l2_impexp
1674     def ExportSTL(self, f, ascii=1):
1675         self.mesh.ExportSTL(f, ascii)
1676
1677
1678     # Operations with groups:
1679     # ----------------------
1680
1681     ## Creates an empty mesh group
1682     #  @param elementType the type of elements in the group
1683     #  @param name the name of the mesh group
1684     #  @return SMESH_Group
1685     #  @ingroup l2_grps_create
1686     def CreateEmptyGroup(self, elementType, name):
1687         return self.mesh.CreateGroup(elementType, name)
1688
1689     ## Creates a mesh group based on the geometrical object \a grp
1690     #  and gives a \a name, \n if this parameter is not defined
1691     #  the name is the same as the geometrical group name
1692     #  @param grp  a geometrical group, a vertex, an edge, a face or a solid
1693     #  @param name the name of the mesh group
1694     #  @param typ  the type of elements in the group. If not set, it is
1695     #              automatically detected by the type of the geometry
1696     #  @return SMESH_GroupOnGeom
1697     #  @ingroup l2_grps_create
1698     def GroupOnGeom(self, grp, name="", typ=None):
1699         if name == "":
1700             name = grp.GetName()
1701
1702         if typ == None:
1703             tgeo = str(grp.GetShapeType())
1704             if tgeo == "VERTEX":
1705                 typ = NODE
1706             elif tgeo == "EDGE":
1707                 typ = EDGE
1708             elif tgeo == "FACE":
1709                 typ = FACE
1710             elif tgeo == "SOLID":
1711                 typ = VOLUME
1712             elif tgeo == "SHELL":
1713                 typ = VOLUME
1714             elif tgeo == "COMPOUND":
1715                 try: # it raises on a compound of compounds
1716                     if len( self.geompyD.GetObjectIDs( grp )) == 0:
1717                         print "Mesh.Group: empty geometric group", GetName( grp )
1718                         return 0
1719                     pass
1720                 except:
1721                     pass
1722                 if grp.GetType() == 37: # GEOMImpl_Types.hxx: #define GEOM_GROUP 37
1723                     # group
1724                     tgeo = self.geompyD.GetType(grp)
1725                     if tgeo == geompyDC.ShapeType["VERTEX"]:
1726                         typ = NODE
1727                     elif tgeo == geompyDC.ShapeType["EDGE"]:
1728                         typ = EDGE
1729                     elif tgeo == geompyDC.ShapeType["FACE"]:
1730                         typ = FACE
1731                     elif tgeo == geompyDC.ShapeType["SOLID"]:
1732                         typ = VOLUME
1733                         pass
1734                     pass
1735                 else:
1736                     # just a compound
1737                     for elemType, shapeType in [[VOLUME,"SOLID"],[FACE,"FACE"],
1738                                                 [EDGE,"EDGE"],[NODE,"VERTEX"]]:
1739                         if self.geompyD.SubShapeAll(grp,geompyDC.ShapeType[shapeType]):
1740                             typ = elemType
1741                             break
1742                         pass
1743                     pass
1744                 pass
1745             pass
1746         if typ == None:
1747             print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1748             return 0
1749         else:
1750             return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1751
1752     ## Creates a mesh group by the given ids of elements
1753     #  @param groupName the name of the mesh group
1754     #  @param elementType the type of elements in the group
1755     #  @param elemIDs the list of ids
1756     #  @return SMESH_Group
1757     #  @ingroup l2_grps_create
1758     def MakeGroupByIds(self, groupName, elementType, elemIDs):
1759         group = self.mesh.CreateGroup(elementType, groupName)
1760         group.Add(elemIDs)
1761         return group
1762
1763     ## Creates a mesh group by the given conditions
1764     #  @param groupName the name of the mesh group
1765     #  @param elementType the type of elements in the group
1766     #  @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1767     #  @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1768     #  @param Treshold the threshold value (range of id ids as string, shape, numeric)
1769     #  @param UnaryOp FT_LogicalNOT or FT_Undefined
1770     #  @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1771     #         FT_LyingOnGeom, FT_CoplanarFaces criteria
1772     #  @return SMESH_Group
1773     #  @ingroup l2_grps_create
1774     def MakeGroup(self,
1775                   groupName,
1776                   elementType,
1777                   CritType=FT_Undefined,
1778                   Compare=FT_EqualTo,
1779                   Treshold="",
1780                   UnaryOp=FT_Undefined,
1781                   Tolerance=1e-07):
1782         aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined,Tolerance)
1783         group = self.MakeGroupByCriterion(groupName, aCriterion)
1784         return group
1785
1786     ## Creates a mesh group by the given criterion
1787     #  @param groupName the name of the mesh group
1788     #  @param Criterion the instance of Criterion class
1789     #  @return SMESH_Group
1790     #  @ingroup l2_grps_create
1791     def MakeGroupByCriterion(self, groupName, Criterion):
1792         aFilterMgr = self.smeshpyD.CreateFilterManager()
1793         aFilter = aFilterMgr.CreateFilter()
1794         aCriteria = []
1795         aCriteria.append(Criterion)
1796         aFilter.SetCriteria(aCriteria)
1797         group = self.MakeGroupByFilter(groupName, aFilter)
1798         aFilterMgr.Destroy()
1799         return group
1800
1801     ## Creates a mesh group by the given criteria (list of criteria)
1802     #  @param groupName the name of the mesh group
1803     #  @param theCriteria the list of criteria
1804     #  @return SMESH_Group
1805     #  @ingroup l2_grps_create
1806     def MakeGroupByCriteria(self, groupName, theCriteria):
1807         aFilterMgr = self.smeshpyD.CreateFilterManager()
1808         aFilter = aFilterMgr.CreateFilter()
1809         aFilter.SetCriteria(theCriteria)
1810         group = self.MakeGroupByFilter(groupName, aFilter)
1811         aFilterMgr.Destroy()
1812         return group
1813
1814     ## Creates a mesh group by the given filter
1815     #  @param groupName the name of the mesh group
1816     #  @param theFilter the instance of Filter class
1817     #  @return SMESH_Group
1818     #  @ingroup l2_grps_create
1819     def MakeGroupByFilter(self, groupName, theFilter):
1820         group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1821         theFilter.SetMesh( self.mesh )
1822         group.AddFrom( theFilter )
1823         return group
1824
1825     ## Passes mesh elements through the given filter and return IDs of fitting elements
1826     #  @param theFilter SMESH_Filter
1827     #  @return a list of ids
1828     #  @ingroup l1_controls
1829     def GetIdsFromFilter(self, theFilter):
1830         theFilter.SetMesh( self.mesh )
1831         return theFilter.GetIDs()
1832
1833     ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
1834     #  Returns a list of special structures (borders).
1835     #  @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
1836     #  @ingroup l1_controls
1837     def GetFreeBorders(self):
1838         aFilterMgr = self.smeshpyD.CreateFilterManager()
1839         aPredicate = aFilterMgr.CreateFreeEdges()
1840         aPredicate.SetMesh(self.mesh)
1841         aBorders = aPredicate.GetBorders()
1842         aFilterMgr.Destroy()
1843         return aBorders
1844
1845     ## Removes a group
1846     #  @ingroup l2_grps_delete
1847     def RemoveGroup(self, group):
1848         self.mesh.RemoveGroup(group)
1849
1850     ## Removes a group with its contents
1851     #  @ingroup l2_grps_delete
1852     def RemoveGroupWithContents(self, group):
1853         self.mesh.RemoveGroupWithContents(group)
1854
1855     ## Gets the list of groups existing in the mesh
1856     #  @return a sequence of SMESH_GroupBase
1857     #  @ingroup l2_grps_create
1858     def GetGroups(self):
1859         return self.mesh.GetGroups()
1860
1861     ## Gets the number of groups existing in the mesh
1862     #  @return the quantity of groups as an integer value
1863     #  @ingroup l2_grps_create
1864     def NbGroups(self):
1865         return self.mesh.NbGroups()
1866
1867     ## Gets the list of names of groups existing in the mesh
1868     #  @return list of strings
1869     #  @ingroup l2_grps_create
1870     def GetGroupNames(self):
1871         groups = self.GetGroups()
1872         names = []
1873         for group in groups:
1874             names.append(group.GetName())
1875         return names
1876
1877     ## Produces a union of two groups
1878     #  A new group is created. All mesh elements that are
1879     #  present in the initial groups are added to the new one
1880     #  @return an instance of SMESH_Group
1881     #  @ingroup l2_grps_operon
1882     def UnionGroups(self, group1, group2, name):
1883         return self.mesh.UnionGroups(group1, group2, name)
1884         
1885     ## Produces a union list of groups
1886     #  New group is created. All mesh elements that are present in 
1887     #  initial groups are added to the new one
1888     #  @return an instance of SMESH_Group
1889     #  @ingroup l2_grps_operon
1890     def UnionListOfGroups(self, groups, name):
1891       return self.mesh.UnionListOfGroups(groups, name)
1892       
1893     ## Prodices an intersection of two groups
1894     #  A new group is created. All mesh elements that are common
1895     #  for the two initial groups are added to the new one.
1896     #  @return an instance of SMESH_Group
1897     #  @ingroup l2_grps_operon
1898     def IntersectGroups(self, group1, group2, name):
1899         return self.mesh.IntersectGroups(group1, group2, name)
1900         
1901     ## Produces an intersection of groups
1902     #  New group is created. All mesh elements that are present in all 
1903     #  initial groups simultaneously are added to the new one
1904     #  @return an instance of SMESH_Group
1905     #  @ingroup l2_grps_operon
1906     def IntersectListOfGroups(self, groups, name):
1907       return self.mesh.IntersectListOfGroups(groups, name)
1908
1909     ## Produces a cut of two groups
1910     #  A new group is created. All mesh elements that are present in
1911     #  the main group but are not present in the tool group are added to the new one
1912     #  @return an instance of SMESH_Group
1913     #  @ingroup l2_grps_operon
1914     def CutGroups(self, main_group, tool_group, name):
1915         return self.mesh.CutGroups(main_group, tool_group, name)
1916         
1917     ## Produces a cut of groups
1918     #  A new group is created. All mesh elements that are present in main groups 
1919     #  but do not present in tool groups are added to the new one
1920     #  @return an instance of SMESH_Group
1921     #  @ingroup l2_grps_operon
1922     def CutListOfGroups(self, main_groups, tool_groups, name):
1923       return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1924       
1925     ## Produces a group of elements with specified element type using list of existing groups
1926     #  A new group is created. System 
1927     #  1) extract all nodes on which groups elements are built
1928     #  2) combine all elements of specified dimension laying on these nodes
1929     #  @return an instance of SMESH_Group
1930     #  @ingroup l2_grps_operon
1931     def CreateDimGroup(self, groups, elem_type, name):
1932       return self.mesh.CreateDimGroup(groups, elem_type, name)
1933
1934
1935     ## Convert group on geom into standalone group
1936     #  @ingroup l2_grps_delete
1937     def ConvertToStandalone(self, group):
1938         return self.mesh.ConvertToStandalone(group)
1939
1940     # Get some info about mesh:
1941     # ------------------------
1942
1943     ## Returns the log of nodes and elements added or removed
1944     #  since the previous clear of the log.
1945     #  @param clearAfterGet log is emptied after Get (safe if concurrents access)
1946     #  @return list of log_block structures:
1947     #                                        commandType
1948     #                                        number
1949     #                                        coords
1950     #                                        indexes
1951     #  @ingroup l1_auxiliary
1952     def GetLog(self, clearAfterGet):
1953         return self.mesh.GetLog(clearAfterGet)
1954
1955     ## Clears the log of nodes and elements added or removed since the previous
1956     #  clear. Must be used immediately after GetLog if clearAfterGet is false.
1957     #  @ingroup l1_auxiliary
1958     def ClearLog(self):
1959         self.mesh.ClearLog()
1960
1961     ## Toggles auto color mode on the object.
1962     #  @param theAutoColor the flag which toggles auto color mode.
1963     #  @ingroup l1_auxiliary
1964     def SetAutoColor(self, theAutoColor):
1965         self.mesh.SetAutoColor(theAutoColor)
1966
1967     ## Gets flag of object auto color mode.
1968     #  @return True or False
1969     #  @ingroup l1_auxiliary
1970     def GetAutoColor(self):
1971         return self.mesh.GetAutoColor()
1972
1973     ## Gets the internal ID
1974     #  @return integer value, which is the internal Id of the mesh
1975     #  @ingroup l1_auxiliary
1976     def GetId(self):
1977         return self.mesh.GetId()
1978
1979     ## Get the study Id
1980     #  @return integer value, which is the study Id of the mesh
1981     #  @ingroup l1_auxiliary
1982     def GetStudyId(self):
1983         return self.mesh.GetStudyId()
1984
1985     ## Checks the group names for duplications.
1986     #  Consider the maximum group name length stored in MED file.
1987     #  @return True or False
1988     #  @ingroup l1_auxiliary
1989     def HasDuplicatedGroupNamesMED(self):
1990         return self.mesh.HasDuplicatedGroupNamesMED()
1991
1992     ## Obtains the mesh editor tool
1993     #  @return an instance of SMESH_MeshEditor
1994     #  @ingroup l1_modifying
1995     def GetMeshEditor(self):
1996         return self.mesh.GetMeshEditor()
1997
1998     ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1999     #  can be passed as argument to accepting mesh, group or sub-mesh
2000     #  @return an instance of SMESH_IDSource
2001     #  @ingroup l1_auxiliary
2002     def GetIDSource(self, ids, elemType):
2003         return self.GetMeshEditor().MakeIDSource(ids, elemType)
2004
2005     ## Gets MED Mesh
2006     #  @return an instance of SALOME_MED::MESH
2007     #  @ingroup l1_auxiliary
2008     def GetMEDMesh(self):
2009         return self.mesh.GetMEDMesh()
2010
2011
2012     # Get informations about mesh contents:
2013     # ------------------------------------
2014
2015     ## Gets the mesh stattistic
2016     #  @return dictionary type element - count of elements
2017     #  @ingroup l1_meshinfo
2018     def GetMeshInfo(self, obj = None):
2019         if not obj: obj = self.mesh
2020         return self.smeshpyD.GetMeshInfo(obj)
2021
2022     ## Returns the number of nodes in the mesh
2023     #  @return an integer value
2024     #  @ingroup l1_meshinfo
2025     def NbNodes(self):
2026         return self.mesh.NbNodes()
2027
2028     ## Returns the number of elements in the mesh
2029     #  @return an integer value
2030     #  @ingroup l1_meshinfo
2031     def NbElements(self):
2032         return self.mesh.NbElements()
2033
2034     ## Returns the number of 0d elements in the mesh
2035     #  @return an integer value
2036     #  @ingroup l1_meshinfo
2037     def Nb0DElements(self):
2038         return self.mesh.Nb0DElements()
2039
2040     ## Returns the number of edges in the mesh
2041     #  @return an integer value
2042     #  @ingroup l1_meshinfo
2043     def NbEdges(self):
2044         return self.mesh.NbEdges()
2045
2046     ## Returns the number of edges with the given order in the mesh
2047     #  @param elementOrder the order of elements:
2048     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2049     #  @return an integer value
2050     #  @ingroup l1_meshinfo
2051     def NbEdgesOfOrder(self, elementOrder):
2052         return self.mesh.NbEdgesOfOrder(elementOrder)
2053
2054     ## Returns the number of faces in the mesh
2055     #  @return an integer value
2056     #  @ingroup l1_meshinfo
2057     def NbFaces(self):
2058         return self.mesh.NbFaces()
2059
2060     ## Returns the number of faces with the given order in the mesh
2061     #  @param elementOrder the order of elements:
2062     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2063     #  @return an integer value
2064     #  @ingroup l1_meshinfo
2065     def NbFacesOfOrder(self, elementOrder):
2066         return self.mesh.NbFacesOfOrder(elementOrder)
2067
2068     ## Returns the number of triangles in the mesh
2069     #  @return an integer value
2070     #  @ingroup l1_meshinfo
2071     def NbTriangles(self):
2072         return self.mesh.NbTriangles()
2073
2074     ## Returns the number of triangles with the given order in the mesh
2075     #  @param elementOrder is the order of elements:
2076     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2077     #  @return an integer value
2078     #  @ingroup l1_meshinfo
2079     def NbTrianglesOfOrder(self, elementOrder):
2080         return self.mesh.NbTrianglesOfOrder(elementOrder)
2081
2082     ## Returns the number of quadrangles in the mesh
2083     #  @return an integer value
2084     #  @ingroup l1_meshinfo
2085     def NbQuadrangles(self):
2086         return self.mesh.NbQuadrangles()
2087
2088     ## Returns the number of quadrangles with the given order in the mesh
2089     #  @param elementOrder the order of elements:
2090     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2091     #  @return an integer value
2092     #  @ingroup l1_meshinfo
2093     def NbQuadranglesOfOrder(self, elementOrder):
2094         return self.mesh.NbQuadranglesOfOrder(elementOrder)
2095
2096     ## Returns the number of polygons in the mesh
2097     #  @return an integer value
2098     #  @ingroup l1_meshinfo
2099     def NbPolygons(self):
2100         return self.mesh.NbPolygons()
2101
2102     ## Returns the number of volumes in the mesh
2103     #  @return an integer value
2104     #  @ingroup l1_meshinfo
2105     def NbVolumes(self):
2106         return self.mesh.NbVolumes()
2107
2108     ## Returns the number of volumes with the given order in the mesh
2109     #  @param elementOrder  the order of elements:
2110     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2111     #  @return an integer value
2112     #  @ingroup l1_meshinfo
2113     def NbVolumesOfOrder(self, elementOrder):
2114         return self.mesh.NbVolumesOfOrder(elementOrder)
2115
2116     ## Returns the number of tetrahedrons in the mesh
2117     #  @return an integer value
2118     #  @ingroup l1_meshinfo
2119     def NbTetras(self):
2120         return self.mesh.NbTetras()
2121
2122     ## Returns the number of tetrahedrons with the given order in the mesh
2123     #  @param elementOrder  the order of elements:
2124     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2125     #  @return an integer value
2126     #  @ingroup l1_meshinfo
2127     def NbTetrasOfOrder(self, elementOrder):
2128         return self.mesh.NbTetrasOfOrder(elementOrder)
2129
2130     ## Returns the number of hexahedrons in the mesh
2131     #  @return an integer value
2132     #  @ingroup l1_meshinfo
2133     def NbHexas(self):
2134         return self.mesh.NbHexas()
2135
2136     ## Returns the number of hexahedrons with the given order in the mesh
2137     #  @param elementOrder  the order of elements:
2138     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2139     #  @return an integer value
2140     #  @ingroup l1_meshinfo
2141     def NbHexasOfOrder(self, elementOrder):
2142         return self.mesh.NbHexasOfOrder(elementOrder)
2143
2144     ## Returns the number of pyramids in the mesh
2145     #  @return an integer value
2146     #  @ingroup l1_meshinfo
2147     def NbPyramids(self):
2148         return self.mesh.NbPyramids()
2149
2150     ## Returns the number of pyramids with the given order in the mesh
2151     #  @param elementOrder  the order of elements:
2152     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2153     #  @return an integer value
2154     #  @ingroup l1_meshinfo
2155     def NbPyramidsOfOrder(self, elementOrder):
2156         return self.mesh.NbPyramidsOfOrder(elementOrder)
2157
2158     ## Returns the number of prisms in the mesh
2159     #  @return an integer value
2160     #  @ingroup l1_meshinfo
2161     def NbPrisms(self):
2162         return self.mesh.NbPrisms()
2163
2164     ## Returns the number of prisms with the given order in the mesh
2165     #  @param elementOrder  the order of elements:
2166     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2167     #  @return an integer value
2168     #  @ingroup l1_meshinfo
2169     def NbPrismsOfOrder(self, elementOrder):
2170         return self.mesh.NbPrismsOfOrder(elementOrder)
2171
2172     ## Returns the number of polyhedrons in the mesh
2173     #  @return an integer value
2174     #  @ingroup l1_meshinfo
2175     def NbPolyhedrons(self):
2176         return self.mesh.NbPolyhedrons()
2177
2178     ## Returns the number of submeshes in the mesh
2179     #  @return an integer value
2180     #  @ingroup l1_meshinfo
2181     def NbSubMesh(self):
2182         return self.mesh.NbSubMesh()
2183
2184     ## Returns the list of mesh elements IDs
2185     #  @return the list of integer values
2186     #  @ingroup l1_meshinfo
2187     def GetElementsId(self):
2188         return self.mesh.GetElementsId()
2189
2190     ## Returns the list of IDs of mesh elements with the given type
2191     #  @param elementType  the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2192     #  @return list of integer values
2193     #  @ingroup l1_meshinfo
2194     def GetElementsByType(self, elementType):
2195         return self.mesh.GetElementsByType(elementType)
2196
2197     ## Returns the list of mesh nodes IDs
2198     #  @return the list of integer values
2199     #  @ingroup l1_meshinfo
2200     def GetNodesId(self):
2201         return self.mesh.GetNodesId()
2202
2203     # Get the information about mesh elements:
2204     # ------------------------------------
2205
2206     ## Returns the type of mesh element
2207     #  @return the value from SMESH::ElementType enumeration
2208     #  @ingroup l1_meshinfo
2209     def GetElementType(self, id, iselem):
2210         return self.mesh.GetElementType(id, iselem)
2211
2212     ## Returns the geometric type of mesh element
2213     #  @return the value from SMESH::EntityType enumeration
2214     #  @ingroup l1_meshinfo
2215     def GetElementGeomType(self, id):
2216         return self.mesh.GetElementGeomType(id)
2217
2218     ## Returns the list of submesh elements IDs
2219     #  @param Shape a geom object(subshape) IOR
2220     #         Shape must be the subshape of a ShapeToMesh()
2221     #  @return the list of integer values
2222     #  @ingroup l1_meshinfo
2223     def GetSubMeshElementsId(self, Shape):
2224         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2225             ShapeID = Shape.GetSubShapeIndices()[0]
2226         else:
2227             ShapeID = Shape
2228         return self.mesh.GetSubMeshElementsId(ShapeID)
2229
2230     ## Returns the list of submesh nodes IDs
2231     #  @param Shape a geom object(subshape) IOR
2232     #         Shape must be the subshape of a ShapeToMesh()
2233     #  @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2234     #  @return the list of integer values
2235     #  @ingroup l1_meshinfo
2236     def GetSubMeshNodesId(self, Shape, all):
2237         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2238             ShapeID = Shape.GetSubShapeIndices()[0]
2239         else:
2240             ShapeID = Shape
2241         return self.mesh.GetSubMeshNodesId(ShapeID, all)
2242
2243     ## Returns type of elements on given shape
2244     #  @param Shape a geom object(subshape) IOR
2245     #         Shape must be a subshape of a ShapeToMesh()
2246     #  @return element type
2247     #  @ingroup l1_meshinfo
2248     def GetSubMeshElementType(self, Shape):
2249         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2250             ShapeID = Shape.GetSubShapeIndices()[0]
2251         else:
2252             ShapeID = Shape
2253         return self.mesh.GetSubMeshElementType(ShapeID)
2254
2255     ## Gets the mesh description
2256     #  @return string value
2257     #  @ingroup l1_meshinfo
2258     def Dump(self):
2259         return self.mesh.Dump()
2260
2261
2262     # Get the information about nodes and elements of a mesh by its IDs:
2263     # -----------------------------------------------------------
2264
2265     ## Gets XYZ coordinates of a node
2266     #  \n If there is no nodes for the given ID - returns an empty list
2267     #  @return a list of double precision values
2268     #  @ingroup l1_meshinfo
2269     def GetNodeXYZ(self, id):
2270         return self.mesh.GetNodeXYZ(id)
2271
2272     ## Returns list of IDs of inverse elements for the given node
2273     #  \n If there is no node for the given ID - returns an empty list
2274     #  @return a list of integer values
2275     #  @ingroup l1_meshinfo
2276     def GetNodeInverseElements(self, id):
2277         return self.mesh.GetNodeInverseElements(id)
2278
2279     ## @brief Returns the position of a node on the shape
2280     #  @return SMESH::NodePosition
2281     #  @ingroup l1_meshinfo
2282     def GetNodePosition(self,NodeID):
2283         return self.mesh.GetNodePosition(NodeID)
2284
2285     ## If the given element is a node, returns the ID of shape
2286     #  \n If there is no node for the given ID - returns -1
2287     #  @return an integer value
2288     #  @ingroup l1_meshinfo
2289     def GetShapeID(self, id):
2290         return self.mesh.GetShapeID(id)
2291
2292     ## Returns the ID of the result shape after
2293     #  FindShape() from SMESH_MeshEditor for the given element
2294     #  \n If there is no element for the given ID - returns -1
2295     #  @return an integer value
2296     #  @ingroup l1_meshinfo
2297     def GetShapeIDForElem(self,id):
2298         return self.mesh.GetShapeIDForElem(id)
2299
2300     ## Returns the number of nodes for the given element
2301     #  \n If there is no element for the given ID - returns -1
2302     #  @return an integer value
2303     #  @ingroup l1_meshinfo
2304     def GetElemNbNodes(self, id):
2305         return self.mesh.GetElemNbNodes(id)
2306
2307     ## Returns the node ID the given index for the given element
2308     #  \n If there is no element for the given ID - returns -1
2309     #  \n If there is no node for the given index - returns -2
2310     #  @return an integer value
2311     #  @ingroup l1_meshinfo
2312     def GetElemNode(self, id, index):
2313         return self.mesh.GetElemNode(id, index)
2314
2315     ## Returns the IDs of nodes of the given element
2316     #  @return a list of integer values
2317     #  @ingroup l1_meshinfo
2318     def GetElemNodes(self, id):
2319         return self.mesh.GetElemNodes(id)
2320
2321     ## Returns true if the given node is the medium node in the given quadratic element
2322     #  @ingroup l1_meshinfo
2323     def IsMediumNode(self, elementID, nodeID):
2324         return self.mesh.IsMediumNode(elementID, nodeID)
2325
2326     ## Returns true if the given node is the medium node in one of quadratic elements
2327     #  @ingroup l1_meshinfo
2328     def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2329         return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2330
2331     ## Returns the number of edges for the given element
2332     #  @ingroup l1_meshinfo
2333     def ElemNbEdges(self, id):
2334         return self.mesh.ElemNbEdges(id)
2335
2336     ## Returns the number of faces for the given element
2337     #  @ingroup l1_meshinfo
2338     def ElemNbFaces(self, id):
2339         return self.mesh.ElemNbFaces(id)
2340
2341     ## Returns nodes of given face (counted from zero) for given volumic element.
2342     #  @ingroup l1_meshinfo
2343     def GetElemFaceNodes(self,elemId, faceIndex):
2344         return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2345
2346     ## Returns an element based on all given nodes.
2347     #  @ingroup l1_meshinfo
2348     def FindElementByNodes(self,nodes):
2349         return self.mesh.FindElementByNodes(nodes)
2350
2351     ## Returns true if the given element is a polygon
2352     #  @ingroup l1_meshinfo
2353     def IsPoly(self, id):
2354         return self.mesh.IsPoly(id)
2355
2356     ## Returns true if the given element is quadratic
2357     #  @ingroup l1_meshinfo
2358     def IsQuadratic(self, id):
2359         return self.mesh.IsQuadratic(id)
2360
2361     ## Returns XYZ coordinates of the barycenter of the given element
2362     #  \n If there is no element for the given ID - returns an empty list
2363     #  @return a list of three double values
2364     #  @ingroup l1_meshinfo
2365     def BaryCenter(self, id):
2366         return self.mesh.BaryCenter(id)
2367
2368
2369     # Get mesh measurements information:
2370     # ------------------------------------
2371
2372     ## Get minimum distance between two nodes, elements or distance to the origin
2373     #  @param id1 first node/element id
2374     #  @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2375     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2376     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2377     #  @return minimum distance value
2378     #  @sa GetMinDistance()
2379     def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2380         aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2381         return aMeasure.value
2382     
2383     ## Get measure structure specifying minimum distance data between two objects
2384     #  @param id1 first node/element id
2385     #  @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2386     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2387     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2388     #  @return Measure structure
2389     #  @sa MinDistance()
2390     def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2391         if isElem1:
2392             id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2393         else:
2394             id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2395         if id2 != 0:
2396             if isElem2:
2397                 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2398             else:
2399                 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2400             pass
2401         else:
2402             id2 = None
2403         
2404         aMeasurements = self.smeshpyD.CreateMeasurements()
2405         aMeasure = aMeasurements.MinDistance(id1, id2)
2406         aMeasurements.Destroy()
2407         return aMeasure
2408     
2409     ## Get bounding box of the specified object(s)
2410     #  @param objects single source object or list of source objects or list of nodes/elements IDs
2411     #  @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2412     #  @c False specifies that @a objects are nodes
2413     #  @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2414     #  @sa GetBoundingBox()
2415     def BoundingBox(self, objects=None, isElem=False):
2416         result = self.GetBoundingBox(objects, isElem)
2417         if result is None:
2418             result = (0.0,)*6
2419         else:
2420             result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2421         return result
2422
2423     ## Get measure structure specifying bounding box data of the specified object(s)
2424     #  @param objects single source object or list of source objects or list of nodes/elements IDs
2425     #  @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2426     #  @c False specifies that @a objects are nodes
2427     #  @return Measure structure
2428     #  @sa BoundingBox()
2429     def GetBoundingBox(self, IDs=None, isElem=False):
2430         if IDs is None:
2431             IDs = [self.mesh]
2432         elif isinstance(IDs, tuple):
2433             IDs = list(IDs)
2434         if not isinstance(IDs, list):
2435             IDs = [IDs]
2436         if len(IDs) > 0 and isinstance(IDs[0], int):
2437             IDs = [IDs]
2438         srclist = []
2439         for o in IDs:
2440             if isinstance(o, Mesh):
2441                 srclist.append(o.mesh)
2442             elif hasattr(o, "_narrow"):
2443                 src = o._narrow(SMESH.SMESH_IDSource)
2444                 if src: srclist.append(src)
2445                 pass
2446             elif isinstance(o, list):
2447                 if isElem:
2448                     srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2449                 else:
2450                     srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2451                 pass
2452             pass
2453         aMeasurements = self.smeshpyD.CreateMeasurements()
2454         aMeasure = aMeasurements.BoundingBox(srclist)
2455         aMeasurements.Destroy()
2456         return aMeasure
2457     
2458     # Mesh edition (SMESH_MeshEditor functionality):
2459     # ---------------------------------------------
2460
2461     ## Removes the elements from the mesh by ids
2462     #  @param IDsOfElements is a list of ids of elements to remove
2463     #  @return True or False
2464     #  @ingroup l2_modif_del
2465     def RemoveElements(self, IDsOfElements):
2466         return self.editor.RemoveElements(IDsOfElements)
2467
2468     ## Removes nodes from mesh by ids
2469     #  @param IDsOfNodes is a list of ids of nodes to remove
2470     #  @return True or False
2471     #  @ingroup l2_modif_del
2472     def RemoveNodes(self, IDsOfNodes):
2473         return self.editor.RemoveNodes(IDsOfNodes)
2474
2475     ## Removes all orphan (free) nodes from mesh
2476     #  @return number of the removed nodes
2477     #  @ingroup l2_modif_del
2478     def RemoveOrphanNodes(self):
2479         return self.editor.RemoveOrphanNodes()
2480
2481     ## Add a node to the mesh by coordinates
2482     #  @return Id of the new node
2483     #  @ingroup l2_modif_add
2484     def AddNode(self, x, y, z):
2485         x,y,z,Parameters = geompyDC.ParseParameters(x,y,z)
2486         self.mesh.SetParameters(Parameters)
2487         return self.editor.AddNode( x, y, z)
2488
2489     ## Creates a 0D element on a node with given number.
2490     #  @param IDOfNode the ID of node for creation of the element.
2491     #  @return the Id of the new 0D element
2492     #  @ingroup l2_modif_add
2493     def Add0DElement(self, IDOfNode):
2494         return self.editor.Add0DElement(IDOfNode)
2495
2496     ## Creates a linear or quadratic edge (this is determined
2497     #  by the number of given nodes).
2498     #  @param IDsOfNodes the list of node IDs for creation of the element.
2499     #  The order of nodes in this list should correspond to the description
2500     #  of MED. \n This description is located by the following link:
2501     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2502     #  @return the Id of the new edge
2503     #  @ingroup l2_modif_add
2504     def AddEdge(self, IDsOfNodes):
2505         return self.editor.AddEdge(IDsOfNodes)
2506
2507     ## Creates a linear or quadratic face (this is determined
2508     #  by the number of given nodes).
2509     #  @param IDsOfNodes the list of node IDs for creation of the element.
2510     #  The order of nodes in this list should correspond to the description
2511     #  of MED. \n This description is located by the following link:
2512     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2513     #  @return the Id of the new face
2514     #  @ingroup l2_modif_add
2515     def AddFace(self, IDsOfNodes):
2516         return self.editor.AddFace(IDsOfNodes)
2517
2518     ## Adds a polygonal face to the mesh by the list of node IDs
2519     #  @param IdsOfNodes the list of node IDs for creation of the element.
2520     #  @return the Id of the new face
2521     #  @ingroup l2_modif_add
2522     def AddPolygonalFace(self, IdsOfNodes):
2523         return self.editor.AddPolygonalFace(IdsOfNodes)
2524
2525     ## Creates both simple and quadratic volume (this is determined
2526     #  by the number of given nodes).
2527     #  @param IDsOfNodes the list of node IDs for creation of the element.
2528     #  The order of nodes in this list should correspond to the description
2529     #  of MED. \n This description is located by the following link:
2530     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2531     #  @return the Id of the new volumic element
2532     #  @ingroup l2_modif_add
2533     def AddVolume(self, IDsOfNodes):
2534         return self.editor.AddVolume(IDsOfNodes)
2535
2536     ## Creates a volume of many faces, giving nodes for each face.
2537     #  @param IdsOfNodes the list of node IDs for volume creation face by face.
2538     #  @param Quantities the list of integer values, Quantities[i]
2539     #         gives the quantity of nodes in face number i.
2540     #  @return the Id of the new volumic element
2541     #  @ingroup l2_modif_add
2542     def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2543         return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2544
2545     ## Creates a volume of many faces, giving the IDs of the existing faces.
2546     #  @param IdsOfFaces the list of face IDs for volume creation.
2547     #
2548     #  Note:  The created volume will refer only to the nodes
2549     #         of the given faces, not to the faces themselves.
2550     #  @return the Id of the new volumic element
2551     #  @ingroup l2_modif_add
2552     def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2553         return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2554
2555
2556     ## @brief Binds a node to a vertex
2557     #  @param NodeID a node ID
2558     #  @param Vertex a vertex or vertex ID
2559     #  @return True if succeed else raises an exception
2560     #  @ingroup l2_modif_add
2561     def SetNodeOnVertex(self, NodeID, Vertex):
2562         if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2563             VertexID = Vertex.GetSubShapeIndices()[0]
2564         else:
2565             VertexID = Vertex
2566         try:
2567             self.editor.SetNodeOnVertex(NodeID, VertexID)
2568         except SALOME.SALOME_Exception, inst:
2569             raise ValueError, inst.details.text
2570         return True
2571
2572
2573     ## @brief Stores the node position on an edge
2574     #  @param NodeID a node ID
2575     #  @param Edge an edge or edge ID
2576     #  @param paramOnEdge a parameter on the edge where the node is located
2577     #  @return True if succeed else raises an exception
2578     #  @ingroup l2_modif_add
2579     def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2580         if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2581             EdgeID = Edge.GetSubShapeIndices()[0]
2582         else:
2583             EdgeID = Edge
2584         try:
2585             self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2586         except SALOME.SALOME_Exception, inst:
2587             raise ValueError, inst.details.text
2588         return True
2589
2590     ## @brief Stores node position on a face
2591     #  @param NodeID a node ID
2592     #  @param Face a face or face ID
2593     #  @param u U parameter on the face where the node is located
2594     #  @param v V parameter on the face where the node is located
2595     #  @return True if succeed else raises an exception
2596     #  @ingroup l2_modif_add
2597     def SetNodeOnFace(self, NodeID, Face, u, v):
2598         if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2599             FaceID = Face.GetSubShapeIndices()[0]
2600         else:
2601             FaceID = Face
2602         try:
2603             self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2604         except SALOME.SALOME_Exception, inst:
2605             raise ValueError, inst.details.text
2606         return True
2607
2608     ## @brief Binds a node to a solid
2609     #  @param NodeID a node ID
2610     #  @param Solid  a solid or solid ID
2611     #  @return True if succeed else raises an exception
2612     #  @ingroup l2_modif_add
2613     def SetNodeInVolume(self, NodeID, Solid):
2614         if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2615             SolidID = Solid.GetSubShapeIndices()[0]
2616         else:
2617             SolidID = Solid
2618         try:
2619             self.editor.SetNodeInVolume(NodeID, SolidID)
2620         except SALOME.SALOME_Exception, inst:
2621             raise ValueError, inst.details.text
2622         return True
2623
2624     ## @brief Bind an element to a shape
2625     #  @param ElementID an element ID
2626     #  @param Shape a shape or shape ID
2627     #  @return True if succeed else raises an exception
2628     #  @ingroup l2_modif_add
2629     def SetMeshElementOnShape(self, ElementID, Shape):
2630         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2631             ShapeID = Shape.GetSubShapeIndices()[0]
2632         else:
2633             ShapeID = Shape
2634         try:
2635             self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2636         except SALOME.SALOME_Exception, inst:
2637             raise ValueError, inst.details.text
2638         return True
2639
2640
2641     ## Moves the node with the given id
2642     #  @param NodeID the id of the node
2643     #  @param x  a new X coordinate
2644     #  @param y  a new Y coordinate
2645     #  @param z  a new Z coordinate
2646     #  @return True if succeed else False
2647     #  @ingroup l2_modif_movenode
2648     def MoveNode(self, NodeID, x, y, z):
2649         x,y,z,Parameters = geompyDC.ParseParameters(x,y,z)
2650         self.mesh.SetParameters(Parameters)
2651         return self.editor.MoveNode(NodeID, x, y, z)
2652
2653     ## Finds the node closest to a point and moves it to a point location
2654     #  @param x  the X coordinate of a point
2655     #  @param y  the Y coordinate of a point
2656     #  @param z  the Z coordinate of a point
2657     #  @param NodeID if specified (>0), the node with this ID is moved,
2658     #  otherwise, the node closest to point (@a x,@a y,@a z) is moved
2659     #  @return the ID of a node
2660     #  @ingroup l2_modif_throughp
2661     def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2662         x,y,z,Parameters = geompyDC.ParseParameters(x,y,z)
2663         self.mesh.SetParameters(Parameters)
2664         return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2665
2666     ## Finds the node closest to a point
2667     #  @param x  the X coordinate of a point
2668     #  @param y  the Y coordinate of a point
2669     #  @param z  the Z coordinate of a point
2670     #  @return the ID of a node
2671     #  @ingroup l2_modif_throughp
2672     def FindNodeClosestTo(self, x, y, z):
2673         #preview = self.mesh.GetMeshEditPreviewer()
2674         #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2675         return self.editor.FindNodeClosestTo(x, y, z)
2676
2677     ## Finds the elements where a point lays IN or ON
2678     #  @param x  the X coordinate of a point
2679     #  @param y  the Y coordinate of a point
2680     #  @param z  the Z coordinate of a point
2681     #  @param elementType type of elements to find (SMESH.ALL type
2682     #         means elements of any type excluding nodes and 0D elements)
2683     #  @return list of IDs of found elements
2684     #  @ingroup l2_modif_throughp
2685     def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL):
2686         return self.editor.FindElementsByPoint(x, y, z, elementType)
2687         
2688     # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
2689     # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2690      
2691     def GetPointState(self, x, y, z):
2692         return self.editor.GetPointState(x, y, z)
2693
2694     ## Finds the node closest to a point and moves it to a point location
2695     #  @param x  the X coordinate of a point
2696     #  @param y  the Y coordinate of a point
2697     #  @param z  the Z coordinate of a point
2698     #  @return the ID of a moved node
2699     #  @ingroup l2_modif_throughp
2700     def MeshToPassThroughAPoint(self, x, y, z):
2701         return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2702
2703     ## Replaces two neighbour triangles sharing Node1-Node2 link
2704     #  with the triangles built on the same 4 nodes but having other common link.
2705     #  @param NodeID1  the ID of the first node
2706     #  @param NodeID2  the ID of the second node
2707     #  @return false if proper faces were not found
2708     #  @ingroup l2_modif_invdiag
2709     def InverseDiag(self, NodeID1, NodeID2):
2710         return self.editor.InverseDiag(NodeID1, NodeID2)
2711
2712     ## Replaces two neighbour triangles sharing Node1-Node2 link
2713     #  with a quadrangle built on the same 4 nodes.
2714     #  @param NodeID1  the ID of the first node
2715     #  @param NodeID2  the ID of the second node
2716     #  @return false if proper faces were not found
2717     #  @ingroup l2_modif_unitetri
2718     def DeleteDiag(self, NodeID1, NodeID2):
2719         return self.editor.DeleteDiag(NodeID1, NodeID2)
2720
2721     ## Reorients elements by ids
2722     #  @param IDsOfElements if undefined reorients all mesh elements
2723     #  @return True if succeed else False
2724     #  @ingroup l2_modif_changori
2725     def Reorient(self, IDsOfElements=None):
2726         if IDsOfElements == None:
2727             IDsOfElements = self.GetElementsId()
2728         return self.editor.Reorient(IDsOfElements)
2729
2730     ## Reorients all elements of the object
2731     #  @param theObject mesh, submesh or group
2732     #  @return True if succeed else False
2733     #  @ingroup l2_modif_changori
2734     def ReorientObject(self, theObject):
2735         if ( isinstance( theObject, Mesh )):
2736             theObject = theObject.GetMesh()
2737         return self.editor.ReorientObject(theObject)
2738
2739     ## Fuses the neighbouring triangles into quadrangles.
2740     #  @param IDsOfElements The triangles to be fused,
2741     #  @param theCriterion  is FT_...; used to choose a neighbour to fuse with.
2742     #  @param MaxAngle      is the maximum angle between element normals at which the fusion
2743     #                       is still performed; theMaxAngle is mesured in radians.
2744     #                       Also it could be a name of variable which defines angle in degrees.
2745     #  @return TRUE in case of success, FALSE otherwise.
2746     #  @ingroup l2_modif_unitetri
2747     def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2748         flag = False
2749         if isinstance(MaxAngle,str):
2750             flag = True
2751         MaxAngle,Parameters = geompyDC.ParseParameters(MaxAngle)
2752         if flag:
2753             MaxAngle = DegreesToRadians(MaxAngle)
2754         if IDsOfElements == []:
2755             IDsOfElements = self.GetElementsId()
2756         self.mesh.SetParameters(Parameters)
2757         Functor = 0
2758         if ( isinstance( theCriterion, SMESH._objref_NumericalFunctor ) ):
2759             Functor = theCriterion
2760         else:
2761             Functor = self.smeshpyD.GetFunctor(theCriterion)
2762         return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2763
2764     ## Fuses the neighbouring triangles of the object into quadrangles
2765     #  @param theObject is mesh, submesh or group
2766     #  @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2767     #  @param MaxAngle   a max angle between element normals at which the fusion
2768     #                   is still performed; theMaxAngle is mesured in radians.
2769     #  @return TRUE in case of success, FALSE otherwise.
2770     #  @ingroup l2_modif_unitetri
2771     def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2772         if ( isinstance( theObject, Mesh )):
2773             theObject = theObject.GetMesh()
2774         return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2775
2776     ## Splits quadrangles into triangles.
2777     #  @param IDsOfElements the faces to be splitted.
2778     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
2779     #  @return TRUE in case of success, FALSE otherwise.
2780     #  @ingroup l2_modif_cutquadr
2781     def QuadToTri (self, IDsOfElements, theCriterion):
2782         if IDsOfElements == []:
2783             IDsOfElements = self.GetElementsId()
2784         return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2785
2786     ## Splits quadrangles into triangles.
2787     #  @param theObject  the object from which the list of elements is taken, this is mesh, submesh or group
2788     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
2789     #  @return TRUE in case of success, FALSE otherwise.
2790     #  @ingroup l2_modif_cutquadr
2791     def QuadToTriObject (self, theObject, theCriterion):
2792         if ( isinstance( theObject, Mesh )):
2793             theObject = theObject.GetMesh()
2794         return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2795
2796     ## Splits quadrangles into triangles.
2797     #  @param IDsOfElements the faces to be splitted
2798     #  @param Diag13        is used to choose a diagonal for splitting.
2799     #  @return TRUE in case of success, FALSE otherwise.
2800     #  @ingroup l2_modif_cutquadr
2801     def SplitQuad (self, IDsOfElements, Diag13):
2802         if IDsOfElements == []:
2803             IDsOfElements = self.GetElementsId()
2804         return self.editor.SplitQuad(IDsOfElements, Diag13)
2805
2806     ## Splits quadrangles into triangles.
2807     #  @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2808     #  @param Diag13    is used to choose a diagonal for splitting.
2809     #  @return TRUE in case of success, FALSE otherwise.
2810     #  @ingroup l2_modif_cutquadr
2811     def SplitQuadObject (self, theObject, Diag13):
2812         if ( isinstance( theObject, Mesh )):
2813             theObject = theObject.GetMesh()
2814         return self.editor.SplitQuadObject(theObject, Diag13)
2815
2816     ## Finds a better splitting of the given quadrangle.
2817     #  @param IDOfQuad   the ID of the quadrangle to be splitted.
2818     #  @param theCriterion  FT_...; a criterion to choose a diagonal for splitting.
2819     #  @return 1 if 1-3 diagonal is better, 2 if 2-4
2820     #          diagonal is better, 0 if error occurs.
2821     #  @ingroup l2_modif_cutquadr
2822     def BestSplit (self, IDOfQuad, theCriterion):
2823         return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2824
2825     ## Splits volumic elements into tetrahedrons
2826     #  @param elemIDs either list of elements or mesh or group or submesh
2827     #  @param method  flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2828     #         Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2829     #  @ingroup l2_modif_cutquadr
2830     def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2831         if isinstance( elemIDs, Mesh ):
2832             elemIDs = elemIDs.GetMesh()
2833         if ( isinstance( elemIDs, list )):
2834             elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2835         self.editor.SplitVolumesIntoTetra(elemIDs, method)
2836
2837     ## Splits quadrangle faces near triangular facets of volumes
2838     #
2839     #  @ingroup l1_auxiliary
2840     def SplitQuadsNearTriangularFacets(self):
2841         faces_array = self.GetElementsByType(SMESH.FACE)
2842         for face_id in faces_array:
2843             if self.GetElemNbNodes(face_id) == 4: # quadrangle
2844                 quad_nodes = self.mesh.GetElemNodes(face_id)
2845                 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2846                 isVolumeFound = False
2847                 for node1_elem in node1_elems:
2848                     if not isVolumeFound:
2849                         if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2850                             nb_nodes = self.GetElemNbNodes(node1_elem)
2851                             if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2852                                 volume_elem = node1_elem
2853                                 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2854                                 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2855                                     if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2856                                         isVolumeFound = True
2857                                         if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2858                                             self.SplitQuad([face_id], False) # diagonal 2-4
2859                                     elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2860                                         isVolumeFound = True
2861                                         self.SplitQuad([face_id], True) # diagonal 1-3
2862                                 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2863                                     if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2864                                         isVolumeFound = True
2865                                         self.SplitQuad([face_id], True) # diagonal 1-3
2866
2867     ## @brief Splits hexahedrons into tetrahedrons.
2868     #
2869     #  This operation uses pattern mapping functionality for splitting.
2870     #  @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2871     #  @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2872     #         pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2873     #         will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2874     #         key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2875     #         The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2876     #  @return TRUE in case of success, FALSE otherwise.
2877     #  @ingroup l1_auxiliary
2878     def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2879         # Pattern:     5.---------.6
2880         #              /|#*      /|
2881         #             / | #*    / |
2882         #            /  |  # * /  |
2883         #           /   |   # /*  |
2884         # (0,0,1) 4.---------.7 * |
2885         #          |#*  |1   | # *|
2886         #          | # *.----|---#.2
2887         #          |  #/ *   |   /
2888         #          |  /#  *  |  /
2889         #          | /   # * | /
2890         #          |/      #*|/
2891         # (0,0,0) 0.---------.3
2892         pattern_tetra = "!!! Nb of points: \n 8 \n\
2893         !!! Points: \n\
2894         0 0 0  !- 0 \n\
2895         0 1 0  !- 1 \n\
2896         1 1 0  !- 2 \n\
2897         1 0 0  !- 3 \n\
2898         0 0 1  !- 4 \n\
2899         0 1 1  !- 5 \n\
2900         1 1 1  !- 6 \n\
2901         1 0 1  !- 7 \n\
2902         !!! Indices of points of 6 tetras: \n\
2903         0 3 4 1 \n\
2904         7 4 3 1 \n\
2905         4 7 5 1 \n\
2906         6 2 5 7 \n\
2907         1 5 2 7 \n\
2908         2 3 1 7 \n"
2909
2910         pattern = self.smeshpyD.GetPattern()
2911         isDone  = pattern.LoadFromFile(pattern_tetra)
2912         if not isDone:
2913             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2914             return isDone
2915
2916         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2917         isDone = pattern.MakeMesh(self.mesh, False, False)
2918         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2919
2920         # split quafrangle faces near triangular facets of volumes
2921         self.SplitQuadsNearTriangularFacets()
2922
2923         return isDone
2924
2925     ## @brief Split hexahedrons into prisms.
2926     #
2927     #  Uses the pattern mapping functionality for splitting.
2928     #  @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2929     #  @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2930     #         pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2931     #         will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2932     #         will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2933     #         Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2934     #  @return TRUE in case of success, FALSE otherwise.
2935     #  @ingroup l1_auxiliary
2936     def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2937         # Pattern:     5.---------.6
2938         #              /|#       /|
2939         #             / | #     / |
2940         #            /  |  #   /  |
2941         #           /   |   # /   |
2942         # (0,0,1) 4.---------.7   |
2943         #          |    |    |    |
2944         #          |   1.----|----.2
2945         #          |   / *   |   /
2946         #          |  /   *  |  /
2947         #          | /     * | /
2948         #          |/       *|/
2949         # (0,0,0) 0.---------.3
2950         pattern_prism = "!!! Nb of points: \n 8 \n\
2951         !!! Points: \n\
2952         0 0 0  !- 0 \n\
2953         0 1 0  !- 1 \n\
2954         1 1 0  !- 2 \n\
2955         1 0 0  !- 3 \n\
2956         0 0 1  !- 4 \n\
2957         0 1 1  !- 5 \n\
2958         1 1 1  !- 6 \n\
2959         1 0 1  !- 7 \n\
2960         !!! Indices of points of 2 prisms: \n\
2961         0 1 3 4 5 7 \n\
2962         2 3 1 6 7 5 \n"
2963
2964         pattern = self.smeshpyD.GetPattern()
2965         isDone  = pattern.LoadFromFile(pattern_prism)
2966         if not isDone:
2967             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2968             return isDone
2969
2970         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2971         isDone = pattern.MakeMesh(self.mesh, False, False)
2972         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2973
2974         # Splits quafrangle faces near triangular facets of volumes
2975         self.SplitQuadsNearTriangularFacets()
2976
2977         return isDone
2978
2979     ## Smoothes elements
2980     #  @param IDsOfElements the list if ids of elements to smooth
2981     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2982     #  Note that nodes built on edges and boundary nodes are always fixed.
2983     #  @param MaxNbOfIterations the maximum number of iterations
2984     #  @param MaxAspectRatio varies in range [1.0, inf]
2985     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2986     #  @return TRUE in case of success, FALSE otherwise.
2987     #  @ingroup l2_modif_smooth
2988     def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2989                MaxNbOfIterations, MaxAspectRatio, Method):
2990         if IDsOfElements == []:
2991             IDsOfElements = self.GetElementsId()
2992         MaxNbOfIterations,MaxAspectRatio,Parameters = geompyDC.ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2993         self.mesh.SetParameters(Parameters)
2994         return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2995                                   MaxNbOfIterations, MaxAspectRatio, Method)
2996
2997     ## Smoothes elements which belong to the given object
2998     #  @param theObject the object to smooth
2999     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3000     #  Note that nodes built on edges and boundary nodes are always fixed.
3001     #  @param MaxNbOfIterations the maximum number of iterations
3002     #  @param MaxAspectRatio varies in range [1.0, inf]
3003     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3004     #  @return TRUE in case of success, FALSE otherwise.
3005     #  @ingroup l2_modif_smooth
3006     def SmoothObject(self, theObject, IDsOfFixedNodes,
3007                      MaxNbOfIterations, MaxAspectRatio, Method):
3008         if ( isinstance( theObject, Mesh )):
3009             theObject = theObject.GetMesh()
3010         return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3011                                         MaxNbOfIterations, MaxAspectRatio, Method)
3012
3013     ## Parametrically smoothes the given elements
3014     #  @param IDsOfElements the list if ids of elements to smooth
3015     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3016     #  Note that nodes built on edges and boundary nodes are always fixed.
3017     #  @param MaxNbOfIterations the maximum number of iterations
3018     #  @param MaxAspectRatio varies in range [1.0, inf]
3019     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3020     #  @return TRUE in case of success, FALSE otherwise.
3021     #  @ingroup l2_modif_smooth
3022     def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3023                          MaxNbOfIterations, MaxAspectRatio, Method):
3024         if IDsOfElements == []:
3025             IDsOfElements = self.GetElementsId()
3026         MaxNbOfIterations,MaxAspectRatio,Parameters = geompyDC.ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3027         self.mesh.SetParameters(Parameters)
3028         return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3029                                             MaxNbOfIterations, MaxAspectRatio, Method)
3030
3031     ## Parametrically smoothes the elements which belong to the given object
3032     #  @param theObject the object to smooth
3033     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3034     #  Note that nodes built on edges and boundary nodes are always fixed.
3035     #  @param MaxNbOfIterations the maximum number of iterations
3036     #  @param MaxAspectRatio varies in range [1.0, inf]
3037     #  @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3038     #  @return TRUE in case of success, FALSE otherwise.
3039     #  @ingroup l2_modif_smooth
3040     def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3041                                MaxNbOfIterations, MaxAspectRatio, Method):
3042         if ( isinstance( theObject, Mesh )):
3043             theObject = theObject.GetMesh()
3044         return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3045                                                   MaxNbOfIterations, MaxAspectRatio, Method)
3046
3047     ## Converts the mesh to quadratic, deletes old elements, replacing
3048     #  them with quadratic with the same id.
3049     #  @param theForce3d new node creation method:
3050     #         0 - the medium node lies at the geometrical edge from which the mesh element is built
3051     #         1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3052     #  @ingroup l2_modif_tofromqu
3053     def ConvertToQuadratic(self, theForce3d):
3054         self.editor.ConvertToQuadratic(theForce3d)
3055
3056     ## Converts the mesh from quadratic to ordinary,
3057     #  deletes old quadratic elements, \n replacing
3058     #  them with ordinary mesh elements with the same id.
3059     #  @return TRUE in case of success, FALSE otherwise.
3060     #  @ingroup l2_modif_tofromqu
3061     def ConvertFromQuadratic(self):
3062         return self.editor.ConvertFromQuadratic()
3063
3064     ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3065     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3066     #  @ingroup l2_modif_edit
3067     def  Make2DMeshFrom3D(self):
3068         return self.editor. Make2DMeshFrom3D()
3069
3070     ## Creates missing boundary elements
3071     #  @param elements - elements whose boundary is to be checked:
3072     #                    mesh, group, sub-mesh or list of elements
3073     #  @param dimension - defines type of boundary elements to create:
3074     #                     SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3075     #  @param groupName - a name of group to store created boundary elements in,
3076     #                     "" means not to create the group
3077     #  @param meshName - a name of new mesh to store created boundary elements in,
3078     #                     "" means not to create the new mesh
3079     #  @param toCopyElements - if true, the checked elements will be copied into the new mesh
3080     #  @param toCopyExistingBondary - if true, not only new but also pre-existing 
3081     #                                boundary elements will be copied into the new mesh
3082     #  @return tuple (mesh, group) where bondary elements were added to
3083     #  @ingroup l2_modif_edit
3084     def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3085                          toCopyElements=False, toCopyExistingBondary=False):
3086         if isinstance( elements, Mesh ):
3087             elements = elements.GetMesh()
3088         if ( isinstance( elements, list )):
3089             elemType = SMESH.ALL
3090             if elements: elemType = self.GetElementType( elements[0], iselem=True)
3091             elements = self.editor.MakeIDSource(elements, elemType)
3092         mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3093                                                    toCopyElements,toCopyExistingBondary)
3094         if mesh: mesh = self.smeshpyD.Mesh(mesh)
3095         return mesh, group
3096
3097     ## Renumber mesh nodes
3098     #  @ingroup l2_modif_renumber
3099     def RenumberNodes(self):
3100         self.editor.RenumberNodes()
3101
3102     ## Renumber mesh elements
3103     #  @ingroup l2_modif_renumber
3104     def RenumberElements(self):
3105         self.editor.RenumberElements()
3106
3107     ## Generates new elements by rotation of the elements around the axis
3108     #  @param IDsOfElements the list of ids of elements to sweep
3109     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3110     #  @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3111     #  @param NbOfSteps the number of steps
3112     #  @param Tolerance tolerance
3113     #  @param MakeGroups forces the generation of new groups from existing ones
3114     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3115     #                    of all steps, else - size of each step
3116     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3117     #  @ingroup l2_modif_extrurev
3118     def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3119                       MakeGroups=False, TotalAngle=False):
3120         flag = False
3121         if isinstance(AngleInRadians,str):
3122             flag = True
3123         AngleInRadians,AngleParameters = geompyDC.ParseParameters(AngleInRadians)
3124         if flag:
3125             AngleInRadians = DegreesToRadians(AngleInRadians)
3126         if IDsOfElements == []:
3127             IDsOfElements = self.GetElementsId()
3128         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3129             Axis = self.smeshpyD.GetAxisStruct(Axis)
3130         Axis,AxisParameters = ParseAxisStruct(Axis)
3131         if TotalAngle and NbOfSteps:
3132             AngleInRadians /= NbOfSteps
3133         NbOfSteps,Tolerance,Parameters = geompyDC.ParseParameters(NbOfSteps,Tolerance)
3134         Parameters = AxisParameters + var_separator + AngleParameters + var_separator + Parameters
3135         self.mesh.SetParameters(Parameters)
3136         if MakeGroups:
3137             return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3138                                                        AngleInRadians, NbOfSteps, Tolerance)
3139         self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3140         return []
3141
3142     ## Generates new elements by rotation of the elements of object around the axis
3143     #  @param theObject object which elements should be sweeped
3144     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3145     #  @param AngleInRadians the angle of Rotation
3146     #  @param NbOfSteps number of steps
3147     #  @param Tolerance tolerance
3148     #  @param MakeGroups forces the generation of new groups from existing ones
3149     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3150     #                    of all steps, else - size of each step
3151     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3152     #  @ingroup l2_modif_extrurev
3153     def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3154                             MakeGroups=False, TotalAngle=False):
3155         flag = False
3156         if isinstance(AngleInRadians,str):
3157             flag = True
3158         AngleInRadians,AngleParameters = geompyDC.ParseParameters(AngleInRadians)
3159         if flag:
3160             AngleInRadians = DegreesToRadians(AngleInRadians)
3161         if ( isinstance( theObject, Mesh )):
3162             theObject = theObject.GetMesh()
3163         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3164             Axis = self.smeshpyD.GetAxisStruct(Axis)
3165         Axis,AxisParameters = ParseAxisStruct(Axis)
3166         if TotalAngle and NbOfSteps:
3167             AngleInRadians /= NbOfSteps
3168         NbOfSteps,Tolerance,Parameters = geompyDC.ParseParameters(NbOfSteps,Tolerance)
3169         Parameters = AxisParameters + var_separator + AngleParameters + var_separator + Parameters
3170         self.mesh.SetParameters(Parameters)
3171         if MakeGroups:
3172             return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3173                                                              NbOfSteps, Tolerance)
3174         self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3175         return []
3176
3177     ## Generates new elements by rotation of the elements of object around the axis
3178     #  @param theObject object which elements should be sweeped
3179     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3180     #  @param AngleInRadians the angle of Rotation
3181     #  @param NbOfSteps number of steps
3182     #  @param Tolerance tolerance
3183     #  @param MakeGroups forces the generation of new groups from existing ones
3184     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3185     #                    of all steps, else - size of each step
3186     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3187     #  @ingroup l2_modif_extrurev
3188     def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3189                               MakeGroups=False, TotalAngle=False):
3190         flag = False
3191         if isinstance(AngleInRadians,str):
3192             flag = True
3193         AngleInRadians,AngleParameters = geompyDC.ParseParameters(AngleInRadians)
3194         if flag:
3195             AngleInRadians = DegreesToRadians(AngleInRadians)
3196         if ( isinstance( theObject, Mesh )):
3197             theObject = theObject.GetMesh()
3198         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3199             Axis = self.smeshpyD.GetAxisStruct(Axis)
3200         Axis,AxisParameters = ParseAxisStruct(Axis)
3201         if TotalAngle and NbOfSteps:
3202             AngleInRadians /= NbOfSteps
3203         NbOfSteps,Tolerance,Parameters = geompyDC.ParseParameters(NbOfSteps,Tolerance)
3204         Parameters = AxisParameters + var_separator + AngleParameters + var_separator + Parameters
3205         self.mesh.SetParameters(Parameters)
3206         if MakeGroups:
3207             return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3208                                                                NbOfSteps, Tolerance)
3209         self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3210         return []
3211
3212     ## Generates new elements by rotation of the elements of object around the axis
3213     #  @param theObject object which elements should be sweeped
3214     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3215     #  @param AngleInRadians the angle of Rotation
3216     #  @param NbOfSteps number of steps
3217     #  @param Tolerance tolerance
3218     #  @param MakeGroups forces the generation of new groups from existing ones
3219     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3220     #                    of all steps, else - size of each step
3221     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3222     #  @ingroup l2_modif_extrurev
3223     def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3224                               MakeGroups=False, TotalAngle=False):
3225         flag = False
3226         if isinstance(AngleInRadians,str):
3227             flag = True
3228         AngleInRadians,AngleParameters = geompyDC.ParseParameters(AngleInRadians)
3229         if flag:
3230             AngleInRadians = DegreesToRadians(AngleInRadians)
3231         if ( isinstance( theObject, Mesh )):
3232             theObject = theObject.GetMesh()
3233         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3234             Axis = self.smeshpyD.GetAxisStruct(Axis)
3235         Axis,AxisParameters = ParseAxisStruct(Axis)
3236         if TotalAngle and NbOfSteps:
3237             AngleInRadians /= NbOfSteps
3238         NbOfSteps,Tolerance,Parameters = geompyDC.ParseParameters(NbOfSteps,Tolerance)
3239         Parameters = AxisParameters + var_separator + AngleParameters + var_separator + Parameters
3240         self.mesh.SetParameters(Parameters)
3241         if MakeGroups:
3242             return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3243                                                              NbOfSteps, Tolerance)
3244         self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3245         return []
3246
3247     ## Generates new elements by extrusion of the elements with given ids
3248     #  @param IDsOfElements the list of elements ids for extrusion
3249     #  @param StepVector vector or DirStruct, defining the direction and value of extrusion
3250     #  @param NbOfSteps the number of steps
3251     #  @param MakeGroups forces the generation of new groups from existing ones
3252     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3253     #  @ingroup l2_modif_extrurev
3254     def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
3255         if IDsOfElements == []:
3256             IDsOfElements = self.GetElementsId()
3257         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3258             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3259         StepVector,StepVectorParameters = ParseDirStruct(StepVector)
3260         NbOfSteps,Parameters = geompyDC.ParseParameters(NbOfSteps)
3261         Parameters = StepVectorParameters + var_separator + Parameters
3262         self.mesh.SetParameters(Parameters)
3263         if MakeGroups:
3264             return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3265         self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3266         return []
3267
3268     ## Generates new elements by extrusion of the elements with given ids
3269     #  @param IDsOfElements is ids of elements
3270     #  @param StepVector vector, defining the direction and value of extrusion
3271     #  @param NbOfSteps the number of steps
3272     #  @param ExtrFlags sets flags for extrusion
3273     #  @param SewTolerance uses for comparing locations of nodes if flag
3274     #         EXTRUSION_FLAG_SEW is set
3275     #  @param MakeGroups forces the generation of new groups from existing ones
3276     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3277     #  @ingroup l2_modif_extrurev
3278     def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3279                           ExtrFlags, SewTolerance, MakeGroups=False):
3280         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3281             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3282         if MakeGroups:
3283             return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3284                                                            ExtrFlags, SewTolerance)
3285         self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3286                                       ExtrFlags, SewTolerance)
3287         return []
3288
3289     ## Generates new elements by extrusion of the elements which belong to the object
3290     #  @param theObject the object which elements should be processed
3291     #  @param StepVector vector, defining the direction and value of extrusion
3292     #  @param NbOfSteps the number of steps
3293     #  @param MakeGroups forces the generation of new groups from existing ones
3294     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3295     #  @ingroup l2_modif_extrurev
3296     def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3297         if ( isinstance( theObject, Mesh )):
3298             theObject = theObject.GetMesh()
3299         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3300             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3301         StepVector,StepVectorParameters = ParseDirStruct(StepVector)
3302         NbOfSteps,Parameters = geompyDC.ParseParameters(NbOfSteps)
3303         Parameters = StepVectorParameters + var_separator + Parameters
3304         self.mesh.SetParameters(Parameters)
3305         if MakeGroups:
3306             return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3307         self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3308         return []
3309
3310     ## Generates new elements by extrusion of the elements which belong to the object
3311     #  @param theObject object which elements should be processed
3312     #  @param StepVector vector, defining the direction and value of extrusion
3313     #  @param NbOfSteps the number of steps
3314     #  @param MakeGroups to generate new groups from existing ones
3315     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3316     #  @ingroup l2_modif_extrurev
3317     def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3318         if ( isinstance( theObject, Mesh )):
3319             theObject = theObject.GetMesh()
3320         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3321             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3322         StepVector,StepVectorParameters = ParseDirStruct(StepVector)
3323         NbOfSteps,Parameters = geompyDC.ParseParameters(NbOfSteps)
3324         Parameters = StepVectorParameters + var_separator + Parameters
3325         self.mesh.SetParameters(Parameters)
3326         if MakeGroups:
3327             return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3328         self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3329         return []
3330
3331     ## Generates new elements by extrusion of the elements which belong to the object
3332     #  @param theObject object which elements should be processed
3333     #  @param StepVector vector, defining the direction and value of extrusion
3334     #  @param NbOfSteps the number of steps
3335     #  @param MakeGroups forces the generation of new groups from existing ones
3336     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3337     #  @ingroup l2_modif_extrurev
3338     def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3339         if ( isinstance( theObject, Mesh )):
3340             theObject = theObject.GetMesh()
3341         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3342             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3343         StepVector,StepVectorParameters = ParseDirStruct(StepVector)
3344         NbOfSteps,Parameters = geompyDC.ParseParameters(NbOfSteps)
3345         Parameters = StepVectorParameters + var_separator + Parameters
3346         self.mesh.SetParameters(Parameters)
3347         if MakeGroups:
3348             return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3349         self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3350         return []
3351
3352
3353
3354     ## Generates new elements by extrusion of the given elements
3355     #  The path of extrusion must be a meshed edge.
3356     #  @param Base mesh or list of ids of elements for extrusion
3357     #  @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3358     #  @param NodeStart the start node from Path. Defines the direction of extrusion
3359     #  @param HasAngles allows the shape to be rotated around the path
3360     #                   to get the resulting mesh in a helical fashion
3361     #  @param Angles list of angles in radians
3362     #  @param LinearVariation forces the computation of rotation angles as linear
3363     #                         variation of the given Angles along path steps
3364     #  @param HasRefPoint allows using the reference point
3365     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3366     #         The User can specify any point as the Reference Point.
3367     #  @param MakeGroups forces the generation of new groups from existing ones
3368     #  @param ElemType type of elements for extrusion (if param Base is a mesh)
3369     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3370     #          only SMESH::Extrusion_Error otherwise
3371     #  @ingroup l2_modif_extrurev
3372     def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3373                             HasAngles, Angles, LinearVariation,
3374                             HasRefPoint, RefPoint, MakeGroups, ElemType):
3375         Angles,AnglesParameters = ParseAngles(Angles)
3376         RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
3377         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3378             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3379             pass
3380         Parameters = AnglesParameters + var_separator + RefPointParameters
3381         self.mesh.SetParameters(Parameters)
3382
3383         if isinstance(Base,list):
3384             IDsOfElements = []
3385             if Base == []: IDsOfElements = self.GetElementsId()
3386             else: IDsOfElements = Base
3387             return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3388                                                    HasAngles, Angles, LinearVariation,
3389                                                    HasRefPoint, RefPoint, MakeGroups, ElemType)
3390         else:
3391             if isinstance(Base,Mesh):
3392                 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3393                                                           HasAngles, Angles, LinearVariation,
3394                                                           HasRefPoint, RefPoint, MakeGroups, ElemType)
3395             else:
3396                 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3397
3398
3399     ## Generates new elements by extrusion of the given elements
3400     #  The path of extrusion must be a meshed edge.
3401     #  @param IDsOfElements ids of elements
3402     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3403     #  @param PathShape shape(edge) defines the sub-mesh for the path
3404     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3405     #  @param HasAngles allows the shape to be rotated around the path
3406     #                   to get the resulting mesh in a helical fashion
3407     #  @param Angles list of angles in radians
3408     #  @param HasRefPoint allows using the reference point
3409     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3410     #         The User can specify any point as the Reference Point.
3411     #  @param MakeGroups forces the generation of new groups from existing ones
3412     #  @param LinearVariation forces the computation of rotation angles as linear
3413     #                         variation of the given Angles along path steps
3414     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3415     #          only SMESH::Extrusion_Error otherwise
3416     #  @ingroup l2_modif_extrurev
3417     def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3418                            HasAngles, Angles, HasRefPoint, RefPoint,
3419                            MakeGroups=False, LinearVariation=False):
3420         Angles,AnglesParameters = ParseAngles(Angles)
3421         RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
3422         if IDsOfElements == []:
3423             IDsOfElements = self.GetElementsId()
3424         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3425             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3426             pass
3427         if ( isinstance( PathMesh, Mesh )):
3428             PathMesh = PathMesh.GetMesh()
3429         if HasAngles and Angles and LinearVariation:
3430             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3431             pass
3432         Parameters = AnglesParameters + var_separator + RefPointParameters
3433         self.mesh.SetParameters(Parameters)
3434         if MakeGroups:
3435             return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3436                                                             PathShape, NodeStart, HasAngles,
3437                                                             Angles, HasRefPoint, RefPoint)
3438         return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3439                                               NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3440
3441     ## Generates new elements by extrusion of the elements which belong to the object
3442     #  The path of extrusion must be a meshed edge.
3443     #  @param theObject the object which elements should be processed
3444     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3445     #  @param PathShape shape(edge) defines the sub-mesh for the path
3446     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3447     #  @param HasAngles allows the shape to be rotated around the path
3448     #                   to get the resulting mesh in a helical fashion
3449     #  @param Angles list of angles
3450     #  @param HasRefPoint allows using the reference point
3451     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3452     #         The User can specify any point as the Reference Point.
3453     #  @param MakeGroups forces the generation of new groups from existing ones
3454     #  @param LinearVariation forces the computation of rotation angles as linear
3455     #                         variation of the given Angles along path steps
3456     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3457     #          only SMESH::Extrusion_Error otherwise
3458     #  @ingroup l2_modif_extrurev
3459     def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3460                                  HasAngles, Angles, HasRefPoint, RefPoint,
3461                                  MakeGroups=False, LinearVariation=False):
3462         Angles,AnglesParameters = ParseAngles(Angles)
3463         RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
3464         if ( isinstance( theObject, Mesh )):
3465             theObject = theObject.GetMesh()
3466         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3467             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3468         if ( isinstance( PathMesh, Mesh )):
3469             PathMesh = PathMesh.GetMesh()
3470         if HasAngles and Angles and LinearVariation:
3471             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3472             pass
3473         Parameters = AnglesParameters + var_separator + RefPointParameters
3474         self.mesh.SetParameters(Parameters)
3475         if MakeGroups:
3476             return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3477                                                                   PathShape, NodeStart, HasAngles,
3478                                                                   Angles, HasRefPoint, RefPoint)
3479         return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3480                                                     NodeStart, HasAngles, Angles, HasRefPoint,
3481                                                     RefPoint)
3482
3483     ## Generates new elements by extrusion of the elements which belong to the object
3484     #  The path of extrusion must be a meshed edge.
3485     #  @param theObject the object which elements should be processed
3486     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3487     #  @param PathShape shape(edge) defines the sub-mesh for the path
3488     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3489     #  @param HasAngles allows the shape to be rotated around the path
3490     #                   to get the resulting mesh in a helical fashion
3491     #  @param Angles list of angles
3492     #  @param HasRefPoint allows using the reference point
3493     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3494     #         The User can specify any point as the Reference Point.
3495     #  @param MakeGroups forces the generation of new groups from existing ones
3496     #  @param LinearVariation forces the computation of rotation angles as linear
3497     #                         variation of the given Angles along path steps
3498     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3499     #          only SMESH::Extrusion_Error otherwise
3500     #  @ingroup l2_modif_extrurev
3501     def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3502                                    HasAngles, Angles, HasRefPoint, RefPoint,
3503                                    MakeGroups=False, LinearVariation=False):
3504         Angles,AnglesParameters = ParseAngles(Angles)
3505         RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
3506         if ( isinstance( theObject, Mesh )):
3507             theObject = theObject.GetMesh()
3508         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3509             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3510         if ( isinstance( PathMesh, Mesh )):
3511             PathMesh = PathMesh.GetMesh()
3512         if HasAngles and Angles and LinearVariation:
3513             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3514             pass
3515         Parameters = AnglesParameters + var_separator + RefPointParameters
3516         self.mesh.SetParameters(Parameters)
3517         if MakeGroups:
3518             return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3519                                                                     PathShape, NodeStart, HasAngles,
3520                                                                     Angles, HasRefPoint, RefPoint)
3521         return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3522                                                       NodeStart, HasAngles, Angles, HasRefPoint,
3523                                                       RefPoint)
3524
3525     ## Generates new elements by extrusion of the elements which belong to the object
3526     #  The path of extrusion must be a meshed edge.
3527     #  @param theObject the object which elements should be processed
3528     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3529     #  @param PathShape shape(edge) defines the sub-mesh for the path
3530     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3531     #  @param HasAngles allows the shape to be rotated around the path
3532     #                   to get the resulting mesh in a helical fashion
3533     #  @param Angles list of angles
3534     #  @param HasRefPoint allows using the reference point
3535     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3536     #         The User can specify any point as the Reference Point.
3537     #  @param MakeGroups forces the generation of new groups from existing ones
3538     #  @param LinearVariation forces the computation of rotation angles as linear
3539     #                         variation of the given Angles along path steps
3540     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3541     #          only SMESH::Extrusion_Error otherwise
3542     #  @ingroup l2_modif_extrurev
3543     def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3544                                    HasAngles, Angles, HasRefPoint, RefPoint,
3545                                    MakeGroups=False, LinearVariation=False):
3546         Angles,AnglesParameters = ParseAngles(Angles)
3547         RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
3548         if ( isinstance( theObject, Mesh )):
3549             theObject = theObject.GetMesh()
3550         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3551             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3552         if ( isinstance( PathMesh, Mesh )):
3553             PathMesh = PathMesh.GetMesh()
3554         if HasAngles and Angles and LinearVariation:
3555             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3556             pass
3557         Parameters = AnglesParameters + var_separator + RefPointParameters
3558         self.mesh.SetParameters(Parameters)
3559         if MakeGroups:
3560             return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3561                                                                     PathShape, NodeStart, HasAngles,
3562                                                                     Angles, HasRefPoint, RefPoint)
3563         return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3564                                                       NodeStart, HasAngles, Angles, HasRefPoint,
3565                                                       RefPoint)
3566
3567     ## Creates a symmetrical copy of mesh elements
3568     #  @param IDsOfElements list of elements ids
3569     #  @param Mirror is AxisStruct or geom object(point, line, plane)
3570     #  @param theMirrorType is  POINT, AXIS or PLANE
3571     #  If the Mirror is a geom object this parameter is unnecessary
3572     #  @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3573     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3574     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3575     #  @ingroup l2_modif_trsf
3576     def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3577         if IDsOfElements == []:
3578             IDsOfElements = self.GetElementsId()
3579         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3580             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3581         Mirror,Parameters = ParseAxisStruct(Mirror)
3582         self.mesh.SetParameters(Parameters)
3583         if Copy and MakeGroups:
3584             return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3585         self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3586         return []
3587
3588     ## Creates a new mesh by a symmetrical copy of mesh elements
3589     #  @param IDsOfElements the list of elements ids
3590     #  @param Mirror is AxisStruct or geom object (point, line, plane)
3591     #  @param theMirrorType is  POINT, AXIS or PLANE
3592     #  If the Mirror is a geom object this parameter is unnecessary
3593     #  @param MakeGroups to generate new groups from existing ones
3594     #  @param NewMeshName a name of the new mesh to create
3595     #  @return instance of Mesh class
3596     #  @ingroup l2_modif_trsf
3597     def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3598         if IDsOfElements == []:
3599             IDsOfElements = self.GetElementsId()
3600         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3601             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3602         Mirror,Parameters = ParseAxisStruct(Mirror)
3603         mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3604                                           MakeGroups, NewMeshName)
3605         mesh.SetParameters(Parameters)
3606         return Mesh(self.smeshpyD,self.geompyD,mesh)
3607
3608     ## Creates a symmetrical copy of the object
3609     #  @param theObject mesh, submesh or group
3610     #  @param Mirror AxisStruct or geom object (point, line, plane)
3611     #  @param theMirrorType is  POINT, AXIS or PLANE
3612     #  If the Mirror is a geom object this parameter is unnecessary
3613     #  @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3614     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3615     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3616     #  @ingroup l2_modif_trsf
3617     def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3618         if ( isinstance( theObject, Mesh )):
3619             theObject = theObject.GetMesh()
3620         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3621             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3622         Mirror,Parameters = ParseAxisStruct(Mirror)
3623         self.mesh.SetParameters(Parameters)
3624         if Copy and MakeGroups:
3625             return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3626         self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3627         return []
3628
3629     ## Creates a new mesh by a symmetrical copy of the object
3630     #  @param theObject mesh, submesh or group
3631     #  @param Mirror AxisStruct or geom object (point, line, plane)
3632     #  @param theMirrorType POINT, AXIS or PLANE
3633     #  If the Mirror is a geom object this parameter is unnecessary
3634     #  @param MakeGroups forces the generation of new groups from existing ones
3635     #  @param NewMeshName the name of the new mesh to create
3636     #  @return instance of Mesh class
3637     #  @ingroup l2_modif_trsf
3638     def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3639         if ( isinstance( theObject, Mesh )):
3640             theObject = theObject.GetMesh()
3641         if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3642             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3643         Mirror,Parameters = ParseAxisStruct(Mirror)
3644         mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3645                                                 MakeGroups, NewMeshName)
3646         mesh.SetParameters(Parameters)
3647         return Mesh( self.smeshpyD,self.geompyD,mesh )
3648
3649     ## Translates the elements
3650     #  @param IDsOfElements list of elements ids
3651     #  @param Vector the direction of translation (DirStruct or vector)
3652     #  @param Copy allows copying the translated elements
3653     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3654     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3655     #  @ingroup l2_modif_trsf
3656     def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3657         if IDsOfElements == []:
3658             IDsOfElements = self.GetElementsId()
3659         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3660             Vector = self.smeshpyD.GetDirStruct(Vector)
3661         Vector,Parameters = ParseDirStruct(Vector)
3662         self.mesh.SetParameters(Parameters)
3663         if Copy and MakeGroups:
3664             return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3665         self.editor.Translate(IDsOfElements, Vector, Copy)
3666         return []
3667
3668     ## Creates a new mesh of translated elements
3669     #  @param IDsOfElements list of elements ids
3670     #  @param Vector the direction of translation (DirStruct or vector)
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 TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3676         if IDsOfElements == []:
3677             IDsOfElements = self.GetElementsId()
3678         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3679             Vector = self.smeshpyD.GetDirStruct(Vector)
3680         Vector,Parameters = ParseDirStruct(Vector)
3681         mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3682         mesh.SetParameters(Parameters)
3683         return Mesh ( self.smeshpyD, self.geompyD, mesh )
3684
3685     ## Translates the object
3686     #  @param theObject the object to translate (mesh, submesh, or group)
3687     #  @param Vector direction of translation (DirStruct or geom vector)
3688     #  @param Copy allows copying the translated elements
3689     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3690     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3691     #  @ingroup l2_modif_trsf
3692     def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3693         if ( isinstance( theObject, Mesh )):
3694             theObject = theObject.GetMesh()
3695         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3696             Vector = self.smeshpyD.GetDirStruct(Vector)
3697         Vector,Parameters = ParseDirStruct(Vector)
3698         self.mesh.SetParameters(Parameters)
3699         if Copy and MakeGroups:
3700             return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3701         self.editor.TranslateObject(theObject, Vector, Copy)
3702         return []
3703
3704     ## Creates a new mesh from the translated object
3705     #  @param theObject the object to translate (mesh, submesh, or group)
3706     #  @param Vector the direction of translation (DirStruct or geom vector)
3707     #  @param MakeGroups forces the generation of new groups from existing ones
3708     #  @param NewMeshName the name of the newly created mesh
3709     #  @return instance of Mesh class
3710     #  @ingroup l2_modif_trsf
3711     def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3712         if (isinstance(theObject, Mesh)):
3713             theObject = theObject.GetMesh()
3714         if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3715             Vector = self.smeshpyD.GetDirStruct(Vector)
3716         Vector,Parameters = ParseDirStruct(Vector)
3717         mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3718         mesh.SetParameters(Parameters)
3719         return Mesh( self.smeshpyD, self.geompyD, mesh )
3720
3721
3722
3723     ## Scales the object
3724     #  @param theObject - the object to translate (mesh, submesh, or group)
3725     #  @param thePoint - base point for scale
3726     #  @param theScaleFact - list of 1-3 scale factors for axises
3727     #  @param Copy - allows copying the translated elements
3728     #  @param MakeGroups - forces the generation of new groups from existing
3729     #                      ones (if Copy)
3730     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3731     #          empty list otherwise
3732     def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3733         if ( isinstance( theObject, Mesh )):
3734             theObject = theObject.GetMesh()
3735         if ( isinstance( theObject, list )):
3736             theObject = self.GetIDSource(theObject, SMESH.ALL)
3737
3738         thePoint, Parameters = ParsePointStruct(thePoint)
3739         self.mesh.SetParameters(Parameters)
3740
3741         if Copy and MakeGroups:
3742             return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3743         self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3744         return []
3745
3746     ## Creates a new mesh from the translated object
3747     #  @param theObject - the object to translate (mesh, submesh, or group)
3748     #  @param thePoint - base point for scale
3749     #  @param theScaleFact - list of 1-3 scale factors for axises
3750     #  @param MakeGroups - forces the generation of new groups from existing ones
3751     #  @param NewMeshName - the name of the newly created mesh
3752     #  @return instance of Mesh class
3753     def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3754         if (isinstance(theObject, Mesh)):
3755             theObject = theObject.GetMesh()
3756         if ( isinstance( theObject, list )):
3757             theObject = self.GetIDSource(theObject,SMESH.ALL)
3758
3759         mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3760                                          MakeGroups, NewMeshName)
3761         #mesh.SetParameters(Parameters)
3762         return Mesh( self.smeshpyD, self.geompyD, mesh )
3763
3764
3765
3766     ## Rotates the elements
3767     #  @param IDsOfElements list of elements ids
3768     #  @param Axis the axis of rotation (AxisStruct or geom line)
3769     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3770     #  @param Copy allows copying the rotated elements
3771     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3772     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3773     #  @ingroup l2_modif_trsf
3774     def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3775         flag = False
3776         if isinstance(AngleInRadians,str):
3777             flag = True
3778         AngleInRadians,Parameters = geompyDC.ParseParameters(AngleInRadians)
3779         if flag:
3780             AngleInRadians = DegreesToRadians(AngleInRadians)
3781         if IDsOfElements == []:
3782             IDsOfElements = self.GetElementsId()
3783         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3784             Axis = self.smeshpyD.GetAxisStruct(Axis)
3785         Axis,AxisParameters = ParseAxisStruct(Axis)
3786         Parameters = AxisParameters + var_separator + Parameters
3787         self.mesh.SetParameters(Parameters)
3788         if Copy and MakeGroups:
3789             return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3790         self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3791         return []
3792
3793     ## Creates a new mesh of rotated elements
3794     #  @param IDsOfElements list of element ids
3795     #  @param Axis the axis of rotation (AxisStruct or geom line)
3796     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3797     #  @param MakeGroups forces the generation of new groups from existing ones
3798     #  @param NewMeshName the name of the newly created mesh
3799     #  @return instance of Mesh class
3800     #  @ingroup l2_modif_trsf
3801     def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3802         flag = False
3803         if isinstance(AngleInRadians,str):
3804             flag = True
3805         AngleInRadians,Parameters = geompyDC.ParseParameters(AngleInRadians)
3806         if flag:
3807             AngleInRadians = DegreesToRadians(AngleInRadians)
3808         if IDsOfElements == []:
3809             IDsOfElements = self.GetElementsId()
3810         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3811             Axis = self.smeshpyD.GetAxisStruct(Axis)
3812         Axis,AxisParameters = ParseAxisStruct(Axis)
3813         Parameters = AxisParameters + var_separator + Parameters
3814         mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3815                                           MakeGroups, NewMeshName)
3816         mesh.SetParameters(Parameters)
3817         return Mesh( self.smeshpyD, self.geompyD, mesh )
3818
3819     ## Rotates the object
3820     #  @param theObject the object to rotate( mesh, submesh, or group)
3821     #  @param Axis the axis of rotation (AxisStruct or geom line)
3822     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3823     #  @param Copy allows copying the rotated elements
3824     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3825     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3826     #  @ingroup l2_modif_trsf
3827     def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3828         flag = False
3829         if isinstance(AngleInRadians,str):
3830             flag = True
3831         AngleInRadians,Parameters = geompyDC.ParseParameters(AngleInRadians)
3832         if flag:
3833             AngleInRadians = DegreesToRadians(AngleInRadians)
3834         if (isinstance(theObject, Mesh)):
3835             theObject = theObject.GetMesh()
3836         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3837             Axis = self.smeshpyD.GetAxisStruct(Axis)
3838         Axis,AxisParameters = ParseAxisStruct(Axis)
3839         Parameters = AxisParameters + ":" + Parameters
3840         self.mesh.SetParameters(Parameters)
3841         if Copy and MakeGroups:
3842             return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3843         self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3844         return []
3845
3846     ## Creates a new mesh from the rotated object
3847     #  @param theObject the object to rotate (mesh, submesh, or group)
3848     #  @param Axis the axis of rotation (AxisStruct or geom line)
3849     #  @param AngleInRadians the angle of rotation (in radians)  or a name of variable which defines angle in degrees
3850     #  @param MakeGroups forces the generation of new groups from existing ones
3851     #  @param NewMeshName the name of the newly created mesh
3852     #  @return instance of Mesh class
3853     #  @ingroup l2_modif_trsf
3854     def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3855         flag = False
3856         if isinstance(AngleInRadians,str):
3857             flag = True
3858         AngleInRadians,Parameters = geompyDC.ParseParameters(AngleInRadians)
3859         if flag:
3860             AngleInRadians = DegreesToRadians(AngleInRadians)
3861         if (isinstance( theObject, Mesh )):
3862             theObject = theObject.GetMesh()
3863         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3864             Axis = self.smeshpyD.GetAxisStruct(Axis)
3865         Axis,AxisParameters = ParseAxisStruct(Axis)
3866         Parameters = AxisParameters + ":" + Parameters
3867         mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3868                                                        MakeGroups, NewMeshName)
3869         mesh.SetParameters(Parameters)
3870         return Mesh( self.smeshpyD, self.geompyD, mesh )
3871
3872     ## Finds groups of ajacent nodes within Tolerance.
3873     #  @param Tolerance the value of tolerance
3874     #  @return the list of groups of nodes
3875     #  @ingroup l2_modif_trsf
3876     def FindCoincidentNodes (self, Tolerance):
3877         return self.editor.FindCoincidentNodes(Tolerance)
3878
3879     ## Finds groups of ajacent nodes within Tolerance.
3880     #  @param Tolerance the value of tolerance
3881     #  @param SubMeshOrGroup SubMesh or Group
3882     #  @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3883     #  @return the list of groups of nodes
3884     #  @ingroup l2_modif_trsf
3885     def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3886         if (isinstance( SubMeshOrGroup, Mesh )):
3887             SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3888         if not isinstance( exceptNodes, list):
3889             exceptNodes = [ exceptNodes ]
3890         if exceptNodes and isinstance( exceptNodes[0], int):
3891             exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3892         return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3893
3894     ## Merges nodes
3895     #  @param GroupsOfNodes the list of groups of nodes
3896     #  @ingroup l2_modif_trsf
3897     def MergeNodes (self, GroupsOfNodes):
3898         self.editor.MergeNodes(GroupsOfNodes)
3899
3900     ## Finds the elements built on the same nodes.
3901     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3902     #  @return a list of groups of equal elements
3903     #  @ingroup l2_modif_trsf
3904     def FindEqualElements (self, MeshOrSubMeshOrGroup):
3905         if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3906             MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3907         return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3908
3909     ## Merges elements in each given group.
3910     #  @param GroupsOfElementsID groups of elements for merging
3911     #  @ingroup l2_modif_trsf
3912     def MergeElements(self, GroupsOfElementsID):
3913         self.editor.MergeElements(GroupsOfElementsID)
3914
3915     ## Leaves one element and removes all other elements built on the same nodes.
3916     #  @ingroup l2_modif_trsf
3917     def MergeEqualElements(self):
3918         self.editor.MergeEqualElements()
3919
3920     ## Sews free borders
3921     #  @return SMESH::Sew_Error
3922     #  @ingroup l2_modif_trsf
3923     def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3924                         FirstNodeID2, SecondNodeID2, LastNodeID2,
3925                         CreatePolygons, CreatePolyedrs):
3926         return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3927                                           FirstNodeID2, SecondNodeID2, LastNodeID2,
3928                                           CreatePolygons, CreatePolyedrs)
3929
3930     ## Sews conform free borders
3931     #  @return SMESH::Sew_Error
3932     #  @ingroup l2_modif_trsf
3933     def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3934                                FirstNodeID2, SecondNodeID2):
3935         return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3936                                                  FirstNodeID2, SecondNodeID2)
3937
3938     ## Sews border to side
3939     #  @return SMESH::Sew_Error
3940     #  @ingroup l2_modif_trsf
3941     def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3942                          FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3943         return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3944                                            FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3945
3946     ## Sews two sides of a mesh. The nodes belonging to Side1 are
3947     #  merged with the nodes of elements of Side2.
3948     #  The number of elements in theSide1 and in theSide2 must be
3949     #  equal and they should have similar nodal connectivity.
3950     #  The nodes to merge should belong to side borders and
3951     #  the first node should be linked to the second.
3952     #  @return SMESH::Sew_Error
3953     #  @ingroup l2_modif_trsf
3954     def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3955                          NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3956                          NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3957         return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3958                                            NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3959                                            NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3960
3961     ## Sets new nodes for the given element.
3962     #  @param ide the element id
3963     #  @param newIDs nodes ids
3964     #  @return If the number of nodes does not correspond to the type of element - returns false
3965     #  @ingroup l2_modif_edit
3966     def ChangeElemNodes(self, ide, newIDs):
3967         return self.editor.ChangeElemNodes(ide, newIDs)
3968
3969     ## If during the last operation of MeshEditor some nodes were
3970     #  created, this method returns the list of their IDs, \n
3971     #  if new nodes were not created - returns empty list
3972     #  @return the list of integer values (can be empty)
3973     #  @ingroup l1_auxiliary
3974     def GetLastCreatedNodes(self):
3975         return self.editor.GetLastCreatedNodes()
3976
3977     ## If during the last operation of MeshEditor some elements were
3978     #  created this method returns the list of their IDs, \n
3979     #  if new elements were not created - returns empty list
3980     #  @return the list of integer values (can be empty)
3981     #  @ingroup l1_auxiliary
3982     def GetLastCreatedElems(self):
3983         return self.editor.GetLastCreatedElems()
3984
3985      ## Creates a hole in a mesh by doubling the nodes of some particular elements
3986     #  @param theNodes identifiers of nodes to be doubled
3987     #  @param theModifiedElems identifiers of elements to be updated by the new (doubled) 
3988     #         nodes. If list of element identifiers is empty then nodes are doubled but 
3989     #         they not assigned to elements
3990     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3991     #  @ingroup l2_modif_edit
3992     def DoubleNodes(self, theNodes, theModifiedElems):
3993         return self.editor.DoubleNodes(theNodes, theModifiedElems)
3994         
3995     ## Creates a hole in a mesh by doubling the nodes of some particular elements
3996     #  This method provided for convenience works as DoubleNodes() described above.
3997     #  @param theNodeId identifiers of node to be doubled
3998     #  @param theModifiedElems identifiers of elements to be updated
3999     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4000     #  @ingroup l2_modif_edit
4001     def DoubleNode(self, theNodeId, theModifiedElems):
4002         return self.editor.DoubleNode(theNodeId, theModifiedElems)
4003         
4004     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4005     #  This method provided for convenience works as DoubleNodes() described above.
4006     #  @param theNodes group of nodes to be doubled
4007     #  @param theModifiedElems group of elements to be updated.
4008     #  @param theMakeGroup forces the generation of a group containing new nodes.
4009     #  @return TRUE or a created group if operation has been completed successfully,
4010     #          FALSE or None otherwise
4011     #  @ingroup l2_modif_edit
4012     def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4013         if theMakeGroup:
4014             return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4015         return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4016
4017     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4018     #  This method provided for convenience works as DoubleNodes() described above.
4019     #  @param theNodes list of groups of nodes to be doubled
4020     #  @param theModifiedElems list of groups of elements to be updated.
4021     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4022     #  @ingroup l2_modif_edit
4023     def DoubleNodeGroups(self, theNodes, theModifiedElems):
4024         return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4025     
4026     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4027     #  @param theElems - the list of elements (edges or faces) to be replicated
4028     #         The nodes for duplication could be found from these elements
4029     #  @param theNodesNot - list of nodes to NOT replicate
4030     #  @param theAffectedElems - the list of elements (cells and edges) to which the 
4031     #         replicated nodes should be associated to.
4032     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4033     #  @ingroup l2_modif_edit
4034     def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4035         return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4036         
4037     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4038     #  @param theElems - the list of elements (edges or faces) to be replicated
4039     #         The nodes for duplication could be found from these elements
4040     #  @param theNodesNot - list of nodes to NOT replicate
4041     #  @param theShape - shape to detect affected elements (element which geometric center
4042     #         located on or inside shape).
4043     #         The replicated nodes should be associated to affected elements.
4044     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4045     #  @ingroup l2_modif_edit
4046     def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4047         return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4048     
4049     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4050     #  This method provided for convenience works as DoubleNodes() described above.
4051     #  @param theElems - group of of elements (edges or faces) to be replicated
4052     #  @param theNodesNot - group of nodes not to replicated
4053     #  @param theAffectedElems - group of elements to which the replicated nodes
4054     #         should be associated to.
4055     #  @param theMakeGroup forces the generation of a group containing new elements.
4056     #  @ingroup l2_modif_edit
4057     def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems, theMakeGroup=False):
4058         if theMakeGroup:
4059             return self.editor.DoubleNodeElemGroupNew(theElems, theNodesNot, theAffectedElems)
4060         return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4061
4062     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4063     #  This method provided for convenience works as DoubleNodes() described above.
4064     #  @param theElems - group of of elements (edges or faces) to be replicated
4065     #  @param theNodesNot - group of nodes not to replicated
4066     #  @param theShape - shape to detect affected elements (element which geometric center
4067     #         located on or inside shape).
4068     #         The replicated nodes should be associated to affected elements.
4069     #  @ingroup l2_modif_edit
4070     def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4071         return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4072         
4073     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4074     #  This method provided for convenience works as DoubleNodes() described above.
4075     #  @param theElems - list of groups of elements (edges or faces) to be replicated
4076     #  @param theNodesNot - list of groups of nodes not to replicated
4077     #  @param theAffectedElems - group of elements to which the replicated nodes
4078     #         should be associated to.
4079     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4080     #  @ingroup l2_modif_edit
4081     def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems):
4082         return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4083
4084     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4085     #  This method provided for convenience works as DoubleNodes() described above.
4086     #  @param theElems - list of groups of elements (edges or faces) to be replicated
4087     #  @param theNodesNot - list of groups of nodes not to replicated
4088     #  @param theShape - shape to detect affected elements (element which geometric center
4089     #         located on or inside shape).
4090     #         The replicated nodes should be associated to affected elements.
4091     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4092     #  @ingroup l2_modif_edit
4093     def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4094         return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4095         
4096     ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4097     # The list of groups must describe a partition of the mesh volumes.
4098     # The nodes of the internal faces at the boundaries of the groups are doubled.
4099     # In option, the internal faces are replaced by flat elements.
4100     # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4101     # @param theDomains - list of groups of volumes
4102     # @param createJointElems - if TRUE, create the elements
4103     # @return TRUE if operation has been completed successfully, FALSE otherwise
4104     def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4105        return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4106
4107     def _valueFromFunctor(self, funcType, elemId):
4108         fn = self.smeshpyD.GetFunctor(funcType)
4109         fn.SetMesh(self.mesh)
4110         if fn.GetElementType() == self.GetElementType(elemId, True):
4111             val = fn.GetValue(elemId)
4112         else:
4113             val = 0
4114         return val
4115         
4116     ## Get length of 1D element.
4117     #  @param elemId mesh element ID
4118     #  @return element's length value
4119     #  @ingroup l1_measurements
4120     def GetLength(self, elemId):
4121         return self._valueFromFunctor(SMESH.FT_Length, elemId)    
4122
4123     ## Get area of 2D element.
4124     #  @param elemId mesh element ID
4125     #  @return element's area value
4126     #  @ingroup l1_measurements
4127     def GetArea(self, elemId):
4128         return self._valueFromFunctor(SMESH.FT_Area, elemId)    
4129
4130     ## Get volume of 3D element.
4131     #  @param elemId mesh element ID
4132     #  @return element's volume value
4133     #  @ingroup l1_measurements
4134     def GetVolume(self, elemId):
4135         return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)    
4136
4137     ## Get maximum element length.
4138     #  @param elemId mesh element ID
4139     #  @return element's maximum length value
4140     #  @ingroup l1_measurements
4141     def GetMaxElementLength(self, elemId):
4142         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4143             ftype = SMESH.FT_MaxElementLength3D
4144         else:
4145             ftype = SMESH.FT_MaxElementLength2D
4146         return self._valueFromFunctor(ftype, elemId)    
4147
4148     ## Get aspect ratio of 2D or 3D element.
4149     #  @param elemId mesh element ID
4150     #  @return element's aspect ratio value
4151     #  @ingroup l1_measurements
4152     def GetAspectRatio(self, elemId):
4153         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4154             ftype = SMESH.FT_AspectRatio3D
4155         else:
4156             ftype = SMESH.FT_AspectRatio
4157         return self._valueFromFunctor(ftype, elemId)    
4158
4159     ## Get warping angle of 2D element.
4160     #  @param elemId mesh element ID
4161     #  @return element's warping angle value
4162     #  @ingroup l1_measurements
4163     def GetWarping(self, elemId):
4164         return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4165
4166     ## Get minimum angle of 2D element.
4167     #  @param elemId mesh element ID
4168     #  @return element's minimum angle value
4169     #  @ingroup l1_measurements
4170     def GetMinimumAngle(self, elemId):
4171         return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4172
4173     ## Get taper of 2D element.
4174     #  @param elemId mesh element ID
4175     #  @return element's taper value
4176     #  @ingroup l1_measurements
4177     def GetTaper(self, elemId):
4178         return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4179
4180     ## Get skew of 2D element.
4181     #  @param elemId mesh element ID
4182     #  @return element's skew value
4183     #  @ingroup l1_measurements
4184     def GetSkew(self, elemId):
4185         return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4186
4187 ## The mother class to define algorithm, it is not recommended to use it directly.
4188 #
4189 #  More details.
4190 #  @ingroup l2_algorithms
4191 class Mesh_Algorithm:
4192     #  @class Mesh_Algorithm
4193     #  @brief Class Mesh_Algorithm
4194
4195     #def __init__(self,smesh):
4196     #    self.smesh=smesh
4197     def __init__(self):
4198         self.mesh = None
4199         self.geom = None
4200         self.subm = None
4201         self.algo = None
4202
4203     ## Finds a hypothesis in the study by its type name and parameters.
4204     #  Finds only the hypotheses created in smeshpyD engine.
4205     #  @return SMESH.SMESH_Hypothesis
4206     def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
4207         study = smeshpyD.GetCurrentStudy()
4208         #to do: find component by smeshpyD object, not by its data type
4209         scomp = study.FindComponent(smeshpyD.ComponentDataType())
4210         if scomp is not None:
4211             res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
4212             # Check if the root label of the hypotheses exists
4213             if res and hypRoot is not None:
4214                 iter = study.NewChildIterator(hypRoot)
4215                 # Check all published hypotheses
4216                 while iter.More():
4217                     hypo_so_i = iter.Value()
4218                     attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
4219                     if attr is not None:
4220                         anIOR = attr.Value()
4221                         hypo_o_i = salome.orb.string_to_object(anIOR)
4222                         if hypo_o_i is not None:
4223                             # Check if this is a hypothesis
4224                             hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
4225                             if hypo_i is not None:
4226                                 # Check if the hypothesis belongs to current engine
4227                                 if smeshpyD.GetObjectId(hypo_i) > 0:
4228                                     # Check if this is the required hypothesis
4229                                     if hypo_i.GetName() == hypname:
4230                                         # Check arguments
4231                                         if CompareMethod(hypo_i, args):
4232                                             # found!!!
4233                                             return hypo_i
4234                                         pass
4235                                     pass
4236                                 pass
4237                             pass
4238                         pass
4239                     iter.Next()
4240                     pass
4241                 pass
4242             pass
4243         return None
4244
4245     ## Finds the algorithm in the study by its type name.
4246     #  Finds only the algorithms, which have been created in smeshpyD engine.
4247     #  @return SMESH.SMESH_Algo
4248     def FindAlgorithm (self, algoname, smeshpyD):
4249         study = smeshpyD.GetCurrentStudy()
4250         #to do: find component by smeshpyD object, not by its data type
4251         scomp = study.FindComponent(smeshpyD.ComponentDataType())
4252         if scomp is not None:
4253             res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
4254             # Check if the root label of the algorithms exists
4255             if res and hypRoot is not None:
4256                 iter = study.NewChildIterator(hypRoot)
4257                 # Check all published algorithms
4258                 while iter.More():
4259                     algo_so_i = iter.Value()
4260                     attr = algo_so_i.FindAttribute("AttributeIOR")[1]
4261                     if attr is not None:
4262                         anIOR = attr.Value()
4263                         algo_o_i = salome.orb.string_to_object(anIOR)
4264                         if algo_o_i is not None:
4265                             # Check if this is an algorithm
4266                             algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
4267                             if algo_i is not None:
4268                                 # Checks if the algorithm belongs to the current engine
4269                                 if smeshpyD.GetObjectId(algo_i) > 0:
4270                                     # Check if this is the required algorithm
4271                                     if algo_i.GetName() == algoname:
4272                                         # found!!!
4273                                         return algo_i
4274                                     pass
4275                                 pass
4276                             pass
4277                         pass
4278                     iter.Next()
4279                     pass
4280                 pass
4281             pass
4282         return None
4283
4284     ## If the algorithm is global, returns 0; \n
4285     #  else returns the submesh associated to this algorithm.
4286     def GetSubMesh(self):
4287         return self.subm
4288
4289     ## Returns the wrapped mesher.
4290     def GetAlgorithm(self):
4291         return self.algo
4292
4293     ## Gets the list of hypothesis that can be used with this algorithm
4294     def GetCompatibleHypothesis(self):
4295         mylist = []
4296         if self.algo:
4297             mylist = self.algo.GetCompatibleHypothesis()
4298         return mylist
4299
4300     ## Gets the name of the algorithm
4301     def GetName(self):
4302         GetName(self.algo)
4303
4304     ## Sets the name to the algorithm
4305     def SetName(self, name):
4306         self.mesh.smeshpyD.SetName(self.algo, name)
4307
4308     ## Gets the id of the algorithm
4309     def GetId(self):
4310         return self.algo.GetId()
4311
4312     ## Private method.
4313     def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
4314         if geom is None:
4315             raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
4316         algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
4317         if algo is None:
4318             algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
4319             pass
4320         self.Assign(algo, mesh, geom)
4321         return self.algo
4322
4323     ## Private method
4324     def Assign(self, algo, mesh, geom):
4325         if geom is None:
4326             raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
4327         self.mesh = mesh
4328         piece = mesh.geom
4329         name = ""
4330         if not geom:
4331             self.geom = piece
4332         else:
4333             self.geom = geom
4334             try:
4335                 name = GetName(geom)
4336                 pass
4337             except:
4338                 name = mesh.geompyD.SubShapeName(geom, piece)
4339                 if not name:
4340                     name = "%s_%s"%(geom.GetShapeType(), id(geom%1000))
4341                 pass
4342             self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
4343
4344         self.algo = algo
4345         status = mesh.mesh.AddHypothesis(self.geom, self.algo)
4346         TreatHypoStatus( status, algo.GetName(), name, True )
4347
4348     def CompareHyp (self, hyp, args):
4349         print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
4350         return False
4351
4352     def CompareEqualHyp (self, hyp, args):
4353         return True
4354
4355     ## Private method
4356     def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
4357                     UseExisting=0, CompareMethod=""):
4358         hypo = None
4359         if UseExisting:
4360             if CompareMethod == "": CompareMethod = self.CompareHyp
4361             hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
4362             pass
4363         if hypo is None:
4364             hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
4365             a = ""
4366             s = "="
4367             i = 0
4368             n = len(args)
4369             while i<n:
4370                 a = a + s + str(args[i])
4371                 s = ","
4372                 i = i + 1
4373                 pass
4374             self.mesh.smeshpyD.SetName(hypo, hyp + a)
4375             pass
4376         geomName=""
4377         if self.geom:
4378             geomName = GetName(self.geom)
4379         status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
4380         TreatHypoStatus( status, GetName(hypo), geomName, 0 )
4381         return hypo
4382
4383     ## Returns entry of the shape to mesh in the study
4384     def MainShapeEntry(self):
4385         entry = ""
4386         if not self.mesh or not self.mesh.GetMesh(): return entry
4387         if not self.mesh.GetMesh().HasShapeToMesh(): return entry
4388         study = self.mesh.smeshpyD.GetCurrentStudy()
4389         ior  = salome.orb.object_to_string( self.mesh.GetShape() )
4390         sobj = study.FindObjectIOR(ior)
4391         if sobj: entry = sobj.GetID()
4392         if not entry: return ""
4393         return entry
4394
4395 # Public class: Mesh_Segment
4396 # --------------------------
4397
4398 ## Class to define a segment 1D algorithm for discretization
4399 #
4400 #  More details.
4401 #  @ingroup l3_algos_basic
4402 class Mesh_Segment(Mesh_Algorithm):
4403
4404     ## Private constructor.
4405     def __init__(self, mesh, geom=0):
4406         Mesh_Algorithm.__init__(self)
4407         self.Create(mesh, geom, "Regular_1D")
4408
4409     ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
4410     #  @param l for the length of segments that cut an edge
4411     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
4412     #                    the same parameters, else (default) - creates a new one
4413     #  @param p precision, used for calculation of the number of segments.
4414     #           The precision should be a positive, meaningful value within the range [0,1].
4415     #           In general, the number of segments is calculated with the formula:
4416     #           nb = ceil((edge_length / l) - p)
4417     #           Function ceil rounds its argument to the higher integer.
4418     #           So, p=0 means rounding of (edge_length / l) to the higher integer,
4419     #               p=0.5 means rounding of (edge_length / l) to the nearest integer,
4420     #               p=1 means rounding of (edge_length / l) to the lower integer.
4421     #           Default value is 1e-07.
4422     #  @return an instance of StdMeshers_LocalLength hypothesis
4423     #  @ingroup l3_hypos_1dhyps
4424     def LocalLength(self, l, UseExisting=0, p=1e-07):
4425         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
4426                               CompareMethod=self.CompareLocalLength)
4427         hyp.SetLength(l)
4428         hyp.SetPrecision(p)
4429         return hyp
4430
4431     ## Private method
4432     ## Checks if the given "LocalLength" hypothesis has the same parameters as the given arguments
4433     def CompareLocalLength(self, hyp, args):
4434         if IsEqual(hyp.GetLength(), args[0]):
4435             return IsEqual(hyp.GetPrecision(), args[1])
4436         return False
4437
4438     ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
4439     #  @param length is optional maximal allowed length of segment, if it is omitted
4440     #                the preestimated length is used that depends on geometry size
4441     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4442     #                     the same parameters, else (default) - create a new one
4443     #  @return an instance of StdMeshers_MaxLength hypothesis
4444     #  @ingroup l3_hypos_1dhyps
4445     def MaxSize(self, length=0.0, UseExisting=0):
4446         hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
4447         if length > 0.0:
4448             # set given length
4449             hyp.SetLength(length)
4450         if not UseExisting:
4451             # set preestimated length
4452             gen = self.mesh.smeshpyD
4453             initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
4454                                                        self.mesh.GetMesh(), self.mesh.GetShape(),
4455                                                        False) # <- byMesh
4456             preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
4457             if preHyp:
4458                 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
4459                 pass
4460             pass
4461         hyp.SetUsePreestimatedLength( length == 0.0 )
4462         return hyp
4463         
4464     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
4465     #  @param n for the number of segments that cut an edge
4466     #  @param s for the scale factor (optional)
4467     #  @param reversedEdges is a list of edges to mesh using reversed orientation
4468     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4469     #                     the same parameters, else (default) - create a new one
4470     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
4471     #  @ingroup l3_hypos_1dhyps
4472     def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
4473         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
4474             reversedEdges, UseExisting = [], reversedEdges
4475         entry = self.MainShapeEntry()
4476         if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
4477             reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
4478         if s == []:
4479             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdges, entry],
4480                                   UseExisting=UseExisting,
4481                                   CompareMethod=self.CompareNumberOfSegments)
4482         else:
4483             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdges, entry],
4484                                   UseExisting=UseExisting,
4485                                   CompareMethod=self.CompareNumberOfSegments)
4486             hyp.SetDistrType( 1 )
4487             hyp.SetScaleFactor(s)
4488         hyp.SetNumberOfSegments(n)
4489         hyp.SetReversedEdges( reversedEdges )
4490         hyp.SetObjectEntry( entry )
4491         return hyp
4492
4493     ## Private method
4494     ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
4495     def CompareNumberOfSegments(self, hyp, args):
4496         if hyp.GetNumberOfSegments() == args[0]:
4497             if len(args) == 3:
4498                 if hyp.GetReversedEdges() == args[1]:
4499                     if not args[1] or hyp.GetObjectEntry() == args[2]:
4500                         return True
4501             else:
4502                 if hyp.GetReversedEdges() == args[2]:
4503                     if not args[2] or hyp.GetObjectEntry() == args[3]:
4504                         if hyp.GetDistrType() == 1:
4505                             if IsEqual(hyp.GetScaleFactor(), args[1]):
4506                                 return True
4507         return False
4508
4509     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
4510     #  @param start defines the length of the first segment
4511     #  @param end   defines the length of the last  segment
4512     #  @param reversedEdges is a list of edges to mesh using reversed orientation
4513     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4514     #                     the same parameters, else (default) - creates a new one
4515     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
4516     #  @ingroup l3_hypos_1dhyps
4517     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
4518         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
4519             reversedEdges, UseExisting = [], reversedEdges
4520         if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
4521             reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
4522         entry = self.MainShapeEntry()
4523         hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdges, entry],
4524                               UseExisting=UseExisting,
4525                               CompareMethod=self.CompareArithmetic1D)
4526         hyp.SetStartLength(start)
4527         hyp.SetEndLength(end)
4528         hyp.SetReversedEdges( reversedEdges )
4529         hyp.SetObjectEntry( entry )
4530         return hyp
4531
4532     ## Private method
4533     ## Check if the given "Arithmetic1D" hypothesis has the same parameters as the given arguments
4534     def CompareArithmetic1D(self, hyp, args):
4535         if IsEqual(hyp.GetLength(1), args[0]):
4536             if IsEqual(hyp.GetLength(0), args[1]):
4537                 if hyp.GetReversedEdges() == args[2]:
4538                     if not args[2] or hyp.GetObjectEntry() == args[3]:
4539                         return True
4540         return False
4541
4542
4543     ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
4544     # on curve from 0 to 1 (additionally it is neecessary to check
4545     # orientation of edges and create list of reversed edges if it is
4546     # needed) and sets numbers of segments between given points (default
4547     # values are equals 1
4548     #  @param points defines the list of parameters on curve
4549     #  @param nbSegs defines the list of numbers of segments
4550     #  @param reversedEdges is a list of edges to mesh using reversed orientation
4551     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4552     #                     the same parameters, else (default) - creates a new one
4553     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
4554     #  @ingroup l3_hypos_1dhyps
4555     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
4556         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
4557             reversedEdges, UseExisting = [], reversedEdges
4558         if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
4559             reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
4560         entry = self.MainShapeEntry()
4561         hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdges, entry],
4562                               UseExisting=UseExisting,
4563                               CompareMethod=self.CompareFixedPoints1D)
4564         hyp.SetPoints(points)
4565         hyp.SetNbSegments(nbSegs)
4566         hyp.SetReversedEdges(reversedEdges)
4567         hyp.SetObjectEntry(entry)
4568         return hyp
4569
4570     ## Private method
4571     ## Check if the given "FixedPoints1D" hypothesis has the same parameters
4572     ## as the given arguments
4573     def CompareFixedPoints1D(self, hyp, args):
4574         if hyp.GetPoints() == args[0]:
4575             if hyp.GetNbSegments() == args[1]:
4576                 if hyp.GetReversedEdges() == args[2]:
4577                     if not args[2] or hyp.GetObjectEntry() == args[3]:
4578                         return True
4579         return False
4580
4581
4582
4583     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
4584     #  @param start defines the length of the first segment
4585     #  @param end   defines the length of the last  segment
4586     #  @param reversedEdges is a list of edges to mesh using reversed orientation
4587     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4588     #                     the same parameters, else (default) - creates a new one
4589     #  @return an instance of StdMeshers_StartEndLength hypothesis
4590     #  @ingroup l3_hypos_1dhyps
4591     def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
4592         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
4593             reversedEdges, UseExisting = [], reversedEdges
4594         if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
4595             reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
4596         entry = self.MainShapeEntry()
4597         hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdges, entry],
4598                               UseExisting=UseExisting,
4599                               CompareMethod=self.CompareStartEndLength)
4600         hyp.SetStartLength(start)
4601         hyp.SetEndLength(end)
4602         hyp.SetReversedEdges( reversedEdges )
4603         hyp.SetObjectEntry( entry )
4604         return hyp
4605
4606     ## Check if the given "StartEndLength" hypothesis has the same parameters as the given arguments
4607     def CompareStartEndLength(self, hyp, args):
4608         if IsEqual(hyp.GetLength(1), args[0]):
4609             if IsEqual(hyp.GetLength(0), args[1]):
4610                 if hyp.GetReversedEdges() == args[2]:
4611                     if not args[2] or hyp.GetObjectEntry() == args[3]:
4612                         return True
4613         return False
4614
4615     ## Defines "Deflection1D" hypothesis
4616     #  @param d for the deflection
4617     #  @param UseExisting if ==true - searches for an existing hypothesis created with
4618     #                     the same parameters, else (default) - create a new one
4619     #  @ingroup l3_hypos_1dhyps
4620     def Deflection1D(self, d, UseExisting=0):
4621         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
4622                               CompareMethod=self.CompareDeflection1D)
4623         hyp.SetDeflection(d)
4624         return hyp
4625
4626     ## Check if the given "Deflection1D" hypothesis has the same parameters as the given arguments
4627     def CompareDeflection1D(self, hyp, args):
4628         return IsEqual(hyp.GetDeflection(), args[0])
4629
4630     ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
4631     #  the opposite side in case of quadrangular faces
4632     #  @ingroup l3_hypos_additi
4633     def Propagation(self):
4634         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
4635
4636     ## Defines "AutomaticLength" hypothesis
4637     #  @param fineness for the fineness [0-1]
4638     #  @param UseExisting if ==true - searches for an existing hypothesis created with the
4639     #                     same parameters, else (default) - create a new one
4640     #  @ingroup l3_hypos_1dhyps
4641     def AutomaticLength(self, fineness=0, UseExisting=0):
4642         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
4643                               CompareMethod=self.CompareAutomaticLength)
4644         hyp.SetFineness( fineness )
4645         return hyp
4646
4647     ## Checks if the given "AutomaticLength" hypothesis has the same parameters as the given arguments
4648     def CompareAutomaticLength(self, hyp, args):
4649         return IsEqual(hyp.GetFineness(), args[0])
4650
4651     ## Defines "SegmentLengthAroundVertex" hypothesis
4652     #  @param length for the segment length
4653     #  @param vertex for the length localization: the vertex index [0,1] | vertex object.
4654     #         Any other integer value means that the hypothesis will be set on the
4655     #         whole 1D shape, where Mesh_Segment algorithm is assigned.
4656     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
4657     #                   the same parameters, else (default) - creates a new one
4658     #  @ingroup l3_algos_segmarv
4659     def LengthNearVertex(self, length, vertex=0, UseExisting=0):
4660         import types
4661         store_geom = self.geom
4662         if type(vertex) is types.IntType:
4663             if vertex == 0 or vertex == 1:
4664                 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geompyDC.ShapeType["VERTEX"],True)[vertex]
4665                 self.geom = vertex
4666                 pass
4667             pass
4668         else:
4669             self.geom = vertex
4670             pass
4671         ### 0D algorithm
4672         if self.geom is None:
4673             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
4674         try:
4675             name = GetName(self.geom)
4676             pass
4677         except:
4678             piece = self.mesh.geom
4679             name = self.mesh.geompyD.SubShapeName(self.geom, piece)
4680             self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
4681             pass
4682         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
4683         if algo is None:
4684             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
4685             pass
4686         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
4687         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
4688         ###
4689         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
4690                               CompareMethod=self.CompareLengthNearVertex)
4691         self.geom = store_geom
4692         hyp.SetLength( length )
4693         return hyp
4694
4695     ## Checks if the given "LengthNearVertex" hypothesis has the same parameters as the given arguments
4696     #  @ingroup l3_algos_segmarv
4697     def CompareLengthNearVertex(self, hyp, args):
4698         return IsEqual(hyp.GetLength(), args[0])
4699
4700     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
4701     #  If the 2D mesher sees that all boundary edges are quadratic,
4702     #  it generates quadratic faces, else it generates linear faces using
4703     #  medium nodes as if they are vertices.
4704     #  The 3D mesher generates quadratic volumes only if all boundary faces
4705     #  are quadratic, else it fails.
4706     #
4707     #  @ingroup l3_hypos_additi
4708     def QuadraticMesh(self):
4709         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
4710         return hyp
4711
4712 # Public class: Mesh_CompositeSegment
4713 # --------------------------
4714
4715 ## Defines a segment 1D algorithm for discretization
4716 #
4717 #  @ingroup l3_algos_basic
4718 class Mesh_CompositeSegment(Mesh_Segment):
4719
4720     ## Private constructor.
4721     def __init__(self, mesh, geom=0):
4722         self.Create(mesh, geom, "CompositeSegment_1D")
4723
4724
4725 # Public class: Mesh_Segment_Python
4726 # ---------------------------------
4727
4728 ## Defines a segment 1D algorithm for discretization with python function
4729 #
4730 #  @ingroup l3_algos_basic
4731 class Mesh_Segment_Python(Mesh_Segment):
4732
4733     ## Private constructor.
4734     def __init__(self, mesh, geom=0):
4735         import Python1dPlugin
4736         self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
4737
4738     ## Defines "PythonSplit1D" hypothesis
4739     #  @param n for the number of segments that cut an edge
4740     #  @param func for the python function that calculates the length of all segments
4741     #  @param UseExisting if ==true - searches for the existing hypothesis created with
4742     #                     the same parameters, else (default) - creates a new one
4743     #  @ingroup l3_hypos_1dhyps
4744     def PythonSplit1D(self, n, func, UseExisting=0):
4745         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
4746                               UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
4747         hyp.SetNumberOfSegments(n)
4748         hyp.SetPythonLog10RatioFunction(func)
4749         return hyp
4750
4751     ## Checks if the given "PythonSplit1D" hypothesis has the same parameters as the given arguments
4752     def ComparePythonSplit1D(self, hyp, args):
4753         #if hyp.GetNumberOfSegments() == args[0]:
4754         #    if hyp.GetPythonLog10RatioFunction() == args[1]:
4755         #        return True
4756         return False
4757
4758 # Public class: Mesh_Triangle
4759 # ---------------------------
4760
4761 ## Defines a triangle 2D algorithm
4762 #
4763 #  @ingroup l3_algos_basic
4764 class Mesh_Triangle(Mesh_Algorithm):
4765
4766     # default values
4767     algoType = 0
4768     params = 0
4769
4770     _angleMeshS = 8
4771     _gradation  = 1.1
4772
4773     ## Private constructor.
4774     def __init__(self, mesh, algoType, geom=0):
4775         Mesh_Algorithm.__init__(self)
4776
4777         self.algoType = algoType
4778         if algoType == MEFISTO:
4779             self.Create(mesh, geom, "MEFISTO_2D")
4780             pass
4781         elif algoType == BLSURF:
4782             CheckPlugin(BLSURF)
4783             self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
4784             #self.SetPhysicalMesh() - PAL19680
4785         elif algoType == NETGEN:
4786             CheckPlugin(NETGEN)
4787             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
4788             pass
4789         elif algoType == NETGEN_2D:
4790             CheckPlugin(NETGEN)
4791             self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
4792             pass
4793
4794     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
4795     #  @param area for the maximum area of each triangle
4796     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
4797     #                     same parameters, else (default) - creates a new one
4798     #
4799     #  Only for algoType == MEFISTO || NETGEN_2D
4800     #  @ingroup l3_hypos_2dhyps
4801     def MaxElementArea(self, area, UseExisting=0):
4802         if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
4803             hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
4804                                   CompareMethod=self.CompareMaxElementArea)
4805         elif self.algoType == NETGEN:
4806             hyp = self.Parameters(SIMPLE)
4807         hyp.SetMaxElementArea(area)
4808         return hyp
4809
4810     ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
4811     def CompareMaxElementArea(self, hyp, args):
4812         return IsEqual(hyp.GetMaxElementArea(), args[0])
4813
4814     ## Defines "LengthFromEdges" hypothesis to build triangles
4815     #  based on the length of the edges taken from the wire
4816     #
4817     #  Only for algoType == MEFISTO || NETGEN_2D
4818     #  @ingroup l3_hypos_2dhyps
4819     def LengthFromEdges(self):
4820         if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
4821             hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
4822             return hyp
4823         elif self.algoType == NETGEN:
4824             hyp = self.Parameters(SIMPLE)
4825             hyp.LengthFromEdges()
4826             return hyp
4827
4828     ## Sets a way to define size of mesh elements to generate.
4829     #  @param thePhysicalMesh is: DefaultSize or Custom.
4830     #  @ingroup l3_hypos_blsurf
4831     def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
4832         # Parameter of BLSURF algo
4833         self.Parameters().SetPhysicalMesh(thePhysicalMesh)
4834
4835     ## Sets size of mesh elements to generate.
4836     #  @ingroup l3_hypos_blsurf
4837     def SetPhySize(self, theVal):
4838         # Parameter of BLSURF algo
4839         self.SetPhysicalMesh(1) #Custom - else why to set the size?
4840         self.Parameters().SetPhySize(theVal)
4841
4842     ## Sets lower boundary of mesh element size (PhySize).
4843     #  @ingroup l3_hypos_blsurf
4844     def SetPhyMin(self, theVal=-1):
4845         #  Parameter of BLSURF algo
4846         self.Parameters().SetPhyMin(theVal)
4847
4848     ## Sets upper boundary of mesh element size (PhySize).
4849     #  @ingroup l3_hypos_blsurf
4850     def SetPhyMax(self, theVal=-1):
4851         #  Parameter of BLSURF algo
4852         self.Parameters().SetPhyMax(theVal)
4853
4854     ## Sets a way to define maximum angular deflection of mesh from CAD model.
4855     #  @param theGeometricMesh is: 0 (None) or 1 (Custom)
4856     #  @ingroup l3_hypos_blsurf
4857     def SetGeometricMesh(self, theGeometricMesh=0):
4858         #  Parameter of BLSURF algo
4859         if self.Parameters().GetPhysicalMesh() == 0: theGeometricMesh = 1
4860         self.params.SetGeometricMesh(theGeometricMesh)
4861
4862     ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
4863     #  @ingroup l3_hypos_blsurf
4864     def SetAngleMeshS(self, theVal=_angleMeshS):
4865         #  Parameter of BLSURF algo
4866         if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
4867         self.params.SetAngleMeshS(theVal)
4868
4869     ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
4870     #  @ingroup l3_hypos_blsurf
4871     def SetAngleMeshC(self, theVal=_angleMeshS):
4872         #  Parameter of BLSURF algo
4873         if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
4874         self.params.SetAngleMeshC(theVal)
4875
4876     ## Sets lower boundary of mesh element size computed to respect angular deflection.
4877     #  @ingroup l3_hypos_blsurf
4878     def SetGeoMin(self, theVal=-1):
4879         #  Parameter of BLSURF algo
4880         self.Parameters().SetGeoMin(theVal)
4881
4882     ## Sets upper boundary of mesh element size computed to respect angular deflection.
4883     #  @ingroup l3_hypos_blsurf
4884     def SetGeoMax(self, theVal=-1):
4885         #  Parameter of BLSURF algo
4886         self.Parameters().SetGeoMax(theVal)
4887
4888     ## Sets maximal allowed ratio between the lengths of two adjacent edges.
4889     #  @ingroup l3_hypos_blsurf
4890     def SetGradation(self, theVal=_gradation):
4891         #  Parameter of BLSURF algo
4892         if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
4893         self.params.SetGradation(theVal)
4894
4895     ## Sets topology usage way.
4896     # @param way defines how mesh conformity is assured <ul>
4897     # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
4898     # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model</li></ul>
4899     #  @ingroup l3_hypos_blsurf
4900     def SetTopology(self, way):
4901         #  Parameter of BLSURF algo
4902         self.Parameters().SetTopology(way)
4903
4904     ## To respect geometrical edges or not.
4905     #  @ingroup l3_hypos_blsurf
4906     def SetDecimesh(self, toIgnoreEdges=False):
4907         #  Parameter of BLSURF algo
4908         self.Parameters().SetDecimesh(toIgnoreEdges)
4909
4910     ## Sets verbosity level in the range 0 to 100.
4911     #  @ingroup l3_hypos_blsurf
4912     def SetVerbosity(self, level):
4913         #  Parameter of BLSURF algo
4914         self.Parameters().SetVerbosity(level)
4915
4916     ## Sets advanced option value.
4917     #  @ingroup l3_hypos_blsurf
4918     def SetOptionValue(self, optionName, level):
4919         #  Parameter of BLSURF algo
4920         self.Parameters().SetOptionValue(optionName,level)
4921
4922     ## Sets QuadAllowed flag.
4923     #  Only for algoType == NETGEN(NETGEN_1D2D) || NETGEN_2D || BLSURF
4924     #  @ingroup l3_hypos_netgen l3_hypos_blsurf
4925     def SetQuadAllowed(self, toAllow=True):
4926         if self.algoType == NETGEN_2D:
4927             if not self.params:
4928                 # use simple hyps
4929                 hasSimpleHyps = False
4930                 simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
4931                 for hyp in self.mesh.GetHypothesisList( self.geom ):
4932                     if hyp.GetName() in simpleHyps:
4933                         hasSimpleHyps = True
4934                         if hyp.GetName() == "QuadranglePreference":
4935                             if not toAllow: # remove QuadranglePreference
4936                                 self.mesh.RemoveHypothesis( self.geom, hyp )
4937                                 pass
4938                             return
4939                         pass
4940                     pass
4941                 if hasSimpleHyps:
4942                     if toAllow: # add QuadranglePreference
4943                         self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
4944                         pass
4945                     return
4946                 pass
4947             pass
4948         if self.Parameters():
4949             self.params.SetQuadAllowed(toAllow)
4950             return
4951
4952     ## Defines hypothesis having several parameters
4953     #
4954     #  @ingroup l3_hypos_netgen
4955     def Parameters(self, which=SOLE):
4956         if not self.params:
4957             if self.algoType == NETGEN:
4958                 if which == SIMPLE:
4959                     self.params = self.Hypothesis("NETGEN_SimpleParameters_2D", [],
4960                                                   "libNETGENEngine.so", UseExisting=0)
4961                 else:
4962                     self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
4963                                                   "libNETGENEngine.so", UseExisting=0)
4964             elif self.algoType == MEFISTO:
4965                 print "Mefisto algo support no multi-parameter hypothesis"
4966             elif self.algoType == NETGEN_2D:
4967                 self.params = self.Hypothesis("NETGEN_Parameters_2D_ONLY", [],
4968                                               "libNETGENEngine.so", UseExisting=0)
4969             elif self.algoType == BLSURF:
4970                 self.params = self.Hypothesis("BLSURF_Parameters", [],
4971                                               "libBLSURFEngine.so", UseExisting=0)
4972             else:
4973                 print "Mesh_Triangle with algo type %s does not have such a parameter, check algo type"%self.algoType
4974         return self.params
4975
4976     ## Sets MaxSize
4977     #
4978     #  Only for algoType == NETGEN
4979     #  @ingroup l3_hypos_netgen
4980     def SetMaxSize(self, theSize):
4981         if self.Parameters():
4982             self.params.SetMaxSize(theSize)
4983
4984     ## Sets SecondOrder flag
4985     #
4986     #  Only for algoType == NETGEN
4987     #  @ingroup l3_hypos_netgen
4988     def SetSecondOrder(self, theVal):
4989         if self.Parameters():
4990             self.params.SetSecondOrder(theVal)
4991
4992     ## Sets Optimize flag
4993     #
4994     #  Only for algoType == NETGEN
4995     #  @ingroup l3_hypos_netgen
4996     def SetOptimize(self, theVal):
4997         if self.Parameters():
4998             self.params.SetOptimize(theVal)
4999
5000     ## Sets Fineness
5001     #  @param theFineness is:
5002     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
5003     #
5004     #  Only for algoType == NETGEN
5005     #  @ingroup l3_hypos_netgen
5006     def SetFineness(self, theFineness):
5007         if self.Parameters():
5008             self.params.SetFineness(theFineness)
5009
5010     ## Sets GrowthRate
5011     #
5012     #  Only for algoType == NETGEN
5013     #  @ingroup l3_hypos_netgen
5014     def SetGrowthRate(self, theRate):
5015         if self.Parameters():
5016             self.params.SetGrowthRate(theRate)
5017
5018     ## Sets NbSegPerEdge
5019     #
5020     #  Only for algoType == NETGEN
5021     #  @ingroup l3_hypos_netgen
5022     def SetNbSegPerEdge(self, theVal):
5023         if self.Parameters():
5024             self.params.SetNbSegPerEdge(theVal)
5025
5026     ## Sets NbSegPerRadius
5027     #
5028     #  Only for algoType == NETGEN
5029     #  @ingroup l3_hypos_netgen
5030     def SetNbSegPerRadius(self, theVal):
5031         if self.Parameters():
5032             self.params.SetNbSegPerRadius(theVal)
5033
5034     ## Sets number of segments overriding value set by SetLocalLength()
5035     #
5036     #  Only for algoType == NETGEN
5037     #  @ingroup l3_hypos_netgen
5038     def SetNumberOfSegments(self, theVal):
5039         self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
5040
5041     ## Sets number of segments overriding value set by SetNumberOfSegments()
5042     #
5043     #  Only for algoType == NETGEN
5044     #  @ingroup l3_hypos_netgen
5045     def SetLocalLength(self, theVal):
5046         self.Parameters(SIMPLE).SetLocalLength(theVal)
5047
5048     pass
5049
5050
5051 # Public class: Mesh_Quadrangle
5052 # -----------------------------
5053
5054 ## Defines a quadrangle 2D algorithm
5055 #
5056 #  @ingroup l3_algos_basic
5057 class Mesh_Quadrangle(Mesh_Algorithm):
5058
5059     params=0
5060
5061     ## Private constructor.
5062     def __init__(self, mesh, geom=0):
5063         Mesh_Algorithm.__init__(self)
5064         self.Create(mesh, geom, "Quadrangle_2D")
5065         return
5066
5067     ## Defines "QuadrangleParameters" hypothesis
5068     #  @param quadType defines the algorithm of transition between differently descretized
5069     #                  sides of a geometrical face:
5070     #  - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
5071     #                    area along the finer meshed sides. 
5072     #  - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
5073     #                    finer meshed sides.
5074     #  - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
5075     #                    the finer meshed sides, iff the total quantity of segments on
5076     #                    all four sides of the face is even (divisible by 2).
5077     #  - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
5078     #                    area is located along the coarser meshed sides. 
5079     #  - QUAD_REDUCED - only quadrangles are built and the transition between the sides
5080     #                    is made gradually, layer by layer. This type has a limitation on
5081     #                    the number of segments: one pair of opposite sides must have the
5082     #                    same number of segments, the other pair must have an even difference
5083     #                    between the numbers of segments on the sides.
5084     #  @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
5085     #                  will be created while other elements will be quadrangles.
5086     #                  Vertex can be either a GEOM_Object or a vertex ID within the
5087     #                  shape to mesh
5088     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
5089     #                  the same parameters, else (default) - creates a new one
5090     #  @ingroup l3_hypos_quad
5091     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0, UseExisting=0):
5092         vertexID = triangleVertex
5093         if isinstance( triangleVertex, geompyDC.GEOM._objref_GEOM_Object ):
5094             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
5095         if not self.params:
5096             compFun = lambda hyp,args: \
5097                       hyp.GetQuadType() == args[0] and \
5098                       ( hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1))
5099             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID],
5100                                           UseExisting = UseExisting, CompareMethod=compFun)
5101             pass
5102         if self.params.GetQuadType() != quadType:
5103             self.params.SetQuadType(quadType)
5104         if vertexID > 0:
5105             self.params.SetTriaVertex( vertexID )
5106         return self.params
5107
5108     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
5109     #   quadrangles are built in the transition area along the finer meshed sides,
5110     #   iff the total quantity of segments on all four sides of the face is even.
5111     #  @param reversed if True, transition area is located along the coarser meshed sides.
5112     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
5113     #                  the same parameters, else (default) - creates a new one
5114     #  @ingroup l3_hypos_quad
5115     def QuadranglePreference(self, reversed=False, UseExisting=0):
5116         if reversed:
5117             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
5118         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
5119
5120     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
5121     #   triangles are built in the transition area along the finer meshed sides.
5122     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
5123     #                  the same parameters, else (default) - creates a new one
5124     #  @ingroup l3_hypos_quad
5125     def TrianglePreference(self, UseExisting=0):
5126         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
5127
5128     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
5129     #   quadrangles are built and the transition between the sides is made gradually,
5130     #   layer by layer. This type has a limitation on the number of segments: one pair
5131     #   of opposite sides must have the same number of segments, the other pair must
5132     #   have an even difference between the numbers of segments on the sides.
5133     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
5134     #                  the same parameters, else (default) - creates a new one
5135     #  @ingroup l3_hypos_quad
5136     def Reduced(self, UseExisting=0):
5137         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
5138
5139     ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
5140     #  @param vertex: vertex of a trilateral geometrical face, around which triangles
5141     #                 will be created while other elements will be quadrangles.
5142     #                 Vertex can be either a GEOM_Object or a vertex ID within the
5143     #                 shape to mesh
5144     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
5145     #                   the same parameters, else (default) - creates a new one
5146     #  @ingroup l3_hypos_quad
5147     def TriangleVertex(self, vertex, UseExisting=0):
5148         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
5149
5150
5151 # Public class: Mesh_Tetrahedron
5152 # ------------------------------
5153
5154 ## Defines a tetrahedron 3D algorithm
5155 #
5156 #  @ingroup l3_algos_basic
5157 class Mesh_Tetrahedron(Mesh_Algorithm):
5158
5159     params = 0
5160     algoType = 0
5161
5162     ## Private constructor.
5163     def __init__(self, mesh, algoType, geom=0):
5164         Mesh_Algorithm.__init__(self)
5165
5166         if algoType == NETGEN:
5167             CheckPlugin(NETGEN)
5168             self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
5169             pass
5170
5171         elif algoType == FULL_NETGEN:
5172             CheckPlugin(NETGEN)
5173             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
5174             pass
5175
5176         elif algoType == GHS3D:
5177             CheckPlugin(GHS3D)
5178             self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
5179             pass
5180
5181         elif algoType == GHS3DPRL:
5182             CheckPlugin(GHS3DPRL)
5183             self.Create(mesh, geom, "GHS3DPRL_3D" , "libGHS3DPRLEngine.so")
5184             pass
5185
5186         self.algoType = algoType
5187
5188     ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
5189     #  @param vol for the maximum volume of each tetrahedron
5190     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5191     #                   the same parameters, else (default) - creates a new one
5192     #  @ingroup l3_hypos_maxvol
5193     def MaxElementVolume(self, vol, UseExisting=0):
5194         if self.algoType == NETGEN:
5195             hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
5196                                   CompareMethod=self.CompareMaxElementVolume)
5197             hyp.SetMaxElementVolume(vol)
5198             return hyp
5199         elif self.algoType == FULL_NETGEN:
5200             self.Parameters(SIMPLE).SetMaxElementVolume(vol)
5201         return None
5202
5203     ## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
5204     def CompareMaxElementVolume(self, hyp, args):
5205         return IsEqual(hyp.GetMaxElementVolume(), args[0])
5206
5207     ## Defines hypothesis having several parameters
5208     #
5209     #  @ingroup l3_hypos_netgen
5210     def Parameters(self, which=SOLE):
5211         if not self.params:
5212
5213             if self.algoType == FULL_NETGEN:
5214                 if which == SIMPLE:
5215                     self.params = self.Hypothesis("NETGEN_SimpleParameters_3D", [],
5216                                                   "libNETGENEngine.so", UseExisting=0)
5217                 else:
5218                     self.params = self.Hypothesis("NETGEN_Parameters", [],
5219                                                   "libNETGENEngine.so", UseExisting=0)
5220
5221             if self.algoType == NETGEN:
5222                 self.params = self.Hypothesis("NETGEN_Parameters_3D", [],
5223                                               "libNETGENEngine.so", UseExisting=0)
5224
5225             elif self.algoType == GHS3D:
5226                 self.params = self.Hypothesis("GHS3D_Parameters", [],
5227                                               "libGHS3DEngine.so", UseExisting=0)
5228
5229             elif self.algoType == GHS3DPRL:
5230                 self.params = self.Hypothesis("GHS3DPRL_Parameters", [],
5231                                               "libGHS3DPRLEngine.so", UseExisting=0)
5232             else:
5233                 print "Algo supports no multi-parameter hypothesis"
5234
5235         return self.params
5236
5237     ## Sets MaxSize
5238     #  Parameter of FULL_NETGEN and NETGEN
5239     #  @ingroup l3_hypos_netgen
5240     def SetMaxSize(self, theSize):
5241         self.Parameters().SetMaxSize(theSize)
5242
5243     ## Sets SecondOrder flag
5244     #  Parameter of FULL_NETGEN
5245     #  @ingroup l3_hypos_netgen
5246     def SetSecondOrder(self, theVal):
5247         self.Parameters().SetSecondOrder(theVal)
5248
5249     ## Sets Optimize flag
5250     #  Parameter of FULL_NETGEN and NETGEN
5251     #  @ingroup l3_hypos_netgen
5252     def SetOptimize(self, theVal):
5253         self.Parameters().SetOptimize(theVal)
5254
5255     ## Sets Fineness
5256     #  @param theFineness is:
5257     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
5258     #  Parameter of FULL_NETGEN
5259     #  @ingroup l3_hypos_netgen
5260     def SetFineness(self, theFineness):
5261         self.Parameters().SetFineness(theFineness)
5262
5263     ## Sets GrowthRate
5264     #  Parameter of FULL_NETGEN
5265     #  @ingroup l3_hypos_netgen
5266     def SetGrowthRate(self, theRate):
5267         self.Parameters().SetGrowthRate(theRate)
5268
5269     ## Sets NbSegPerEdge
5270     #  Parameter of FULL_NETGEN
5271     #  @ingroup l3_hypos_netgen
5272     def SetNbSegPerEdge(self, theVal):
5273         self.Parameters().SetNbSegPerEdge(theVal)
5274
5275     ## Sets NbSegPerRadius
5276     #  Parameter of FULL_NETGEN
5277     #  @ingroup l3_hypos_netgen
5278     def SetNbSegPerRadius(self, theVal):
5279         self.Parameters().SetNbSegPerRadius(theVal)
5280
5281     ## Sets number of segments overriding value set by SetLocalLength()
5282     #  Only for algoType == NETGEN_FULL
5283     #  @ingroup l3_hypos_netgen
5284     def SetNumberOfSegments(self, theVal):
5285         self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
5286
5287     ## Sets number of segments overriding value set by SetNumberOfSegments()
5288     #  Only for algoType == NETGEN_FULL
5289     #  @ingroup l3_hypos_netgen
5290     def SetLocalLength(self, theVal):
5291         self.Parameters(SIMPLE).SetLocalLength(theVal)
5292
5293     ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis.
5294     #  Overrides value set by LengthFromEdges()
5295     #  Only for algoType == NETGEN_FULL
5296     #  @ingroup l3_hypos_netgen
5297     def MaxElementArea(self, area):
5298         self.Parameters(SIMPLE).SetMaxElementArea(area)
5299
5300     ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis
5301     #  Overrides value set by MaxElementArea()
5302     #  Only for algoType == NETGEN_FULL
5303     #  @ingroup l3_hypos_netgen
5304     def LengthFromEdges(self):
5305         self.Parameters(SIMPLE).LengthFromEdges()
5306
5307     ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis
5308     #  Overrides value set by MaxElementVolume()
5309     #  Only for algoType == NETGEN_FULL
5310     #  @ingroup l3_hypos_netgen
5311     def LengthFromFaces(self):
5312         self.Parameters(SIMPLE).LengthFromFaces()
5313
5314     ## To mesh "holes" in a solid or not. Default is to mesh.
5315     #  @ingroup l3_hypos_ghs3dh
5316     def SetToMeshHoles(self, toMesh):
5317         #  Parameter of GHS3D
5318         self.Parameters().SetToMeshHoles(toMesh)
5319
5320     ## Set Optimization level:
5321     #   None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization,
5322     #   Strong_Optimization.
5323     # Default is Standard_Optimization
5324     #  @ingroup l3_hypos_ghs3dh
5325     def SetOptimizationLevel(self, level):
5326         #  Parameter of GHS3D
5327         self.Parameters().SetOptimizationLevel(level)
5328
5329     ## Maximal size of memory to be used by the algorithm (in Megabytes).
5330     #  @ingroup l3_hypos_ghs3dh
5331     def SetMaximumMemory(self, MB):
5332         #  Advanced parameter of GHS3D
5333         self.Parameters().SetMaximumMemory(MB)
5334
5335     ## Initial size of memory to be used by the algorithm (in Megabytes) in
5336     #  automatic memory adjustment mode.
5337     #  @ingroup l3_hypos_ghs3dh
5338     def SetInitialMemory(self, MB):
5339         #  Advanced parameter of GHS3D
5340         self.Parameters().SetInitialMemory(MB)
5341
5342     ## Path to working directory.
5343     #  @ingroup l3_hypos_ghs3dh
5344     def SetWorkingDirectory(self, path):
5345         #  Advanced parameter of GHS3D
5346         self.Parameters().SetWorkingDirectory(path)
5347
5348     ## To keep working files or remove them. Log file remains in case of errors anyway.
5349     #  @ingroup l3_hypos_ghs3dh
5350     def SetKeepFiles(self, toKeep):
5351         #  Advanced parameter of GHS3D and GHS3DPRL
5352         self.Parameters().SetKeepFiles(toKeep)
5353
5354     ## To set verbose level [0-10]. <ul>
5355     #<li> 0 - no standard output,
5356     #<li> 2 - prints the data, quality statistics of the skin and final meshes and
5357     #     indicates when the final mesh is being saved. In addition the software
5358     #     gives indication regarding the CPU time.
5359     #<li>10 - same as 2 plus the main steps in the computation, quality statistics
5360     #     histogram of the skin mesh, quality statistics histogram together with
5361     #     the characteristics of the final mesh.</ul>
5362     #  @ingroup l3_hypos_ghs3dh
5363     def SetVerboseLevel(self, level):
5364         #  Advanced parameter of GHS3D
5365         self.Parameters().SetVerboseLevel(level)
5366
5367     ## To create new nodes.
5368     #  @ingroup l3_hypos_ghs3dh
5369     def SetToCreateNewNodes(self, toCreate):
5370         #  Advanced parameter of GHS3D
5371         self.Parameters().SetToCreateNewNodes(toCreate)
5372
5373     ## To use boundary recovery version which tries to create mesh on a very poor
5374     #  quality surface mesh.
5375     #  @ingroup l3_hypos_ghs3dh
5376     def SetToUseBoundaryRecoveryVersion(self, toUse):
5377         #  Advanced parameter of GHS3D
5378         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
5379
5380     ## Sets command line option as text.
5381     #  @ingroup l3_hypos_ghs3dh
5382     def SetTextOption(self, option):
5383         #  Advanced parameter of GHS3D
5384         self.Parameters().SetTextOption(option)
5385
5386     ## Sets MED files name and path.
5387     def SetMEDName(self, value):
5388         self.Parameters().SetMEDName(value)
5389
5390     ## Sets the number of partition of the initial mesh
5391     def SetNbPart(self, value):
5392         self.Parameters().SetNbPart(value)
5393
5394     ## When big mesh, start tepal in background
5395     def SetBackground(self, value):
5396         self.Parameters().SetBackground(value)
5397
5398 # Public class: Mesh_Hexahedron
5399 # ------------------------------
5400
5401 ## Defines a hexahedron 3D algorithm
5402 #
5403 #  @ingroup l3_algos_basic
5404 class Mesh_Hexahedron(Mesh_Algorithm):
5405
5406     params = 0
5407     algoType = 0
5408
5409     ## Private constructor.
5410     def __init__(self, mesh, algoType=Hexa, geom=0):
5411         Mesh_Algorithm.__init__(self)
5412
5413         self.algoType = algoType
5414
5415         if algoType == Hexa:
5416             self.Create(mesh, geom, "Hexa_3D")
5417             pass
5418
5419         elif algoType == Hexotic:
5420             CheckPlugin(Hexotic)
5421             self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
5422             pass
5423
5424     ## Defines "MinMaxQuad" hypothesis to give three hexotic parameters
5425     #  @ingroup l3_hypos_hexotic
5426     def MinMaxQuad(self, min=3, max=8, quad=True):
5427         self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
5428                                       UseExisting=0)
5429         self.params.SetHexesMinLevel(min)
5430         self.params.SetHexesMaxLevel(max)
5431         self.params.SetHexoticQuadrangles(quad)
5432         return self.params
5433
5434 # Deprecated, only for compatibility!
5435 # Public class: Mesh_Netgen
5436 # ------------------------------
5437
5438 ## Defines a NETGEN-based 2D or 3D algorithm
5439 #  that needs no discrete boundary (i.e. independent)
5440 #
5441 #  This class is deprecated, only for compatibility!
5442 #
5443 #  More details.
5444 #  @ingroup l3_algos_basic
5445 class Mesh_Netgen(Mesh_Algorithm):
5446
5447     is3D = 0
5448
5449     ## Private constructor.
5450     def __init__(self, mesh, is3D, geom=0):
5451         Mesh_Algorithm.__init__(self)
5452
5453         CheckPlugin(NETGEN)
5454
5455         self.is3D = is3D
5456         if is3D:
5457             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
5458             pass
5459
5460         else:
5461             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
5462             pass
5463
5464     ## Defines the hypothesis containing parameters of the algorithm
5465     def Parameters(self):
5466         if self.is3D:
5467             hyp = self.Hypothesis("NETGEN_Parameters", [],
5468                                   "libNETGENEngine.so", UseExisting=0)
5469         else:
5470             hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
5471                                   "libNETGENEngine.so", UseExisting=0)
5472         return hyp
5473
5474 # Public class: Mesh_Projection1D
5475 # ------------------------------
5476
5477 ## Defines a projection 1D algorithm
5478 #  @ingroup l3_algos_proj
5479 #
5480 class Mesh_Projection1D(Mesh_Algorithm):
5481
5482     ## Private constructor.
5483     def __init__(self, mesh, geom=0):
5484         Mesh_Algorithm.__init__(self)
5485         self.Create(mesh, geom, "Projection_1D")
5486
5487     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
5488     #  a mesh pattern is taken, and, optionally, the association of vertices
5489     #  between the source edge and a target edge (to which a hypothesis is assigned)
5490     #  @param edge from which nodes distribution is taken
5491     #  @param mesh from which nodes distribution is taken (optional)
5492     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
5493     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
5494     #  to associate with \a srcV (optional)
5495     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5496     #                     the same parameters, else (default) - creates a new one
5497     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
5498         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
5499                               UseExisting=0)
5500                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
5501         hyp.SetSourceEdge( edge )
5502         if not mesh is None and isinstance(mesh, Mesh):
5503             mesh = mesh.GetMesh()
5504         hyp.SetSourceMesh( mesh )
5505         hyp.SetVertexAssociation( srcV, tgtV )
5506         return hyp
5507
5508     ## Checks if the given "SourceEdge" hypothesis has the same parameters as the given arguments
5509     #def CompareSourceEdge(self, hyp, args):
5510     #    # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
5511     #    return False
5512
5513
5514 # Public class: Mesh_Projection2D
5515 # ------------------------------
5516
5517 ## Defines a projection 2D algorithm
5518 #  @ingroup l3_algos_proj
5519 #
5520 class Mesh_Projection2D(Mesh_Algorithm):
5521
5522     ## Private constructor.
5523     def __init__(self, mesh, geom=0):
5524         Mesh_Algorithm.__init__(self)
5525         self.Create(mesh, geom, "Projection_2D")
5526
5527     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
5528     #  a mesh pattern is taken, and, optionally, the association of vertices
5529     #  between the source face and the target face (to which a hypothesis is assigned)
5530     #  @param face from which the mesh pattern is taken
5531     #  @param mesh from which the mesh pattern is taken (optional)
5532     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
5533     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
5534     #               to associate with \a srcV1 (optional)
5535     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
5536     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
5537     #               to associate with \a srcV2 (optional)
5538     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
5539     #                     the same parameters, else (default) - forces the creation a new one
5540     #
5541     #  Note: all association vertices must belong to one edge of a face
5542     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
5543                    srcV2=None, tgtV2=None, UseExisting=0):
5544         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
5545                               UseExisting=0)
5546                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
5547         hyp.SetSourceFace( face )
5548         if not mesh is None and isinstance(mesh, Mesh):
5549             mesh = mesh.GetMesh()
5550         hyp.SetSourceMesh( mesh )
5551         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
5552         return hyp
5553
5554     ## Checks if the given "SourceFace" hypothesis has the same parameters as the given arguments
5555     #def CompareSourceFace(self, hyp, args):
5556     #    # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
5557     #    return False
5558
5559 # Public class: Mesh_Projection3D
5560 # ------------------------------
5561
5562 ## Defines a projection 3D algorithm
5563 #  @ingroup l3_algos_proj
5564 #
5565 class Mesh_Projection3D(Mesh_Algorithm):
5566
5567     ## Private constructor.
5568     def __init__(self, mesh, geom=0):
5569         Mesh_Algorithm.__init__(self)
5570         self.Create(mesh, geom, "Projection_3D")
5571
5572     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
5573     #  the mesh pattern is taken, and, optionally, the  association of vertices
5574     #  between the source and the target solid  (to which a hipothesis is assigned)
5575     #  @param solid from where the mesh pattern is taken
5576     #  @param mesh from where the mesh pattern is taken (optional)
5577     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
5578     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
5579     #  to associate with \a srcV1 (optional)
5580     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
5581     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
5582     #  to associate with \a srcV2 (optional)
5583     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
5584     #                     the same parameters, else (default) - creates a new one
5585     #
5586     #  Note: association vertices must belong to one edge of a solid
5587     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
5588                       srcV2=0, tgtV2=0, UseExisting=0):
5589         hyp = self.Hypothesis("ProjectionSource3D",
5590                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
5591                               UseExisting=0)
5592                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
5593         hyp.SetSource3DShape( solid )
5594         if not mesh is None and isinstance(mesh, Mesh):
5595             mesh = mesh.GetMesh()
5596         hyp.SetSourceMesh( mesh )
5597         if srcV1 and srcV2 and tgtV1 and tgtV2:
5598             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
5599         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
5600         return hyp
5601
5602     ## Checks if the given "SourceShape3D" hypothesis has the same parameters as given arguments
5603     #def CompareSourceShape3D(self, hyp, args):
5604     #    # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
5605     #    return False
5606
5607
5608 # Public class: Mesh_Prism
5609 # ------------------------
5610
5611 ## Defines a 3D extrusion algorithm
5612 #  @ingroup l3_algos_3dextr
5613 #
5614 class Mesh_Prism3D(Mesh_Algorithm):
5615
5616     ## Private constructor.
5617     def __init__(self, mesh, geom=0):
5618         Mesh_Algorithm.__init__(self)
5619         self.Create(mesh, geom, "Prism_3D")
5620
5621 # Public class: Mesh_RadialPrism
5622 # -------------------------------
5623
5624 ## Defines a Radial Prism 3D algorithm
5625 #  @ingroup l3_algos_radialp
5626 #
5627 class Mesh_RadialPrism3D(Mesh_Algorithm):
5628
5629     ## Private constructor.
5630     def __init__(self, mesh, geom=0):
5631         Mesh_Algorithm.__init__(self)
5632         self.Create(mesh, geom, "RadialPrism_3D")
5633
5634         self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
5635         self.nbLayers = None
5636
5637     ## Return 3D hypothesis holding the 1D one
5638     def Get3DHypothesis(self):
5639         return self.distribHyp
5640
5641     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
5642     #  hypothesis. Returns the created hypothesis
5643     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
5644         #print "OwnHypothesis",hypType
5645         if not self.nbLayers is None:
5646             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
5647             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
5648         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
5649         self.mesh.smeshpyD.SetCurrentStudy( None )
5650         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
5651         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
5652         self.distribHyp.SetLayerDistribution( hyp )
5653         return hyp
5654
5655     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
5656     #  prisms to build between the inner and outer shells
5657     #  @param n number of layers
5658     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5659     #                     the same parameters, else (default) - creates a new one
5660     def NumberOfLayers(self, n, UseExisting=0):
5661         self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
5662         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
5663                                         CompareMethod=self.CompareNumberOfLayers)
5664         self.nbLayers.SetNumberOfLayers( n )
5665         return self.nbLayers
5666
5667     ## Checks if the given "NumberOfLayers" hypothesis has the same parameters as the given arguments
5668     def CompareNumberOfLayers(self, hyp, args):
5669         return IsEqual(hyp.GetNumberOfLayers(), args[0])
5670
5671     ## Defines "LocalLength" hypothesis, specifying the segment length
5672     #  to build between the inner and the outer shells
5673     #  @param l the length of segments
5674     #  @param p the precision of rounding
5675     def LocalLength(self, l, p=1e-07):
5676         hyp = self.OwnHypothesis("LocalLength", [l,p])
5677         hyp.SetLength(l)
5678         hyp.SetPrecision(p)
5679         return hyp
5680
5681     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
5682     #  prisms to build between the inner and the outer shells.
5683     #  @param n the number of layers
5684     #  @param s the scale factor (optional)
5685     def NumberOfSegments(self, n, s=[]):
5686         if s == []:
5687             hyp = self.OwnHypothesis("NumberOfSegments", [n])
5688         else:
5689             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
5690             hyp.SetDistrType( 1 )
5691             hyp.SetScaleFactor(s)
5692         hyp.SetNumberOfSegments(n)
5693         return hyp
5694
5695     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
5696     #  to build between the inner and the outer shells with a length that changes in arithmetic progression
5697     #  @param start  the length of the first segment
5698     #  @param end    the length of the last  segment
5699     def Arithmetic1D(self, start, end ):
5700         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
5701         hyp.SetLength(start, 1)
5702         hyp.SetLength(end  , 0)
5703         return hyp
5704
5705     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
5706     #  to build between the inner and the outer shells as geometric length increasing
5707     #  @param start for the length of the first segment
5708     #  @param end   for the length of the last  segment
5709     def StartEndLength(self, start, end):
5710         hyp = self.OwnHypothesis("StartEndLength", [start, end])
5711         hyp.SetLength(start, 1)
5712         hyp.SetLength(end  , 0)
5713         return hyp
5714
5715     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
5716     #  to build between the inner and outer shells
5717     #  @param fineness defines the quality of the mesh within the range [0-1]
5718     def AutomaticLength(self, fineness=0):
5719         hyp = self.OwnHypothesis("AutomaticLength")
5720         hyp.SetFineness( fineness )
5721         return hyp
5722
5723 # Public class: Mesh_RadialQuadrangle1D2D
5724 # -------------------------------
5725
5726 ## Defines a Radial Quadrangle 1D2D algorithm
5727 #  @ingroup l2_algos_radialq
5728 #
5729 class Mesh_RadialQuadrangle1D2D(Mesh_Algorithm):
5730
5731     ## Private constructor.
5732     def __init__(self, mesh, geom=0):
5733         Mesh_Algorithm.__init__(self)
5734         self.Create(mesh, geom, "RadialQuadrangle_1D2D")
5735
5736         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
5737         self.nbLayers = None
5738
5739     ## Return 2D hypothesis holding the 1D one
5740     def Get2DHypothesis(self):
5741         return self.distribHyp
5742
5743     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
5744     #  hypothesis. Returns the created hypothesis
5745     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
5746         #print "OwnHypothesis",hypType
5747         if self.nbLayers:
5748             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
5749         if self.distribHyp is None:
5750             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
5751         else:
5752             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
5753         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
5754         self.mesh.smeshpyD.SetCurrentStudy( None )
5755         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
5756         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
5757         self.distribHyp.SetLayerDistribution( hyp )
5758         return hyp
5759
5760     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
5761     #  @param n number of layers
5762     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5763     #                     the same parameters, else (default) - creates a new one
5764     def NumberOfLayers(self, n, UseExisting=0):
5765         if self.distribHyp:
5766             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
5767         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
5768                                         CompareMethod=self.CompareNumberOfLayers)
5769         self.nbLayers.SetNumberOfLayers( n )
5770         return self.nbLayers
5771
5772     ## Checks if the given "NumberOfLayers" hypothesis has the same parameters as the given arguments
5773     def CompareNumberOfLayers(self, hyp, args):
5774         return IsEqual(hyp.GetNumberOfLayers(), args[0])
5775
5776     ## Defines "LocalLength" hypothesis, specifying the segment length
5777     #  @param l the length of segments
5778     #  @param p the precision of rounding
5779     def LocalLength(self, l, p=1e-07):
5780         hyp = self.OwnHypothesis("LocalLength", [l,p])
5781         hyp.SetLength(l)
5782         hyp.SetPrecision(p)
5783         return hyp
5784
5785     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
5786     #  @param n the number of layers
5787     #  @param s the scale factor (optional)
5788     def NumberOfSegments(self, n, s=[]):
5789         if s == []:
5790             hyp = self.OwnHypothesis("NumberOfSegments", [n])
5791         else:
5792             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
5793             hyp.SetDistrType( 1 )
5794             hyp.SetScaleFactor(s)
5795         hyp.SetNumberOfSegments(n)
5796         return hyp
5797
5798     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
5799     #  with a length that changes in arithmetic progression
5800     #  @param start  the length of the first segment
5801     #  @param end    the length of the last  segment
5802     def Arithmetic1D(self, start, end ):
5803         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
5804         hyp.SetLength(start, 1)
5805         hyp.SetLength(end  , 0)
5806         return hyp
5807
5808     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
5809     #  as geometric length increasing
5810     #  @param start for the length of the first segment
5811     #  @param end   for the length of the last  segment
5812     def StartEndLength(self, start, end):
5813         hyp = self.OwnHypothesis("StartEndLength", [start, end])
5814         hyp.SetLength(start, 1)
5815         hyp.SetLength(end  , 0)
5816         return hyp
5817
5818     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
5819     #  @param fineness defines the quality of the mesh within the range [0-1]
5820     def AutomaticLength(self, fineness=0):
5821         hyp = self.OwnHypothesis("AutomaticLength")
5822         hyp.SetFineness( fineness )
5823         return hyp
5824
5825
5826 # Public class: Mesh_UseExistingElements
5827 # --------------------------------------
5828 ## Defines a Radial Quadrangle 1D2D algorithm
5829 #  @ingroup l3_algos_basic
5830 #
5831 class Mesh_UseExistingElements(Mesh_Algorithm):
5832
5833     def __init__(self, dim, mesh, geom=0):
5834         if dim == 1:
5835             self.Create(mesh, geom, "Import_1D")
5836         else:
5837             self.Create(mesh, geom, "Import_1D2D")
5838         return
5839
5840     ## Defines "Source edges" hypothesis, specifying groups of edges to import
5841     #  @param groups list of groups of edges
5842     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
5843     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
5844     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5845     #                     the same parameters, else (default) - creates a new one
5846     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
5847         if self.algo.GetName() == "Import_2D":
5848             raise ValueError, "algoritm dimension mismatch"
5849         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
5850                               UseExisting=UseExisting, CompareMethod=self._compareHyp)
5851         hyp.SetSourceEdges(groups)
5852         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
5853         return hyp
5854
5855     ## Defines "Source faces" hypothesis, specifying groups of faces to import
5856     #  @param groups list of groups of faces
5857     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
5858     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
5859     #  @param UseExisting if ==true - searches for the existing hypothesis created with
5860     #                     the same parameters, else (default) - creates a new one
5861     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
5862         if self.algo.GetName() == "Import_1D":
5863             raise ValueError, "algoritm dimension mismatch"
5864         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
5865                               UseExisting=UseExisting, CompareMethod=self._compareHyp)
5866         hyp.SetSourceFaces(groups)
5867         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
5868         return hyp
5869
5870     def _compareHyp(self,hyp,args):
5871         if hasattr( hyp, "GetSourceEdges"):
5872             entries = hyp.GetSourceEdges()
5873         else:
5874             entries = hyp.GetSourceFaces()
5875         groups = args[0]
5876         toCopyMesh,toCopyGroups = hyp.GetCopySourceMesh()
5877         if len(entries)==len(groups) and toCopyMesh==args[1] and toCopyGroups==args[2]:
5878             entries2 = []
5879             study = self.mesh.smeshpyD.GetCurrentStudy()
5880             if study:
5881                 for g in groups:
5882                     ior  = salome.orb.object_to_string(g)
5883                     sobj = study.FindObjectIOR(ior)
5884                     if sobj: entries2.append( sobj.GetID() )
5885                     pass
5886                 pass
5887             entries.sort()
5888             entries2.sort()
5889             return entries == entries2
5890         return False
5891
5892
5893 # Private class: Mesh_UseExisting
5894 # -------------------------------
5895 class Mesh_UseExisting(Mesh_Algorithm):
5896
5897     def __init__(self, dim, mesh, geom=0):
5898         if dim == 1:
5899             self.Create(mesh, geom, "UseExisting_1D")
5900         else:
5901             self.Create(mesh, geom, "UseExisting_2D")
5902
5903
5904 import salome_notebook
5905 notebook = salome_notebook.notebook
5906
5907 ##Return values of the notebook variables
5908 def ParseParameters(last, nbParams,nbParam, value):
5909     result = None
5910     strResult = ""
5911     counter = 0
5912     listSize = len(last)
5913     for n in range(0,nbParams):
5914         if n+1 != nbParam:
5915             if counter < listSize:
5916                 strResult = strResult + last[counter]
5917             else:
5918                 strResult = strResult + ""
5919         else:
5920             if isinstance(value, str):
5921                 if notebook.isVariable(value):
5922                     result = notebook.get(value)
5923                     strResult=strResult+value
5924                 else:
5925                     raise RuntimeError, "Variable with name '" + value + "' doesn't exist!!!"
5926             else:
5927                 strResult=strResult+str(value)
5928                 result = value
5929         if nbParams - 1 != counter:
5930             strResult=strResult+var_separator #":"
5931         counter = counter+1
5932     return result, strResult
5933
5934 #Wrapper class for StdMeshers_LocalLength hypothesis
5935 class LocalLength(StdMeshers._objref_StdMeshers_LocalLength):
5936
5937     ## Set Length parameter value
5938     #  @param length numerical value or name of variable from notebook
5939     def SetLength(self, length):
5940         length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,1,length)
5941         StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters)
5942         StdMeshers._objref_StdMeshers_LocalLength.SetLength(self,length)
5943
5944    ## Set Precision parameter value
5945    #  @param precision numerical value or name of variable from notebook
5946     def SetPrecision(self, precision):
5947         precision,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,2,precision)
5948         StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters)
5949         StdMeshers._objref_StdMeshers_LocalLength.SetPrecision(self, precision)
5950
5951 #Registering the new proxy for LocalLength
5952 omniORB.registerObjref(StdMeshers._objref_StdMeshers_LocalLength._NP_RepositoryId, LocalLength)
5953
5954
5955 #Wrapper class for StdMeshers_LayerDistribution hypothesis
5956 class LayerDistribution(StdMeshers._objref_StdMeshers_LayerDistribution):
5957     
5958     def SetLayerDistribution(self, hypo):
5959         StdMeshers._objref_StdMeshers_LayerDistribution.SetParameters(self,hypo.GetParameters())
5960         hypo.ClearParameters();
5961         StdMeshers._objref_StdMeshers_LayerDistribution.SetLayerDistribution(self,hypo)
5962
5963 #Registering the new proxy for LayerDistribution
5964 omniORB.registerObjref(StdMeshers._objref_StdMeshers_LayerDistribution._NP_RepositoryId, LayerDistribution)
5965
5966 #Wrapper class for StdMeshers_SegmentLengthAroundVertex hypothesis
5967 class SegmentLengthAroundVertex(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex):
5968     
5969     ## Set Length parameter value
5970     #  @param length numerical value or name of variable from notebook    
5971     def SetLength(self, length):
5972         length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.GetLastParameters(self),1,1,length)
5973         StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.SetParameters(self,parameters)
5974         StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex.SetLength(self,length)
5975
5976 #Registering the new proxy for SegmentLengthAroundVertex
5977 omniORB.registerObjref(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex._NP_RepositoryId, SegmentLengthAroundVertex)
5978
5979
5980 #Wrapper class for StdMeshers_Arithmetic1D hypothesis
5981 class Arithmetic1D(StdMeshers._objref_StdMeshers_Arithmetic1D):
5982     
5983     ## Set Length parameter value
5984     #  @param length   numerical value or name of variable from notebook
5985     #  @param isStart  true is length is Start Length, otherwise false
5986     def SetLength(self, length, isStart):
5987         nb = 2
5988         if isStart:
5989             nb = 1
5990         length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_Arithmetic1D.GetLastParameters(self),2,nb,length)
5991         StdMeshers._objref_StdMeshers_Arithmetic1D.SetParameters(self,parameters)
5992         StdMeshers._objref_StdMeshers_Arithmetic1D.SetLength(self,length,isStart)
5993         
5994 #Registering the new proxy for Arithmetic1D
5995 omniORB.registerObjref(StdMeshers._objref_StdMeshers_Arithmetic1D._NP_RepositoryId, Arithmetic1D)
5996
5997 #Wrapper class for StdMeshers_Deflection1D hypothesis
5998 class Deflection1D(StdMeshers._objref_StdMeshers_Deflection1D):
5999     
6000     ## Set Deflection parameter value
6001     #  @param deflection numerical value or name of variable from notebook    
6002     def SetDeflection(self, deflection):
6003         deflection,parameters = ParseParameters(StdMeshers._objref_StdMeshers_Deflection1D.GetLastParameters(self),1,1,deflection)
6004         StdMeshers._objref_StdMeshers_Deflection1D.SetParameters(self,parameters)
6005         StdMeshers._objref_StdMeshers_Deflection1D.SetDeflection(self,deflection)
6006
6007 #Registering the new proxy for Deflection1D
6008 omniORB.registerObjref(StdMeshers._objref_StdMeshers_Deflection1D._NP_RepositoryId, Deflection1D)
6009
6010 #Wrapper class for StdMeshers_StartEndLength hypothesis
6011 class StartEndLength(StdMeshers._objref_StdMeshers_StartEndLength):
6012     
6013     ## Set Length parameter value
6014     #  @param length  numerical value or name of variable from notebook
6015     #  @param isStart true is length is Start Length, otherwise false
6016     def SetLength(self, length, isStart):
6017         nb = 2
6018         if isStart:
6019             nb = 1
6020         length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_StartEndLength.GetLastParameters(self),2,nb,length)
6021         StdMeshers._objref_StdMeshers_StartEndLength.SetParameters(self,parameters)
6022         StdMeshers._objref_StdMeshers_StartEndLength.SetLength(self,length,isStart)
6023         
6024 #Registering the new proxy for StartEndLength
6025 omniORB.registerObjref(StdMeshers._objref_StdMeshers_StartEndLength._NP_RepositoryId, StartEndLength)
6026
6027 #Wrapper class for StdMeshers_MaxElementArea hypothesis
6028 class MaxElementArea(StdMeshers._objref_StdMeshers_MaxElementArea):
6029     
6030     ## Set Max Element Area parameter value
6031     #  @param area  numerical value or name of variable from notebook
6032     def SetMaxElementArea(self, area):
6033         area ,parameters = ParseParameters(StdMeshers._objref_StdMeshers_MaxElementArea.GetLastParameters(self),1,1,area)
6034         StdMeshers._objref_StdMeshers_MaxElementArea.SetParameters(self,parameters)
6035         StdMeshers._objref_StdMeshers_MaxElementArea.SetMaxElementArea(self,area)
6036         
6037 #Registering the new proxy for MaxElementArea
6038 omniORB.registerObjref(StdMeshers._objref_StdMeshers_MaxElementArea._NP_RepositoryId, MaxElementArea)
6039
6040
6041 #Wrapper class for StdMeshers_MaxElementVolume hypothesis
6042 class MaxElementVolume(StdMeshers._objref_StdMeshers_MaxElementVolume):
6043     
6044     ## Set Max Element Volume parameter value
6045     #  @param volume numerical value or name of variable from notebook
6046     def SetMaxElementVolume(self, volume):
6047         volume ,parameters = ParseParameters(StdMeshers._objref_StdMeshers_MaxElementVolume.GetLastParameters(self),1,1,volume)
6048         StdMeshers._objref_StdMeshers_MaxElementVolume.SetParameters(self,parameters)
6049         StdMeshers._objref_StdMeshers_MaxElementVolume.SetMaxElementVolume(self,volume)
6050         
6051 #Registering the new proxy for MaxElementVolume
6052 omniORB.registerObjref(StdMeshers._objref_StdMeshers_MaxElementVolume._NP_RepositoryId, MaxElementVolume)
6053
6054
6055 #Wrapper class for StdMeshers_NumberOfLayers hypothesis
6056 class NumberOfLayers(StdMeshers._objref_StdMeshers_NumberOfLayers):
6057     
6058     ## Set Number Of Layers parameter value
6059     #  @param nbLayers  numerical value or name of variable from notebook
6060     def SetNumberOfLayers(self, nbLayers):
6061         nbLayers ,parameters = ParseParameters(StdMeshers._objref_StdMeshers_NumberOfLayers.GetLastParameters(self),1,1,nbLayers)
6062         StdMeshers._objref_StdMeshers_NumberOfLayers.SetParameters(self,parameters)
6063         StdMeshers._objref_StdMeshers_NumberOfLayers.SetNumberOfLayers(self,nbLayers)
6064         
6065 #Registering the new proxy for NumberOfLayers
6066 omniORB.registerObjref(StdMeshers._objref_StdMeshers_NumberOfLayers._NP_RepositoryId, NumberOfLayers)
6067
6068 #Wrapper class for StdMeshers_NumberOfSegments hypothesis
6069 class NumberOfSegments(StdMeshers._objref_StdMeshers_NumberOfSegments):
6070     
6071     ## Set Number Of Segments parameter value
6072     #  @param nbSeg numerical value or name of variable from notebook
6073     def SetNumberOfSegments(self, nbSeg):
6074         lastParameters = StdMeshers._objref_StdMeshers_NumberOfSegments.GetLastParameters(self)
6075         nbSeg , parameters = ParseParameters(lastParameters,1,1,nbSeg)
6076         StdMeshers._objref_StdMeshers_NumberOfSegments.SetParameters(self,parameters)
6077         StdMeshers._objref_StdMeshers_NumberOfSegments.SetNumberOfSegments(self,nbSeg)
6078         
6079     ## Set Scale Factor parameter value
6080     #  @param factor numerical value or name of variable from notebook
6081     def SetScaleFactor(self, factor):
6082         factor, parameters = ParseParameters(StdMeshers._objref_StdMeshers_NumberOfSegments.GetLastParameters(self),2,2,factor)
6083         StdMeshers._objref_StdMeshers_NumberOfSegments.SetParameters(self,parameters)
6084         StdMeshers._objref_StdMeshers_NumberOfSegments.SetScaleFactor(self,factor)
6085         
6086 #Registering the new proxy for NumberOfSegments
6087 omniORB.registerObjref(StdMeshers._objref_StdMeshers_NumberOfSegments._NP_RepositoryId, NumberOfSegments)
6088
6089 if not noNETGENPlugin:
6090     #Wrapper class for NETGENPlugin_Hypothesis hypothesis
6091     class NETGENPlugin_Hypothesis(NETGENPlugin._objref_NETGENPlugin_Hypothesis):
6092
6093         ## Set Max Size parameter value
6094         #  @param maxsize numerical value or name of variable from notebook
6095         def SetMaxSize(self, maxsize):
6096             lastParameters = NETGENPlugin._objref_NETGENPlugin_Hypothesis.GetLastParameters(self)
6097             maxsize, parameters = ParseParameters(lastParameters,4,1,maxsize)
6098             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetParameters(self,parameters)
6099             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetMaxSize(self,maxsize)
6100
6101         ## Set Growth Rate parameter value
6102         #  @param value  numerical value or name of variable from notebook
6103         def SetGrowthRate(self, value):
6104             lastParameters = NETGENPlugin._objref_NETGENPlugin_Hypothesis.GetLastParameters(self)
6105             value, parameters = ParseParameters(lastParameters,4,2,value)
6106             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetParameters(self,parameters)
6107             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetGrowthRate(self,value)
6108
6109         ## Set Number of Segments per Edge parameter value
6110         #  @param value  numerical value or name of variable from notebook
6111         def SetNbSegPerEdge(self, value):
6112             lastParameters = NETGENPlugin._objref_NETGENPlugin_Hypothesis.GetLastParameters(self)
6113             value, parameters = ParseParameters(lastParameters,4,3,value)
6114             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetParameters(self,parameters)
6115             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetNbSegPerEdge(self,value)
6116
6117         ## Set Number of Segments per Radius parameter value
6118         #  @param value  numerical value or name of variable from notebook
6119         def SetNbSegPerRadius(self, value):
6120             lastParameters = NETGENPlugin._objref_NETGENPlugin_Hypothesis.GetLastParameters(self)
6121             value, parameters = ParseParameters(lastParameters,4,4,value)
6122             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetParameters(self,parameters)
6123             NETGENPlugin._objref_NETGENPlugin_Hypothesis.SetNbSegPerRadius(self,value)
6124
6125     #Registering the new proxy for NETGENPlugin_Hypothesis
6126     omniORB.registerObjref(NETGENPlugin._objref_NETGENPlugin_Hypothesis._NP_RepositoryId, NETGENPlugin_Hypothesis)
6127
6128
6129     #Wrapper class for NETGENPlugin_Hypothesis_2D hypothesis
6130     class NETGENPlugin_Hypothesis_2D(NETGENPlugin_Hypothesis,NETGENPlugin._objref_NETGENPlugin_Hypothesis_2D):
6131         pass
6132
6133     #Registering the new proxy for NETGENPlugin_Hypothesis_2D
6134     omniORB.registerObjref(NETGENPlugin._objref_NETGENPlugin_Hypothesis_2D._NP_RepositoryId, NETGENPlugin_Hypothesis_2D)
6135
6136     #Wrapper class for NETGENPlugin_SimpleHypothesis_2D hypothesis
6137     class NETGEN_SimpleParameters_2D(NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D):
6138
6139         ## Set Number of Segments parameter value
6140         #  @param nbSeg numerical value or name of variable from notebook
6141         def SetNumberOfSegments(self, nbSeg):
6142             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.GetLastParameters(self)
6143             nbSeg, parameters = ParseParameters(lastParameters,2,1,nbSeg)
6144             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetParameters(self,parameters)
6145             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetNumberOfSegments(self, nbSeg)
6146
6147         ## Set Local Length parameter value
6148         #  @param length numerical value or name of variable from notebook
6149         def SetLocalLength(self, length):
6150             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.GetLastParameters(self)
6151             length, parameters = ParseParameters(lastParameters,2,1,length)
6152             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetParameters(self,parameters)
6153             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetLocalLength(self, length)
6154
6155         ## Set Max Element Area parameter value
6156         #  @param area numerical value or name of variable from notebook    
6157         def SetMaxElementArea(self, area):
6158             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.GetLastParameters(self)
6159             area, parameters = ParseParameters(lastParameters,2,2,area)
6160             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetParameters(self,parameters)
6161             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetMaxElementArea(self, area)
6162
6163         def LengthFromEdges(self):
6164             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.GetLastParameters(self)
6165             value = 0;
6166             value, parameters = ParseParameters(lastParameters,2,2,value)
6167             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.SetParameters(self,parameters)
6168             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D.LengthFromEdges(self)
6169
6170     #Registering the new proxy for NETGEN_SimpleParameters_2D
6171     omniORB.registerObjref(NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_2D._NP_RepositoryId, NETGEN_SimpleParameters_2D)
6172
6173
6174     #Wrapper class for NETGENPlugin_SimpleHypothesis_3D hypothesis
6175     class NETGEN_SimpleParameters_3D(NETGEN_SimpleParameters_2D,NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D):
6176         ## Set Max Element Volume parameter value
6177         #  @param volume numerical value or name of variable from notebook    
6178         def SetMaxElementVolume(self, volume):
6179             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.GetLastParameters(self)
6180             volume, parameters = ParseParameters(lastParameters,3,3,volume)
6181             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.SetParameters(self,parameters)
6182             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.SetMaxElementVolume(self, volume)
6183
6184         def LengthFromFaces(self):
6185             lastParameters = NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.GetLastParameters(self)
6186             value = 0;
6187             value, parameters = ParseParameters(lastParameters,3,3,value)
6188             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.SetParameters(self,parameters)
6189             NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D.LengthFromFaces(self)
6190
6191     #Registering the new proxy for NETGEN_SimpleParameters_3D
6192     omniORB.registerObjref(NETGENPlugin._objref_NETGENPlugin_SimpleHypothesis_3D._NP_RepositoryId, NETGEN_SimpleParameters_3D)
6193
6194     pass # if not noNETGENPlugin:
6195
6196 class Pattern(SMESH._objref_SMESH_Pattern):
6197
6198     def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
6199         flag = False
6200         if isinstance(theNodeIndexOnKeyPoint1,str):
6201             flag = True
6202         theNodeIndexOnKeyPoint1,Parameters = geompyDC.ParseParameters(theNodeIndexOnKeyPoint1)
6203         if flag:
6204             theNodeIndexOnKeyPoint1 -= 1
6205         theMesh.SetParameters(Parameters)
6206         return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
6207
6208     def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
6209         flag0 = False
6210         flag1 = False
6211         if isinstance(theNode000Index,str):
6212             flag0 = True
6213         if isinstance(theNode001Index,str):
6214             flag1 = True
6215         theNode000Index,theNode001Index,Parameters = geompyDC.ParseParameters(theNode000Index,theNode001Index)
6216         if flag0:
6217             theNode000Index -= 1
6218         if flag1:
6219             theNode001Index -= 1
6220         theMesh.SetParameters(Parameters)
6221         return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
6222
6223 #Registering the new proxy for Pattern
6224 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)