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