Salome HOME
[bos #35147] [EDF] (2023-T1) Decompose Viscous Layer API.
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersBuilder.py
1 # Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21 Python API for the standard meshing plug-in module.
22 """
23
24 LIBRARY = "libStdMeshersEngine.so"
25
26 from salome.smesh.smesh_algorithm import Mesh_Algorithm
27 import StdMeshers
28 from salome.geom import geomBuilder
29
30 #----------------------------
31 # Mesh algo type identifiers
32 #----------------------------
33
34 REGULAR     = "Regular_1D"
35 """
36 Algorithm type: Regular 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment`
37 """
38
39 PYTHON      = "Python_1D"
40 """
41 Algorithm type: Python 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment_Python`
42 """
43
44 COMPOSITE   = "CompositeSegment_1D"
45 """
46 Algorithm type: Composite segment 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_CompositeSegment`
47 """
48
49 Hexa        = "Hexa_3D"
50 """
51 Algorithm type: Hexahedron 3D (i-j-k) algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Hexahedron`
52 """
53
54 QUADRANGLE  = "Quadrangle_2D"
55 """
56 Algorithm type: Quadrangle 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Quadrangle`
57 """
58
59 RADIAL_QUAD = "RadialQuadrangle_1D2D"
60 """
61 Algorithm type: Radial Quadrangle 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_RadialQuadrangle1D2D`
62 """
63
64 QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
65 """
66 Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_QuadMA_1D2D`
67 """
68
69 POLYGON     = "PolygonPerFace_2D"
70 """
71 Algorithm type: Polygon Per Face 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolygonPerFace`
72 """
73
74 POLYHEDRON = "PolyhedronPerSolid_3D"
75 """
76 Algorithm type: Polyhedron Per Solid 3D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolyhedronPerSolid`
77 """
78
79 # import items of enums
80 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
81 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
82
83 #----------------------
84 # Algorithms
85 #----------------------
86
87 class StdMeshersBuilder_Segment(Mesh_Algorithm):
88     """
89     Defines segment 1D algorithm for edges discretization.
90     
91     It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
92     """
93     
94     
95     meshMethod = "Segment"
96     """
97     name of the dynamic method in smeshBuilder.Mesh class
98     """
99
100     algoType   = REGULAR
101     """
102     type of algorithm used with helper function in smeshBuilder.Mesh class
103     """
104
105     isDefault  = True
106     """
107     flag pointing whether this algorithm should be used by default in dynamic method
108     of smeshBuilder.Mesh class    
109     """
110
111     docHelper  = "Create segment 1D algorithm for edges"
112     """
113     doc string of the method
114     """
115
116     def __init__(self, mesh, geom=0):
117         """
118         Private constructor.
119         Parameters:
120             mesh: parent mesh object algorithm is assigned to
121             geom: geometry (shape/sub-shape) algorithm is assigned to;
122                 if it is :code:`0` (default), the algorithm is assigned to the main shape
123         """
124         Mesh_Algorithm.__init__(self)
125         self.Create(mesh, geom, self.algoType)
126         pass
127
128     def LocalLength(self, l, UseExisting=0, p=1e-07):
129         """
130         Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
131         
132         Parameters:
133             l : for the length of segments that cut an edge
134             UseExisting : if == true - searches for an  existing hypothesis created with
135                 the same parameters, else (default) - Create a new one
136             p : precision, used for calculation of the number of segments.
137                 The precision should be a positive, meaningful value within the range [0,1].
138                 In general, the number of segments is calculated with the formula:
139                 nb = ceil((edge_length / l) - p)
140                 Function ceil rounds its argument to the higher integer.
141                 So, p=0 means rounding of (edge_length / l) to the higher integer,
142                 p=0.5 means rounding of (edge_length / l) to the nearest integer,
143                 p=1 means rounding of (edge_length / l) to the lower integer.
144                 Default value is 1e-07.
145                 
146         Returns: 
147             an instance of StdMeshers_LocalLength hypothesis
148         """
149
150         from salome.smesh.smeshBuilder import IsEqual
151         comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
152         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
153         hyp.SetLength(l)
154         hyp.SetPrecision(p)
155         return hyp
156
157     def MaxSize(self, length=0.0, UseExisting=0):
158         """
159         Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
160
161         Parameters:
162             length : is optional maximal allowed length of segment, if it is omitted
163                 the preestimated length is used that depends on geometry size
164             UseExisting : if ==true - searches for an existing hypothesis created with
165                 the same parameters, else (default) - Create a new one
166         
167         Returns:
168             an instance of StdMeshers_MaxLength hypothesis
169         """
170     
171
172         hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
173         if isinstance(length,str) or length > 0:
174             # set given length
175             hyp.SetLength(length)
176         if not UseExisting:
177             # set preestimated length
178             import SMESH
179             gen = self.mesh.smeshpyD
180             initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
181                                                        self.mesh.GetMesh(), self.mesh.GetShape(),
182                                                        SMESH.HypInitParams( 1, 1.0, False ))
183             preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
184             if preHyp:
185                 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
186                 pass
187             pass
188         hyp.SetUsePreestimatedLength( length == 0.0 )
189         return hyp
190
191     def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
192         """
193         Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
194
195         Parameters:
196             n: for the number of segments that cut an edge
197             s: for the scale factor (optional)
198             reversedEdges: is a list of edges to mesh using reversed orientation.
199                     A list item can also be a tuple (edge, 1st_vertex_of_edge)
200             UseExisting: if ==true - searches for an existing hypothesis created with
201                     the same parameters, else (default) - create a new one
202     
203         Returns: 
204             an instance of StdMeshers_NumberOfSegments hypothesis
205         """
206     
207         
208         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
209             reversedEdges, UseExisting = [], reversedEdges
210         entry = self.MainShapeEntry()
211         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
212         if not s:
213             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
214                                   UseExisting=UseExisting,
215                                   CompareMethod=self._compareNumberOfSegments)
216         else:
217             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
218                                   UseExisting=UseExisting,
219                                   CompareMethod=self._compareNumberOfSegments)
220             hyp.SetScaleFactor(s)
221         hyp.SetNumberOfSegments(n)
222         hyp.SetReversedEdges( reversedEdgeInd )
223         hyp.SetObjectEntry( entry )
224         return hyp
225
226     def _compareNumberOfSegments(self, hyp, args):
227         """
228         Private method
229         Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
230         """
231         if hyp.GetNumberOfSegments() == args[0]:
232             if len(args) == 3:
233                 if hyp.GetReversedEdges() == args[1]:
234                     if not args[1] or hyp.GetObjectEntry() == args[2]:
235                         return True
236             else:
237                 from salome.smesh.smeshBuilder import IsEqual
238                 if hyp.GetReversedEdges() == args[2]:
239                     if not args[2] or hyp.GetObjectEntry() == args[3]:
240                         if hyp.GetDistrType() == 1:
241                             if IsEqual(hyp.GetScaleFactor(), args[1]):
242                                 return True
243         return False
244
245     def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
246         """
247         Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
248         within the given range and considering (1) deflection of segments from the edge
249         and (2) distance from segments to closest edges and faces to have segment length
250         not longer than two times shortest distances to edges and faces.
251
252         Parameters:
253             minSize: defines the minimal allowed segment length
254             maxSize: defines the maximal allowed segment length
255             deflection: defines the maximal allowed distance from a segment to an edge
256             UseExisting: if ==true - searches for an existing hypothesis created with
257                 the same parameters, else (default) - Create a new one
258
259         Returns:
260             an instance of StdMeshers_Adaptive1D hypothesis
261         """
262         
263         from salome.smesh.smeshBuilder import IsEqual
264         compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
265                                       IsEqual(hyp.GetMaxSize(), args[1]) and \
266                                       IsEqual(hyp.GetDeflection(), args[2]))
267         hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
268                               UseExisting=UseExisting, CompareMethod=compFun)
269         hyp.SetMinSize(minSize)
270         hyp.SetMaxSize(maxSize)
271         hyp.SetDeflection(deflection)
272         return hyp
273
274     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
275         """
276         Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
277                 that changes in arithmetic progression
278
279         Parameters:
280             start: defines the length of the first segment
281             end:   defines the length of the last  segment
282             reversedEdges: is a list of edges to mesh using reversed orientation.
283                 A list item can also be a tuple (edge, 1st_vertex_of_edge)
284             UseExisting: if ==true - searches for an existing hypothesis created with
285                 the same parameters, else (default) - Create a new one
286
287         Returns:
288                 an instance of StdMeshers_Arithmetic1D hypothesis
289         """
290         
291         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
292             reversedEdges, UseExisting = [], reversedEdges
293         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
294         entry = self.MainShapeEntry()
295         from salome.smesh.smeshBuilder import IsEqual
296         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
297                                       IsEqual(hyp.GetLength(0), args[1]) and \
298                                       hyp.GetReversedEdges() == args[2]  and \
299                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
300         hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
301                               UseExisting=UseExisting, CompareMethod=compFun)
302         hyp.SetStartLength(start)
303         hyp.SetEndLength(end)
304         hyp.SetReversedEdges( reversedEdgeInd )
305         hyp.SetObjectEntry( entry )
306         return hyp
307
308     def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
309         """
310             Defines "GeometricProgression" hypothesis to cut an edge in several
311                 segments with a length that changes in Geometric progression
312
313             Parameters:
314                 start: defines the length of the first segment
315                 ratio: defines the common ratio of the geometric progression
316                 reversedEdges: is a list of edges to mesh using reversed orientation.
317                     A list item can also be a tuple (edge, 1st_vertex_of_edge)
318                 UseExisting: if ==true - searches for an existing hypothesis created with
319                     the same parameters, else (default) - Create a new one
320
321             Returns:
322                 an instance of StdMeshers_Geometric1D hypothesis
323         """
324         
325         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
326         entry = self.MainShapeEntry()
327         from salome.smesh.smeshBuilder import IsEqual
328         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
329                                       IsEqual(hyp.GetLength(0), args[1]) and \
330                                       hyp.GetReversedEdges() == args[2]  and \
331                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
332         hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
333                               UseExisting=UseExisting, CompareMethod=compFun)
334         hyp.SetStartLength( start )
335         hyp.SetCommonRatio( ratio )
336         hyp.SetReversedEdges( reversedEdgeInd )
337         hyp.SetObjectEntry( entry )
338         return hyp
339
340     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
341         """
342         Defines "FixedPoints1D" hypothesis to cut an edge using parameter
343                 on curve from 0 to 1 (additionally it is neecessary to check
344                 orientation of edges and create list of reversed edges if it is
345                 needed) and sets numbers of segments between given points (default
346                 values are 1)
347
348         Parameters:
349             points: defines the list of parameters on curve
350             nbSegs: defines the list of numbers of segments
351             reversedEdges: is a list of edges to mesh using reversed orientation.
352                 A list item can also be a tuple (edge, 1st_vertex_of_edge)
353             UseExisting: if ==true - searches for an existing hypothesis created with
354                 the same parameters, else (default) - Create a new one
355
356         Returns:
357                 an instance of StdMeshers_FixedPoints1D hypothesis
358         """
359         
360         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
361             reversedEdges, UseExisting = [], reversedEdges
362         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
363         entry = self.MainShapeEntry()
364         compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
365                                       hyp.GetNbSegments() == args[1] and \
366                                       hyp.GetReversedEdges() == args[2] and \
367                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
368         hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
369                               UseExisting=UseExisting, CompareMethod=compFun)
370         hyp.SetPoints(points)
371         hyp.SetNbSegments(nbSegs)
372         hyp.SetReversedEdges(reversedEdgeInd)
373         hyp.SetObjectEntry(entry)
374         return hyp
375
376     def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
377         """
378         Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
379
380         Parameters:
381             start: defines the length of the first segment
382             end:   defines the length of the last  segment
383             reversedEdges: is a list of edges to mesh using reversed orientation.
384                 A list item can also be a tuple (edge, 1st_vertex_of_edge)
385             UseExisting: if ==true - searches for an existing hypothesis created with
386                 the same parameters, else (default) - Create a new one
387
388         Returns:
389             an instance of StdMeshers_StartEndLength hypothesis
390         """
391         
392         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
393             reversedEdges, UseExisting = [], reversedEdges
394         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
395         entry = self.MainShapeEntry()
396         from salome.smesh.smeshBuilder import IsEqual
397         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
398                                       IsEqual(hyp.GetLength(0), args[1]) and \
399                                       hyp.GetReversedEdges() == args[2]  and \
400                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
401         hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
402                               UseExisting=UseExisting, CompareMethod=compFun)
403         hyp.SetStartLength(start)
404         hyp.SetEndLength(end)
405         hyp.SetReversedEdges( reversedEdgeInd )
406         hyp.SetObjectEntry( entry )
407         return hyp
408
409     def Deflection1D(self, d, UseExisting=0):
410         """
411         Defines "Deflection1D" hypothesis
412
413         Parameters:
414             d: for the deflection
415             UseExisting: if ==true - searches for an existing hypothesis created with
416                 the same parameters, else (default) - create a new one
417         """
418         
419         from salome.smesh.smeshBuilder import IsEqual
420         compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
421         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
422         hyp.SetDeflection(d)
423         return hyp
424
425     def Propagation(self):
426         """
427         Defines "Propagation" hypothesis that propagates 1D hypotheses
428                 from an edge where this hypothesis is assigned to
429                 on all other edges that are at the opposite side in case of quadrangular faces
430                 This hypothesis should be assigned to an edge to propagate a hypothesis from.
431         """
432         
433         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
434
435     def PropagationOfDistribution(self):
436         """
437         Defines "Propagation of Node Distribution" hypothesis that propagates
438                 distribution of nodes from an edge where this hypothesis is assigned to,
439                 to opposite edges of quadrangular faces, so that number of segments on all these
440                 edges will be the same, as well as relations between segment lengths. 
441         """
442         
443         return self.Hypothesis("PropagOfDistribution", UseExisting=1,
444                                CompareMethod=self.CompareEqualHyp)
445
446     def AutomaticLength(self, fineness=0, UseExisting=0):
447         """
448         Defines "AutomaticLength" hypothesis
449
450         Parameters:
451             fineness: for the fineness [0-1]
452             UseExisting: if ==true - searches for an existing hypothesis created with the
453                 same parameters, else (default) - create a new one
454         """
455         
456         from salome.smesh.smeshBuilder import IsEqual
457         compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
458         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
459                               CompareMethod=compFun)
460         hyp.SetFineness( fineness )
461         return hyp
462
463     def LengthNearVertex(self, length, vertex=-1, UseExisting=0):
464         """
465         Defines "SegmentLengthAroundVertex" hypothesis
466
467         Parameters:
468             length: for the segment length
469             vertex: for the length localization: the vertex index [0,1] | vertex object.
470                 Any other integer value means that the hypothesis will be set on the
471                 whole 1D shape, where Mesh_Segment algorithm is assigned.
472             UseExisting: if ==true - searches for an  existing hypothesis created with
473                 the same parameters, else (default) - Create a new one
474         """
475         
476         import types
477         store_geom = self.geom
478         if isinstance(vertex, int):
479             if vertex == 0 or vertex == 1:
480                 from salome.geom import geomBuilder
481                 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
482                 self.geom = vertex
483                 pass
484             pass
485         else:
486             self.geom = vertex
487             pass
488         # 0D algorithm
489         if self.geom is None:
490             self.geom = store_geom
491             raise RuntimeError("Attempt to create SegmentAroundVertex_0D algorithm on None shape")
492         from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
493         AssureGeomPublished( self.mesh, self.geom )
494         name = GetName(self.geom)
495
496         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
497         if algo is None:
498             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
499             pass
500         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
501         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
502         #
503         from salome.smesh.smeshBuilder import IsEqual
504         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
505         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
506                               CompareMethod=comFun)
507         self.geom = store_geom
508         hyp.SetLength( length )
509         return hyp
510
511     def QuadraticMesh(self):
512         """
513         Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
514         If the 2D mesher sees that all boundary edges are quadratic,
515         it generates quadratic faces, else it generates linear faces using
516         medium nodes as if they are vertices.
517         The 3D mesher generates quadratic volumes only if all boundary faces
518         are quadratic, else it fails.
519         """
520         
521         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
522         return hyp
523
524     pass # end of StdMeshersBuilder_Segment class
525
526 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
527     """
528     Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
529
530     It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
531     """
532     
533
534     meshMethod = "Segment"
535     """
536     name of the dynamic method in smeshBuilder.Mesh class
537     """
538
539     algoType   = COMPOSITE
540     """
541     type of algorithm used with helper function in smeshBuilder.Mesh class
542     """
543
544     isDefault  = False
545     """
546     flag pointing whether this algorithm should be used by default in dynamic method
547         of smeshBuilder.Mesh class
548     """
549
550     docHelper  = "Create segment 1D algorithm for edges"
551     """
552     doc string of the method
553     """
554
555     def __init__(self, mesh, geom=0):
556         """
557         Private constructor.
558
559         Parameters:
560             mesh: parent mesh object algorithm is assigned to
561             geom: geometry (shape/sub-shape) algorithm is assigned to;
562                 if it is :code:`0` (default), the algorithm is assigned to the main shape
563         """
564         self.Create(mesh, geom, self.algoType)
565         pass
566
567     pass # end of StdMeshersBuilder_CompositeSegment class
568
569 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
570     """
571     Defines a segment 1D algorithm for discretization of edges with Python function.
572     It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
573     """
574     
575
576     meshMethod = "Segment"
577     """
578     name of the dynamic method in smeshBuilder.Mesh class
579     """
580     algoType   = PYTHON
581     """
582     type of algorithm used with helper function in smeshBuilder.Mesh class
583     """
584     docHelper  = "Create segment 1D algorithm for edges"
585     """
586     doc string of the method
587     """
588
589     def __init__(self, mesh, geom=0):
590         """
591         Private constructor.
592
593         Parameters:
594             mesh: parent mesh object algorithm is assigned to
595             geom: geometry (shape/sub-shape) algorithm is assigned to;
596                 if it is :code:`0` (default), the algorithm is assigned to the main shape
597         """
598         import Python1dPlugin
599         self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
600         pass
601
602     def PythonSplit1D(self, n, func, UseExisting=0):
603         """
604         Defines "PythonSplit1D" hypothesis
605
606         Parameters:
607             n: for the number of segments that cut an edge
608             func: for the python function that calculates the length of all segments
609             UseExisting: if ==true - searches for the existing hypothesis created with
610                 the same parameters, else (default) - Create a new one
611         """
612         
613         compFun = lambda hyp, args: False
614         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
615                               UseExisting=UseExisting, CompareMethod=compFun)
616         hyp.SetNumberOfSegments(n)
617         hyp.SetPythonLog10RatioFunction(func)
618         return hyp
619
620     pass # end of StdMeshersBuilder_Segment_Python class
621
622 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
623     """
624     Defines a quadrangle 2D algorithm.
625     It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
626     """
627     
628
629     meshMethod = "Quadrangle"
630     """
631     name of the dynamic method in smeshBuilder.Mesh class
632     """
633     algoType   = QUADRANGLE
634     """
635     type of algorithm used with helper function in smeshBuilder.Mesh class
636     """
637     isDefault  = True
638     """
639     flag pointing whether this algorithm should be used by default in dynamic method
640         of smeshBuilder.Mesh class
641     """
642     docHelper  = "Create quadrangle 2D algorithm for faces"
643     """
644     doc string of the method
645     """
646     params     = 0
647     """
648     hypothesis associated with algorithm
649     """
650
651     def __init__(self, mesh, geom=0):
652         """
653         Private constructor.
654
655         Parameters:
656             mesh: parent mesh object algorithm is assigned to
657             geom: geometry (shape/sub-shape) algorithm is assigned to;
658                 if it is :code:`0` (default), the algorithm is assigned to the main shape
659         """
660         Mesh_Algorithm.__init__(self)
661         self.Create(mesh, geom, self.algoType)
662         pass
663
664     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
665                              enfVertices=[],enfPoints=[],corners=[],UseExisting=0):
666         """
667         Defines "QuadrangleParameters" hypothesis
668             quadType defines the algorithm of transition between differently descretized
669             sides of a geometrical face:
670
671             - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
672                 area along the finer meshed sides.
673             - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
674                 finer meshed sides.
675             - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
676                 the finer meshed sides, iff the total quantity of segments on
677                 all four sides of the face is even (divisible by 2).
678             - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
679                 area is located along the coarser meshed sides.
680             - QUAD_REDUCED - only quadrangles are built and the transition between the sides
681                 is made gradually, layer by layer. This type has a limitation on
682                 the number of segments: one pair of opposite sides must have the
683                 same number of segments, the other pair must have an even difference
684                 between the numbers of segments on the sides.
685
686         Parameters:
687             triangleVertex: vertex of a trilateral geometrical face, around which triangles
688                 will be created while other elements will be quadrangles.
689                 Vertex can be either a GEOM_Object or a vertex ID within the
690                 shape to mesh
691             enfVertices: list of shapes defining positions where nodes (enforced nodes)
692                 must be created by the mesher. Shapes can be of any type,
693                 vertices of given shapes define positions of enforced nodes.
694                 Only vertices successfully projected to the face are used.
695             enfPoints: list of points giving positions of enforced nodes.
696                 Point can be defined either as SMESH.PointStruct's
697                 ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
698                 or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
699                 In the case if the defined QuadrangleParameters() refer to a sole face,
700                 all given points must lie on this face, else the mesher fails.
701             corners: list of vertices that should be used as quadrangle corners.
702                 The parameter can be useful for faces with more than four vertices,
703                 since in some cases Quadrangle Mapping algorithm chooses corner vertices
704                 differently than it is desired.
705                 A hypothesis can be global and define corners for all CAD faces that
706                 require it, but be sure that each specified vertex is a corner in all
707                 faces the hypothesis will be applied to.
708             UseExisting: if *True* - searches for the existing hypothesis created with
709                 the same parameters, else (default) - Create a new one
710         """
711         
712
713         import GEOM, SMESH
714         vertexID = triangleVertex
715         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
716             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
717         if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
718             # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
719             UseExisting, enfVertices = enfVertices, []
720
721         pStructs, xyz = [], []
722         for p in enfPoints:
723             if isinstance( p, SMESH.PointStruct ):
724                 xyz.append(( p.x, p.y, p.z ))
725                 pStructs.append( p )
726             else:
727                 xyz.append(( p[0], p[1], p[2] ))
728                 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
729         if not self.params:
730             compFun = lambda hyp,args: \
731                       hyp.GetQuadType() == args[0] and \
732                       (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
733                       ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
734             entries = [ shape.GetStudyEntry() for shape in enfVertices ]
735             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
736                                           UseExisting = UseExisting, CompareMethod=compFun)
737             pass
738
739         if corners and isinstance( corners[0], GEOM._objref_GEOM_Object ):
740             corners = [ self.mesh.geompyD.GetSubShapeID( self.mesh.geom, v ) for v in corners ]
741
742         if self.params.GetQuadType() != quadType:
743             self.params.SetQuadType(quadType)
744         if vertexID > 0:
745             self.params.SetTriaVertex( vertexID )
746         from salome.smesh.smeshBuilder import AssureGeomPublished
747         for v in enfVertices:
748             AssureGeomPublished( self.mesh, v )
749         self.params.SetEnforcedNodes( enfVertices, pStructs )
750         self.params.SetCorners( corners )
751         return self.params
752
753     def QuadranglePreference(self, reversed=False, UseExisting=0):
754         """
755         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
756             quadrangles are built in the transition area along the finer meshed sides,
757             if the total quantity of segments on all four sides of the face is even.
758
759         Parameters:
760             reversed: if True, transition area is located along the coarser meshed sides.
761         UseExisting: if ==true - searches for the existing hypothesis created with
762             the same parameters, else (default) - Create a new one
763         """
764         
765         if reversed:
766             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
767         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
768
769     def TrianglePreference(self, UseExisting=0):
770         """
771         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
772             triangles are built in the transition area along the finer meshed sides.
773
774         Parameters:
775             UseExisting: if ==true - searches for the existing hypothesis created with
776                 the same parameters, else (default) - Create a new one
777         """
778     
779         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
780
781     def Reduced(self, UseExisting=0):
782         """
783         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
784             quadrangles are built and the transition between the sides is made gradually,
785             layer by layer. This type has a limitation on the number of segments: one pair
786             of opposite sides must have the same number of segments, the other pair must
787             have an even difference between the numbers of segments on the sides.
788
789         Parameters:
790             UseExisting: if ==true - searches for the existing hypothesis created with
791                 the same parameters, else (default) - Create a new one
792         """
793         
794         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
795
796     def TriangleVertex(self, vertex, UseExisting=0):
797         """
798         Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
799
800         Parameters:
801             vertex: vertex of a trilateral geometrical face, around which triangles
802                 will be created while other elements will be quadrangles.
803                 Vertex can be either a GEOM_Object or a vertex ID within the
804                 shape to mesh
805              UseExisting: if ==true - searches for the existing hypothesis created with
806                 the same parameters, else (default) - Create a new one
807         """
808         
809         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
810
811     pass # end of StdMeshersBuilder_Quadrangle class
812
813 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
814     """
815     Defines a hexahedron 3D algorithm.
816     It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
817     """
818     
819
820     meshMethod = "Hexahedron"
821     """
822     name of the dynamic method in smeshBuilder.Mesh class
823     """
824     algoType   = Hexa
825     """
826     type of algorithm used with helper function in smeshBuilder.Mesh class
827     """
828     isDefault  = True
829     """
830     flag pointing whether this algorithm should be used by default in dynamic method
831         of smeshBuilder.Mesh class
832     """
833     docHelper  = "Create hexahedron 3D algorithm for volumes"
834     """
835     doc string of the method
836     """
837
838     def __init__(self, mesh, geom=0):
839         """
840         Private constructor.
841
842         Parameters:
843             mesh: parent mesh object algorithm is assigned to
844             geom: geometry (shape/sub-shape) algorithm is assigned to;
845                 if it is :code:`0` (default), the algorithm is assigned to the main shape
846         """
847         Mesh_Algorithm.__init__(self)
848         self.Create(mesh, geom, Hexa)
849         self.renumHypothesis = 0
850         pass
851
852     def Renumber(self, blockCSList=[] ):
853         if isinstance( blockCSList, StdMeshers.BlockCS ):
854             blockCSList = [blockCSList]
855         if not self.renumHypothesis:
856             self.renumHypothesis = self.Hypothesis("BlockRenumber", blockCSList, UseExisting=0)
857         self.renumHypothesis.SetBlocksOrientation( blockCSList )
858         return self.renumHypothesis
859
860     pass # end of StdMeshersBuilder_Hexahedron class
861
862 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
863     """
864     Defines a projection 1D algorithm.
865     It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
866     """
867     
868
869     meshMethod = "Projection1D"
870     """
871     name of the dynamic method in smeshBuilder.Mesh class
872     """
873     algoType   = "Projection_1D"
874     """
875     type of algorithm used with helper function in smeshBuilder.Mesh class
876     """
877     isDefault  = True
878     """
879     flag pointing whether this algorithm should be used by default in dynamic method
880         of smeshBuilder.Mesh class
881     """
882     docHelper  = "Create projection 1D algorithm for edges"
883     """
884     doc string of the method
885     """
886     def __init__(self, mesh, geom=0):
887         """
888         Private constructor.
889
890         Parameters:
891             mesh: parent mesh object algorithm is assigned to
892             geom: geometry (shape/sub-shape) algorithm is assigned to;
893                 if it is :code:`0` (default), the algorithm is assigned to the main shape
894         """
895         Mesh_Algorithm.__init__(self)
896         self.Create(mesh, geom, self.algoType)
897         pass
898
899     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
900         """
901         Defines "Source Edge" hypothesis, specifying a meshed edge, from where
902             a mesh pattern is taken, and, optionally, the association of vertices
903             between the source edge and a target edge (to which a hypothesis is assigned)
904
905         Parameters:
906             edge: from which nodes distribution is taken
907             mesh: from which nodes distribution is taken (optional)
908             srcV: a vertex of *edge* to associate with *tgtV* (optional)
909             tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
910             UseExisting: if ==true - searches for the existing hypothesis created with
911                 the same parameters, else (default) - Create a new one
912         """
913         from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
914         AssureGeomPublished( self.mesh, edge )
915         AssureGeomPublished( self.mesh, srcV )
916         AssureGeomPublished( self.mesh, tgtV )
917         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
918                               UseExisting=0)
919         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
920                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
921         hyp.SetSourceEdge( edge )
922         if not mesh is None and isinstance(mesh, Mesh):
923             mesh = mesh.GetMesh()
924         hyp.SetSourceMesh( mesh )
925         hyp.SetVertexAssociation( srcV, tgtV )
926         return hyp
927
928     pass # end of StdMeshersBuilder_Projection1D class
929
930 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
931     """
932     Defines a projection 2D algorithm.
933     It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
934     """
935     
936
937     meshMethod = "Projection2D"
938     """
939     name of the dynamic method in smeshBuilder.Mesh class
940     """
941     algoType   = "Projection_2D"
942     """
943     type of algorithm used with helper function in smeshBuilder.Mesh class
944     """
945     isDefault  = True
946     """
947     flag pointing whether this algorithm should be used by default in dynamic method
948         of smeshBuilder.Mesh class
949     """
950     docHelper  = "Create projection 2D algorithm for faces"
951     """
952     doc string of the method
953     """
954
955     def __init__(self, mesh, geom=0):
956         """
957         Private constructor.
958
959         Parameters:
960             mesh: parent mesh object algorithm is assigned to
961             geom: geometry (shape/sub-shape) algorithm is assigned to;
962             if it is :code:`0` (default), the algorithm is assigned to the main shape
963         """
964         Mesh_Algorithm.__init__(self)
965         self.Create(mesh, geom, self.algoType)
966         pass
967
968
969     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
970                    srcV2=None, tgtV2=None, UseExisting=0):
971         """
972         Defines "Source Face" hypothesis, specifying a meshed face, from where
973             a mesh pattern is taken, and, optionally, the association of vertices
974             between the source face and the target face (to which a hypothesis is assigned)
975
976         Parameters:
977             face: from which the mesh pattern is taken
978             mesh: from which the mesh pattern is taken (optional)
979             srcV1: a vertex of *face* to associate with *tgtV1* (optional)
980             tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
981             srcV2: a vertex of *face* to associate with *tgtV1* (optional)
982             tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
983             UseExisting: if ==true - forces the search for the existing hypothesis created with
984                 he same parameters, else (default) - forces the creation a new one
985
986         Note: 
987             all association vertices must belong to one edge of a face
988         """
989         from salome.smesh.smeshBuilder import Mesh
990         if isinstance(mesh, Mesh):
991             mesh = mesh.GetMesh()
992         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
993             from salome.smesh.smeshBuilder import AssureGeomPublished
994             AssureGeomPublished( self.mesh, geom )
995         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
996                               UseExisting=0, toAdd=False)
997         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
998                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
999         hyp.SetSourceFace( face )
1000         hyp.SetSourceMesh( mesh )
1001         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1002         self.mesh.AddHypothesis(hyp, self.geom)
1003         return hyp
1004
1005     pass # end of StdMeshersBuilder_Projection2D class
1006
1007 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1008     """
1009     Defines a projection 1D-2D algorithm.
1010     It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1011     """
1012     
1013
1014     meshMethod = "Projection1D2D"
1015     """
1016     name of the dynamic method in smeshBuilder.Mesh class
1017     """
1018     algoType   = "Projection_1D2D"
1019     """
1020     type of algorithm used with helper function in smeshBuilder.Mesh class
1021     """
1022     docHelper  = "Create projection 1D-2D algorithm for faces"
1023     """
1024     doc string of the method
1025     """
1026
1027     def __init__(self, mesh, geom=0):
1028         """
1029         Private constructor.
1030
1031         Parameters:
1032             mesh: parent mesh object algorithm is assigned to
1033             geom: geometry (shape/sub-shape) algorithm is assigned to;
1034                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1035         """
1036         StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1037         pass
1038
1039     pass # end of StdMeshersBuilder_Projection1D2D class
1040
1041 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1042     """
1043     Defines a projection 3D algorithm.
1044     It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1045     """
1046     
1047
1048     meshMethod = "Projection3D"
1049     """
1050     name of the dynamic method in smeshBuilder.Mesh class
1051     """
1052     algoType   = "Projection_3D"
1053     """
1054     type of algorithm used with helper function in smeshBuilder.Mesh class
1055     """
1056     docHelper  = "Create projection 3D algorithm for volumes"
1057     """
1058     doc string of the method
1059     """
1060
1061     def __init__(self, mesh, geom=0):
1062         """
1063         Private constructor.
1064
1065         Parameters:
1066             mesh: parent mesh object algorithm is assigned to
1067             geom" geometry (shape/sub-shape) algorithm is assigned to;
1068                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1069         """
1070         Mesh_Algorithm.__init__(self)
1071         self.Create(mesh, geom, self.algoType)
1072         pass
1073
1074     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1075                       srcV2=0, tgtV2=0, UseExisting=0):
1076         """
1077         Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1078             the mesh pattern is taken, and, optionally, the  association of vertices
1079             between the source and the target solid  (to which a hipothesis is assigned)
1080
1081         Parameters:
1082             solid: from where the mesh pattern is taken
1083             mesh: from where the mesh pattern is taken (optional)
1084             srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1085             tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1086             srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1087             tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1088             UseExisting: if ==true - searches for the existing hypothesis created with
1089                     the same parameters, else (default) - Create a new one
1090
1091         Note: 
1092             association vertices must belong to one edge of a solid
1093         """
1094         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1095             from salome.smesh.smeshBuilder import AssureGeomPublished
1096             AssureGeomPublished( self.mesh, geom )
1097         hyp = self.Hypothesis("ProjectionSource3D",
1098                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1099                               UseExisting=0)
1100         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1101                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1102         hyp.SetSource3DShape( solid )
1103         from salome.smesh.smeshBuilder import Mesh
1104         if isinstance(mesh, Mesh):
1105             mesh = mesh.GetMesh()
1106         if mesh:
1107             hyp.SetSourceMesh( mesh )
1108         if srcV1 and srcV2 and tgtV1 and tgtV2:
1109             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1110         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1111         return hyp
1112
1113     pass # end of StdMeshersBuilder_Projection3D class
1114
1115 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1116     """
1117     Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1118     It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1119     """
1120     
1121
1122     meshMethod = "Prism"
1123     """
1124     name of the dynamic method in smeshBuilder.Mesh class
1125     """
1126     algoType   = "Prism_3D"
1127     """
1128     type of algorithm used with helper function in smeshBuilder.Mesh class
1129     """
1130     docHelper  = "Create prism 3D algorithm for volumes"
1131     """
1132     doc string of the method
1133     """
1134     isDefault  = True
1135     """
1136     flag pointing whether this algorithm should be used by default in dynamic method
1137         of smeshBuilder.Mesh class
1138     """
1139
1140     def __init__(self, mesh, geom=0):
1141         """
1142         Private constructor.
1143
1144         Parameters:
1145             mesh: parent mesh object algorithm is assigned to
1146             geom: geometry (shape/sub-shape) algorithm is assigned to;
1147                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1148         """
1149         Mesh_Algorithm.__init__(self)
1150         
1151         shape = geom
1152         if not shape:
1153             shape = mesh.geom
1154         isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1155         if not isRadial:
1156             self.Create(mesh, geom, "Prism_3D")
1157             pass
1158         else:
1159             self.algoType = "RadialPrism_3D"
1160             self.Create(mesh, geom, "RadialPrism_3D")
1161             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1162             self.nbLayers = None
1163             pass
1164         pass
1165
1166     def Get3DHypothesis(self):
1167         """
1168         Returns: 
1169             3D hypothesis holding the 1D one
1170         """
1171         if self.algoType != "RadialPrism_3D":
1172             print("Prism_3D algorithm doesn't support any hypothesis")
1173             return None
1174         return self.distribHyp
1175
1176     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1177         """
1178         Private method creating a 1D hypothesis and storing it in the LayerDistribution
1179             hypothesis. 
1180
1181         Returns:
1182             the created hypothesis
1183         """
1184         if self.algoType != "RadialPrism_3D":
1185             print("Prism_3D algorithm doesn't support any hypothesis")
1186             return None
1187         if not self.nbLayers is None:
1188             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1189             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1190         self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1191         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1192         self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1193         if not self.distribHyp:
1194             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1195         self.distribHyp.SetLayerDistribution( hyp )
1196         return hyp
1197
1198     def NumberOfLayers(self, n, UseExisting=0):
1199         """
1200         Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1201             prisms to build between the inner and outer shells
1202
1203         Parameters:
1204             n: number of layers
1205             UseExisting: if ==true - searches for the existing hypothesis created with
1206                 the same parameters, else (default) - Create a new one
1207         """
1208         if self.algoType != "RadialPrism_3D":
1209             print("Prism_3D algorithm doesn't support any hypothesis")
1210             return None
1211         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1212         from salome.smesh.smeshBuilder import IsEqual
1213         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1214         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1215                                         CompareMethod=compFun)
1216         self.nbLayers.SetNumberOfLayers( n )
1217         return self.nbLayers
1218
1219     def LocalLength(self, l, p=1e-07):
1220         """
1221         Defines "LocalLength" hypothesis, specifying the segment length
1222             to build between the inner and the outer shells
1223
1224         Parameters:
1225             l: the length of segments
1226             p: the precision of rounding
1227         """
1228         if self.algoType != "RadialPrism_3D":
1229             print("Prism_3D algorithm doesn't support any hypothesis")
1230             return None
1231         hyp = self.OwnHypothesis("LocalLength", [l,p])
1232         hyp.SetLength(l)
1233         hyp.SetPrecision(p)
1234         return hyp
1235
1236     def NumberOfSegments(self, n, s=[]):
1237         """
1238         Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1239             prisms to build between the inner and the outer shells.
1240
1241         Parameters:
1242             n: the number of layers
1243             s: the scale factor (optional)
1244         """
1245         if self.algoType != "RadialPrism_3D":
1246             print("Prism_3D algorithm doesn't support any hypothesis")
1247             return None
1248         if not s:
1249             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1250         else:
1251             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1252             hyp.SetScaleFactor(s)
1253         hyp.SetNumberOfSegments(n)
1254         return hyp
1255
1256     def Arithmetic1D(self, start, end ):
1257         """
1258         Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1259             to build between the inner and the outer shells with a length that changes
1260             in arithmetic progression
1261
1262         Parameters:
1263             start:  the length of the first segment
1264             end:    the length of the last  segment
1265         """
1266         if self.algoType != "RadialPrism_3D":
1267             print("Prism_3D algorithm doesn't support any hypothesis")
1268             return None
1269         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1270         hyp.SetLength(start, 1)
1271         hyp.SetLength(end  , 0)
1272         return hyp
1273
1274     def GeometricProgression(self, start, ratio ):
1275         """
1276         Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1277             to build between the inner and the outer shells with a length that changes
1278             in Geometric progression
1279
1280         Parameters:
1281             start:  the length of the first segment
1282             ratio:  the common ratio of the geometric progression
1283         """
1284         if self.algoType != "RadialPrism_3D":
1285             print("Prism_3D algorithm doesn't support any hypothesis")
1286             return None
1287         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1288         hyp.SetStartLength( start )
1289         hyp.SetCommonRatio( ratio )
1290         return hyp
1291
1292     def StartEndLength(self, start, end):
1293         """
1294         Defines "StartEndLength" hypothesis, specifying distribution of segments
1295             to build between the inner and the outer shells as geometric length increasing
1296
1297         Parameters:
1298             start: for the length of the first segment
1299         end:   for the length of the last  segment
1300         """
1301         if self.algoType != "RadialPrism_3D":
1302             print("Prism_3D algorithm doesn't support any hypothesis")
1303             return None
1304         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1305         hyp.SetLength(start, 1)
1306         hyp.SetLength(end  , 0)
1307         return hyp
1308
1309     def AutomaticLength(self, fineness=0):
1310         """
1311         Defines "AutomaticLength" hypothesis, specifying the number of segments
1312             to build between the inner and outer shells
1313
1314         Parameters:
1315             fineness: defines the quality of the mesh within the range [0-1]
1316         """
1317         if self.algoType != "RadialPrism_3D":
1318             print("Prism_3D algorithm doesn't support any hypothesis")
1319             return None
1320         hyp = self.OwnHypothesis("AutomaticLength")
1321         hyp.SetFineness( fineness )
1322         return hyp
1323
1324     pass # end of StdMeshersBuilder_Prism3D class
1325
1326 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1327     """
1328     Defines Radial Prism 3D algorithm.
1329     It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1330     See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1331     build between the inner and outer shells.
1332     """
1333
1334     meshMethod = "Prism"
1335     """
1336     name of the dynamic method in smeshBuilder.Mesh class
1337     """
1338     algoType   = "RadialPrism_3D"
1339     """
1340     type of algorithm used with helper function in smeshBuilder.Mesh class
1341     """
1342     docHelper  = "Create Raial Prism 3D algorithm for volumes"
1343     """
1344     doc string of the method
1345     """
1346
1347     def __init__(self, mesh, geom=0):
1348         """
1349         Private constructor.
1350
1351         Parameters:
1352             mesh: parent mesh object algorithm is assigned to
1353             geom: geometry (shape/sub-shape) algorithm is assigned to;
1354             if it is :code:`0` (default), the algorithm is assigned to the main shape
1355         """
1356         Mesh_Algorithm.__init__(self)
1357         
1358         shape = geom
1359         if not shape:
1360             shape = mesh.geom
1361         self.Create(mesh, geom, "RadialPrism_3D")
1362         self.distribHyp = None
1363         self.nbLayers = None
1364         return
1365
1366 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1367     """
1368     Base class for algorithms supporting radial distribution hypotheses
1369     """ 
1370
1371     def __init__(self):
1372         Mesh_Algorithm.__init__(self)
1373
1374         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1375         self.nbLayers = None
1376         pass
1377
1378     def Get2DHypothesis(self):
1379         """
1380         Returns:
1381             2D hypothesis holding the 1D one
1382         """
1383         if not self.distribHyp:
1384             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1385         return self.distribHyp
1386
1387     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1388         """
1389         Private method creating a 1D hypothesis and storing it in the LayerDistribution
1390             hypothesis. 
1391
1392         Returns: 
1393             the created hypothesis
1394         """
1395         if self.nbLayers:
1396             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1397         if self.distribHyp is None:
1398             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1399         else:
1400             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1401         self.mesh.smeshpyD.SetEnablePublish( False )
1402         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1403         self.mesh.smeshpyD.SetEnablePublish( True )
1404         self.distribHyp.SetLayerDistribution( hyp )
1405         return hyp
1406
1407     def NumberOfLayers(self, n, UseExisting=0):
1408         """
1409         Defines "NumberOfLayers" hypothesis, specifying the number of layers
1410
1411         Parameters:
1412             n: number of layers
1413             UseExisting: if ==true - searches for the existing hypothesis created with
1414                 the same parameters, else (default) - Create a new one
1415         """
1416         if self.distribHyp:
1417             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1418         from salome.smesh.smeshBuilder import IsEqual
1419         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1420         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1421                                         CompareMethod=compFun)
1422         self.nbLayers.SetNumberOfLayers( n )
1423         return self.nbLayers
1424
1425     def LocalLength(self, l, p=1e-07):
1426         """
1427         Defines "LocalLength" hypothesis, specifying the segment length
1428
1429         Parameters:
1430             l: the length of segments
1431             p: the precision of rounding
1432         """
1433         hyp = self.OwnHypothesis("LocalLength", [l,p])
1434         hyp.SetLength(l)
1435         hyp.SetPrecision(p)
1436         return hyp
1437
1438     def NumberOfSegments(self, n, s=[]):
1439         """
1440         Defines "NumberOfSegments" hypothesis, specifying the number of layers
1441
1442         Parameters:
1443             n: the number of layers
1444             s: the scale factor (optional)
1445         """
1446         if s == []:
1447             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1448         else:
1449             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1450             hyp.SetDistrType( 1 )
1451             hyp.SetScaleFactor(s)
1452         hyp.SetNumberOfSegments(n)
1453         return hyp
1454
1455     def Arithmetic1D(self, start, end ):
1456         """
1457         Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1458             with a length that changes in arithmetic progression
1459
1460         Parameters:
1461             start:  the length of the first segment
1462             end:    the length of the last  segment
1463         """
1464         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1465         hyp.SetLength(start, 1)
1466         hyp.SetLength(end  , 0)
1467         return hyp
1468
1469     def GeometricProgression(self, start, ratio ):
1470         """
1471         Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1472             with a length that changes in Geometric progression
1473
1474         Parameters:
1475             start:  the length of the first segment
1476             ratio:  the common ratio of the geometric progression
1477         """
1478         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1479         hyp.SetStartLength( start )
1480         hyp.SetCommonRatio( ratio )
1481         return hyp
1482
1483     def StartEndLength(self, start, end):
1484         """
1485         Defines "StartEndLength" hypothesis, specifying distribution of segments
1486             as geometric length increasing
1487
1488         Parameters:
1489             start: for the length of the first segment
1490             end:   for the length of the last  segment
1491         """
1492         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1493         hyp.SetLength(start, 1)
1494         hyp.SetLength(end  , 0)
1495         return hyp
1496
1497     def AutomaticLength(self, fineness=0):
1498         """
1499         Defines "AutomaticLength" hypothesis, specifying the number of segments
1500
1501         Parameters:
1502             fineness: defines the quality of the mesh within the range [0-1]
1503         """
1504         hyp = self.OwnHypothesis("AutomaticLength")
1505         hyp.SetFineness( fineness )
1506         return hyp
1507
1508     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1509
1510 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1511     """
1512     Defines a Radial Quadrangle 1D-2D algorithm.
1513     It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1514     """
1515
1516     meshMethod = "Quadrangle"
1517     """
1518     name of the dynamic method in smeshBuilder.Mesh class
1519     """
1520     algoType   = RADIAL_QUAD
1521     """
1522     type of algorithm used with helper function in smeshBuilder.Mesh class
1523     """
1524     docHelper  = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1525     """
1526     doc string of the method
1527     """
1528
1529     def __init__(self, mesh, geom=0):
1530         """
1531         Private constructor.
1532
1533         Parameters:
1534             mesh: parent mesh object algorithm is assigned to
1535             geom: geometry (shape/sub-shape) algorithm is assigned to;
1536                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1537         """
1538         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1539         self.Create(mesh, geom, self.algoType)
1540
1541         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1542         self.nbLayers = None
1543         pass
1544
1545
1546 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1547     """
1548     Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1549     It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1550     """
1551
1552     meshMethod = "Quadrangle"
1553     """
1554     name of the dynamic method in smeshBuilder.Mesh class
1555     """
1556     algoType   = QUAD_MA_PROJ
1557     """
1558     type of algorithm used with helper function in smeshBuilder.Mesh class
1559     """
1560     docHelper  = "Create quadrangle 1D-2D algorithm for faces"
1561     """
1562     doc string of the method
1563     """
1564
1565     def __init__(self, mesh, geom=0):
1566         """
1567         Private constructor.
1568
1569         Parameters:
1570             mesh: parent mesh object algorithm is assigned to
1571             geom: geometry (shape/sub-shape) algorithm is assigned to;
1572                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1573         """
1574         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1575         self.Create(mesh, geom, self.algoType)
1576         pass
1577
1578     pass
1579
1580 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1581     """ Defines a Polygon Per Face 2D algorithm.
1582         It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1583     """
1584
1585     meshMethod = "Polygon"
1586     """
1587     name of the dynamic method in smeshBuilder.Mesh class
1588     """
1589     algoType   = POLYGON
1590     """
1591     type of algorithm used with helper function in smeshBuilder.Mesh class
1592     """
1593     isDefault  = True
1594     """
1595     flag pointing whether this algorithm should be used by default in dynamic method
1596         of smeshBuilder.Mesh class
1597     """
1598     docHelper  = "Create polygon 2D algorithm for faces"
1599     """
1600     doc string of the method
1601     """
1602
1603     def __init__(self, mesh, geom=0):
1604         """
1605         Private constructor.
1606
1607         Parameters:
1608             mesh: parent mesh object algorithm is assigned to
1609             geom: geometry (shape/sub-shape) algorithm is assigned to;
1610                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1611         """
1612         Mesh_Algorithm.__init__(self)
1613         self.Create(mesh, geom, self.algoType)
1614         pass
1615
1616     pass
1617
1618 class StdMeshersBuilder_PolyhedronPerSolid(Mesh_Algorithm):
1619     """ Defines a Polyhedron Per Solid 3D algorithm.
1620         It is created by calling smeshBuilder.Mesh.Polyhedron(geom=0)
1621     """
1622
1623     meshMethod = "Polyhedron"
1624     """
1625     name of the dynamic method in smeshBuilder.Mesh class
1626     """
1627     algoType   = POLYHEDRON
1628     """
1629     type of algorithm used with helper function in smeshBuilder.Mesh class
1630     """
1631     isDefault  = True
1632     """
1633     flag pointing whether this algorithm should be used by default in dynamic method
1634         of smeshBuilder.Mesh class
1635     """
1636     docHelper  = "Create polyhedron 3D algorithm for solids"
1637     """
1638     doc string of the method
1639     """
1640
1641     def __init__(self, mesh, geom=0):
1642         """
1643         Private constructor.
1644
1645         Parameters:
1646             mesh: parent mesh object algorithm is assigned to
1647             geom: geometry (shape/sub-shape) algorithm is assigned to;
1648                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1649         """
1650         Mesh_Algorithm.__init__(self)
1651         self.Create(mesh, geom, self.algoType)
1652         pass
1653
1654     pass
1655
1656 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1657     """ Defines a Use Existing Elements 1D algorithm.
1658
1659     It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1660     """
1661     
1662
1663     meshMethod = "UseExisting1DElements"
1664     """
1665     name of the dynamic method in smeshBuilder.Mesh class
1666     """
1667     algoType   = "Import_1D"
1668     """
1669     type of algorithm used with helper function in smeshBuilder.Mesh class
1670     """
1671     isDefault  = True
1672     """
1673     flag pointing whether this algorithm should be used by default in dynamic method
1674         of smeshBuilder.Mesh class
1675     """
1676     docHelper  = "Create 1D algorithm for edges with reusing of existing mesh elements"
1677     """
1678     doc string of the method
1679     """
1680
1681     def __init__(self, mesh, geom=0):
1682         """
1683         Private constructor.
1684
1685         Parameters:
1686             mesh: parent mesh object algorithm is assigned to
1687             geom: geometry (shape/sub-shape) algorithm is assigned to;
1688                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1689         """
1690         Mesh_Algorithm.__init__(self)
1691         self.Create(mesh, geom, self.algoType)
1692         pass
1693
1694     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1695         """
1696         Defines "Source edges" hypothesis, specifying groups of edges to import
1697
1698         Parameters:
1699             groups: list of groups of edges
1700             toCopyMesh: if True, the whole mesh *groups* belong to is imported
1701             toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1702             UseExisting: if ==true - searches for the existing hypothesis created with
1703                 the same parameters, else (default) - Create a new one
1704         """
1705         for group in groups:
1706             from salome.smesh.smeshBuilder import AssureGeomPublished
1707             AssureGeomPublished( self.mesh, group )
1708         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1709                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1710         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1711                               UseExisting=UseExisting, CompareMethod=compFun)
1712         hyp.SetSourceEdges(groups)
1713         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1714         return hyp
1715
1716     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1717
1718 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1719     """ Defines a Use Existing Elements 1D-2D algorithm.
1720
1721     It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1722     """
1723     
1724
1725     meshMethod = "UseExisting2DElements"
1726     """
1727     name of the dynamic method in smeshBuilder.Mesh class
1728     """
1729     algoType   = "Import_1D2D"
1730     """
1731     type of algorithm used with helper function in smeshBuilder.Mesh class
1732     """
1733     isDefault  = True
1734     """
1735     flag pointing whether this algorithm should be used by default in dynamic method
1736         of smeshBuilder.Mesh class
1737     """
1738     docHelper  = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1739     """
1740     doc string of the method
1741     """
1742
1743     def __init__(self, mesh, geom=0):
1744         """
1745         Private constructor.
1746
1747         Parameters:
1748             mesh: parent mesh object algorithm is assigned to
1749             geom: geometry (shape/sub-shape) algorithm is assigned to;
1750                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1751         """
1752         Mesh_Algorithm.__init__(self)
1753         self.Create(mesh, geom, self.algoType)
1754         pass
1755
1756     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1757         """
1758         Defines "Source faces" hypothesis, specifying groups of faces to import
1759
1760         Parameters:
1761             groups: list of groups of faces
1762             toCopyMesh: if True, the whole mesh *groups* belong to is imported
1763             toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1764             UseExisting: if ==true - searches for the existing hypothesis created with
1765                 the same parameters, else (default) - Create a new one
1766         """
1767         import SMESH
1768         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1769                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1770         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1771                               UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1772         if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1773             groups = [groups]
1774         hyp.SetSourceFaces(groups)
1775         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1776         self.mesh.AddHypothesis(hyp, self.geom)
1777         return hyp
1778
1779     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1780
1781 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1782     """ Defines a Body Fitting 3D algorithm.
1783
1784     It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1785     """
1786     
1787
1788     meshMethod = "BodyFitted"
1789     """
1790     name of the dynamic method in smeshBuilder.Mesh class
1791     """
1792     algoType   = "Cartesian_3D"
1793     """
1794     type of algorithm used with helper function in smeshBuilder.Mesh class
1795     """
1796     isDefault  = True
1797     """
1798     flag pointing whether this algorithm should be used by default in dynamic method
1799         of smeshBuilder.Mesh class
1800     """
1801     docHelper  = "Create Body Fitting 3D algorithm for volumes"
1802     """
1803     doc string of the method
1804     """
1805
1806     def __init__(self, mesh, geom=0):
1807         """
1808         Private constructor.
1809
1810         Parameters:
1811             mesh: parent mesh object algorithm is assigned to
1812             geom: geometry (shape/sub-shape) algorithm is assigned to;
1813                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1814         """
1815         self.Create(mesh, geom, self.algoType)
1816         self.hyp = None
1817         pass
1818
1819     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1820         """
1821         Defines "Body Fitting parameters" hypothesis
1822
1823         Parameters:
1824             xGridDef: is definition of the grid along the X asix.
1825                 It can be in either of two following forms:
1826
1827                     - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1828                     - Functions f(t) defining grid spacing at each point on grid axis. If there are
1829                         several functions, they must be accompanied by relative coordinates of
1830                         points dividing the whole shape into ranges where the functions apply; points
1831                         coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1832                         function f(t) varies from 0.0 to 1.0 within a shape range. 
1833         Note: 
1834             The actual grid spacing can slightly differ from the defined one. This is done for the
1835             best fitting of polyhedrons and for a better mesh quality on the interval boundaries.
1836             For example, if a constant **Spacing** is defined along an axis, the actual grid will
1837             fill the shape's dimension L along this axis with round number of equal cells:
1838             Spacing_actual = L / round( L / Spacing_defined ).
1839
1840         Examples:
1841             "10.5" - defines a grid with a constant spacing
1842             [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1843
1844         Parameters:
1845             yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1846             zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1847             sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1848                 a polyhedron of size less than hexSize/sizeThreshold is not created.
1849             implEdges: enables implementation of geometrical edges into the mesh.
1850         """
1851         if not self.hyp:
1852             compFun = lambda hyp, args: False
1853             self.hyp = self.Hypothesis("CartesianParameters3D",
1854                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1855                                        UseExisting=False, CompareMethod=compFun)
1856         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1857             self.mesh.AddHypothesis( self.hyp, self.geom )
1858
1859         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1860             if not gridDef: raise ValueError("Empty grid definition")
1861             if isinstance( gridDef, str ):
1862                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1863             elif isinstance( gridDef[0], str ):
1864                 self.hyp.SetGridSpacing( gridDef, [], axis )
1865             elif isinstance( gridDef[0], int ) or \
1866                  isinstance( gridDef[0], float ):
1867                 self.hyp.SetGrid(gridDef, axis )
1868             else:
1869                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1870         self.hyp.SetSizeThreshold( sizeThreshold )
1871         self.hyp.SetToAddEdges( implEdges )
1872         return self.hyp
1873
1874     def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1875         """
1876         Defines custom directions of axes of the grid
1877
1878         Parameters:
1879             xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1880             yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1881             zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1882         """
1883         import GEOM
1884         if hasattr( xAxis, "__getitem__" ):
1885             xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1886         elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1887             xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1888         if hasattr( yAxis, "__getitem__" ):
1889             yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1890         elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1891             yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1892         if hasattr( zAxis, "__getitem__" ):
1893             zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1894         elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1895             zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1896         if not self.hyp:
1897             self.hyp = self.Hypothesis("CartesianParameters3D")
1898         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1899             self.mesh.AddHypothesis( self.hyp, self.geom )
1900         self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1901         return self.hyp
1902
1903     def SetOptimalAxesDirs(self, isOrthogonal=True):
1904         """
1905         Automatically defines directions of axes of the grid at which
1906             a number of generated hexahedra is maximal
1907
1908         Parameters:
1909             isOrthogonal: defines whether the axes mush be orthogonal
1910         """
1911         if not self.hyp:
1912             self.hyp = self.Hypothesis("CartesianParameters3D")
1913         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1914             self.mesh.AddHypothesis( self.hyp, self.geom )
1915         x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1916         self.hyp.SetAxesDirs( x,y,z )
1917         return self.hyp
1918
1919     def SetFixedPoint( self, p, toUnset=False ):
1920         """
1921         Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1922             through the fixed point in each direction at which the grid is defined
1923             by spacing
1924
1925         Parameters:
1926             p: coordinates of the fixed point. Either SMESH.PointStruct or
1927                 a vertex or 3 components of coordinates.
1928             toUnset: defines whether the fixed point is defined or removed.
1929         """
1930         import SMESH, GEOM
1931         if toUnset:
1932             if not self.hyp: return
1933             p = SMESH.PointStruct(0,0,0)
1934         elif hasattr( p, "__getitem__" ):
1935             p = SMESH.PointStruct( p[0],p[1],p[2] )
1936         elif isinstance( p, GEOM._objref_GEOM_Object ):
1937             p = self.mesh.smeshpyD.GetPointStruct( p )
1938         if not self.hyp:
1939             self.hyp = self.Hypothesis("CartesianParameters3D")
1940         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1941             self.mesh.AddHypothesis( self.hyp, self.geom )
1942         self.hyp.SetFixedPoint( p, toUnset )
1943         return self.hyp
1944         
1945
1946     pass # end of StdMeshersBuilder_Cartesian_3D class
1947
1948 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1949     """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1950         segments usable by 2D algorithms.
1951
1952     It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1953     """
1954
1955
1956     meshMethod = "UseExistingSegments"
1957     """
1958     name of the dynamic method in smeshBuilder.Mesh class
1959     """
1960     algoType   = "UseExisting_1D"
1961     """
1962     type of algorithm used with helper function in smeshBuilder.Mesh class
1963     """
1964     docHelper  = "Create 1D algorithm allowing batch meshing of edges"
1965     """
1966     doc string of the method
1967     """
1968
1969     def __init__(self, mesh, geom=0):
1970         """
1971         Private constructor.
1972
1973         Parameters:
1974             mesh: parent mesh object algorithm is assigned to
1975             geom: geometry (shape/sub-shape) algorithm is assigned to;
1976                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1977         """
1978         self.Create(mesh, geom, self.algoType)
1979         pass
1980
1981     pass # end of StdMeshersBuilder_UseExisting_1D class
1982
1983 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1984     """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1985     faces usable by 3D algorithms.
1986
1987     It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1988     """
1989     
1990
1991     meshMethod = "UseExistingFaces"
1992     """
1993     name of the dynamic method in smeshBuilder.Mesh class
1994     """
1995     algoType   = "UseExisting_2D"
1996     """
1997     type of algorithm used with helper function in smeshBuilder.Mesh class
1998     """
1999     docHelper  = "Create 2D algorithm allowing batch meshing of faces"
2000     """
2001     doc string of the method
2002     """
2003
2004     def __init__(self, mesh, geom=0):
2005         """
2006         Private constructor.
2007
2008         Parameters:
2009             mesh: parent mesh object algorithm is assigned to
2010             geom: geometry (shape/sub-shape) algorithm is assigned to;
2011             if it is :code:`0` (default), the algorithm is assigned to the main shape
2012         """
2013         self.Create(mesh, geom, self.algoType)
2014         pass
2015
2016     pass # end of StdMeshersBuilder_UseExisting_2D class
2017     
2018 class StdMeshersBuilder_ViscousLayer(Mesh_Algorithm):
2019     """ Defines the prismatic layer builder.
2020
2021     It is created by calling smeshBuilder.Mesh.ViscousLayerBuilder(geom=TheGeometry)
2022     """
2023     
2024     meshMethod = "ViscousLayerBuilder"
2025     """
2026     name of the dynamic method in smeshBuilder.Mesh class
2027     """
2028     algoType   = "ViscousLayerBuilder"
2029     """
2030     type of algorithm used with helper function in smeshBuilder.Mesh class
2031     """
2032     docHelper  = "Viscous layer builder for 2D and 3D geometries"
2033     """
2034     doc string of the method
2035     """
2036     
2037     # On create method it will call create method from mesh python class
2038     # 
2039     def __init__(self, mesh, geom = 0 ):
2040         """
2041         Private constructor.
2042
2043         Parameters:
2044             mesh: parent mesh object algorithm is assigned to
2045             geom: geometry (shape/sub-shape) algorithm is assigned to;
2046                 if it is :code:`0` (default), the algorithm is assigned to the main shape
2047         """        
2048         self.thickness          = None
2049         self.numberOfLayers     = None
2050         self.stretchFactor      = None
2051         self.elementsId         = []
2052         self.isElementToIgnore  = True
2053         self.extrMethod         = StdMeshers.SURF_OFFSET_SMOOTH
2054         self.groupName          = ""
2055         self.shrinkGeometry     = None
2056         self.algo               = self.Create(mesh, geom, self.algoType)     
2057         pass
2058
2059     def setBuilderParameters( self, thickness, numberOfLayers, stretchFactor, elementsId=[], 
2060                                     isElementToIgnore=True, extrMethod=StdMeshers.SURF_OFFSET_SMOOTH, groupName="" ):            
2061         self.thickness          = thickness
2062         self.numberOfLayers     = numberOfLayers
2063         self.stretchFactor      = stretchFactor
2064         self.elementsId         = elementsId        # can be faces or edges
2065         self.isElementToIgnore  = isElementToIgnore
2066         self.extrMethod         = extrMethod
2067         self.groupName          = groupName
2068
2069         self.algo.SetTotalThickness( thickness )
2070         self.algo.SetNumberLayers( numberOfLayers )
2071         self.algo.SetStretchFactor( stretchFactor )
2072         
2073         #Faces are set based on int ids so if a collection of face geom objects is recived cast it to int 
2074         if elementsId and isinstance( elementsId, geomBuilder.GEOM._objref_GEOM_Object ):
2075             elementsId = [ elementsId ]
2076         if elementsId and isinstance( elementsId[0], geomBuilder.GEOM._objref_GEOM_Object ):
2077             elementsIDs = []
2078             for shape in elementsId:
2079                 try:
2080                   ff = self.mesh.geompyD.SubShapeAll( shape, self.mesh.geompyD.ShapeType["FACE"] )
2081                   if ( len( ff ) == 0 ):
2082                     #try to get edges
2083                     ff = self.mesh.geompyD.SubShapeAll( shape, self.mesh.geompyD.ShapeType["EDGE"] )
2084
2085                   for f in ff:
2086                     elementsIDs.append( self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f))
2087                 except:
2088                   # try to get the SHAPERSTUDY engine directly, because GetGen does not work because of
2089                   # simplification of access in geomBuilder: omniORB.registerObjref
2090                   from SHAPERSTUDY_utils import getEngine
2091                   gen = getEngine()
2092                   if gen:
2093                     aShapeOp = gen.GetIShapesOperations()
2094                     ff = aShapeOp.ExtractSubShapes( shape, self.mesh.geompyD.ShapeType["FACE"], False)
2095                     if (len(ff)==0):
2096                         #try to get edges
2097                         ff = aShapeOp.ExtractSubShapes( shape, self.mesh.geompyD.ShapeType["EDGE"], False)
2098                     for f in ff:
2099                       elementsIDs.append( aShapeOp.GetSubShapeIndex( self.mesh.geom, f ))
2100             elementsId = elementsIDs
2101
2102         self.algo.SetFaces( elementsId, isElementToIgnore )    
2103         self.algo.SetGroupName( groupName )   
2104         self.algo.SetMethod( extrMethod )        
2105         
2106     def GetShrinkGeometry( self ):
2107         if isinstance(self.geom, geomBuilder.GEOM._objref_GEOM_Object):
2108             self.shrinkGeometry = self.algo.GetShrinkGeometry( self.mesh.GetMesh(), self.geom )
2109         
2110         return self.shrinkGeometry
2111
2112     def AddLayers( self, shrinkMesh ):
2113         success = self.algo.AddLayers( shrinkMesh.GetMesh(), self.mesh.GetMesh(), self.geom )
2114         if ( success ):
2115             return self.mesh  #Return the original mesh of the builder
2116         else:
2117             return shrinkMesh
2118
2119     pass # end of StdMeshersBuilder_ViscousLayer class