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