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