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