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