Salome HOME
#17845 [EDF] Modifications of Automatic meshing
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersBuilder.py
1 # Copyright (C) 2007-2019  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  = "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_Triangle_MEFISTO(Mesh_Algorithm):
622     """
623     Triangle MEFISTO 2D algorithm.
624     It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
625     """
626     
627
628     meshMethod = "Triangle"
629     """
630     name of the dynamic method in smeshBuilder.Mesh class
631     """
632     algoType   = MEFISTO
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 triangle 2D algorithm for faces"
642     """
643     doc string of the method
644     """
645
646     def __init__(self, mesh, geom=0):
647         """
648         Private constructor.
649
650         Parameters:
651             mesh: parent mesh object algorithm is assigned to
652             geom: geometry (shape/sub-shape) algorithm is assigned to;
653                 if it is :code:`0` (default), the algorithm is assigned to the main shape
654         """
655         Mesh_Algorithm.__init__(self)
656         self.Create(mesh, geom, self.algoType)
657         pass
658
659     def MaxElementArea(self, area, UseExisting=0):
660         """
661         Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
662
663         Parameters:
664             area: for the maximum area of each triangle
665             UseExisting: if ==true - searches for an  existing hypothesis created with the
666                 same parameters, else (default) - Create a new one
667         """
668         
669         from salome.smesh.smeshBuilder import IsEqual
670         comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
671         hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
672                               CompareMethod=comparator)
673         hyp.SetMaxElementArea(area)
674         return hyp
675
676     def LengthFromEdges(self):
677         """
678         Defines "LengthFromEdges" hypothesis to build triangles
679             based on the length of the edges taken from the wire
680         """
681         
682         hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
683         return hyp
684
685     pass # end of StdMeshersBuilder_Triangle_MEFISTO class
686
687 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
688     """
689     Defines a quadrangle 2D algorithm.
690     It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
691     """
692     
693
694     meshMethod = "Quadrangle"
695     """
696     name of the dynamic method in smeshBuilder.Mesh class
697     """
698     algoType   = QUADRANGLE
699     """
700     type of algorithm used with helper function in smeshBuilder.Mesh class
701     """
702     isDefault  = True
703     """
704     flag pointing whether this algorithm should be used by default in dynamic method
705         of smeshBuilder.Mesh class
706     """
707     docHelper  = "Create quadrangle 2D algorithm for faces"
708     """
709     doc string of the method
710     """
711     params     = 0
712     """
713     hypothesis associated with algorithm
714     """
715
716     def __init__(self, mesh, geom=0):
717         """
718         Private constructor.
719
720         Parameters:
721             mesh: parent mesh object algorithm is assigned to
722             geom: geometry (shape/sub-shape) algorithm is assigned to;
723                 if it is :code:`0` (default), the algorithm is assigned to the main shape
724         """
725         Mesh_Algorithm.__init__(self)
726         self.Create(mesh, geom, self.algoType)
727         pass
728
729     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
730                              enfVertices=[],enfPoints=[],corners=[],UseExisting=0):
731         """
732         Defines "QuadrangleParameters" hypothesis
733             quadType defines the algorithm of transition between differently descretized
734             sides of a geometrical face:
735
736             - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
737                 area along the finer meshed sides.
738             - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
739                 finer meshed sides.
740             - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
741                 the finer meshed sides, iff the total quantity of segments on
742                 all four sides of the face is even (divisible by 2).
743             - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
744                 area is located along the coarser meshed sides.
745             - QUAD_REDUCED - only quadrangles are built and the transition between the sides
746                 is made gradually, layer by layer. This type has a limitation on
747                 the number of segments: one pair of opposite sides must have the
748                 same number of segments, the other pair must have an even difference
749                 between the numbers of segments on the sides.
750
751         Parameters:
752             triangleVertex: vertex of a trilateral geometrical face, around which triangles
753                 will be created while other elements will be quadrangles.
754                 Vertex can be either a GEOM_Object or a vertex ID within the
755                 shape to mesh
756             enfVertices: list of shapes defining positions where nodes (enforced nodes)
757                 must be created by the mesher. Shapes can be of any type,
758                 vertices of given shapes define positions of enforced nodes.
759                 Only vertices successfully projected to the face are used.
760             enfPoints: list of points giving positions of enforced nodes.
761                 Point can be defined either as SMESH.PointStruct's
762                 ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
763                 or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
764                 In the case if the defined QuadrangleParameters() refer to a sole face,
765                 all given points must lie on this face, else the mesher fails.
766             corners: list of vertices that should be used as quadrangle corners.
767                 The parameter can be useful for faces with more than four vertices,
768                 since in some cases Quadrangle Mapping algorithm chooses corner vertices
769                 differently than it is desired.
770                 A hypothesis can be global and define corners for all CAD faces that
771                 require it, but be sure that each specified vertex is a corner in all
772                 faces the hypothesis will be applied to.
773             UseExisting: if *True* - searches for the existing hypothesis created with
774                 the same parameters, else (default) - Create a new one
775         """
776         
777
778         import GEOM, SMESH
779         vertexID = triangleVertex
780         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
781             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
782         if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
783             # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
784             UseExisting, enfVertices = enfVertices, []
785
786         pStructs, xyz = [], []
787         for p in enfPoints:
788             if isinstance( p, SMESH.PointStruct ):
789                 xyz.append(( p.x, p.y, p.z ))
790                 pStructs.append( p )
791             else:
792                 xyz.append(( p[0], p[1], p[2] ))
793                 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
794         if not self.params:
795             compFun = lambda hyp,args: \
796                       hyp.GetQuadType() == args[0] and \
797                       (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
798                       ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
799             entries = [ shape.GetStudyEntry() for shape in enfVertices ]
800             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
801                                           UseExisting = UseExisting, CompareMethod=compFun)
802             pass
803
804         if corners and isinstance( corners[0], GEOM._objref_GEOM_Object ):
805             corners = [ self.mesh.geompyD.GetSubShapeID( self.mesh.geom, v ) for v in corners ]
806
807         if self.params.GetQuadType() != quadType:
808             self.params.SetQuadType(quadType)
809         if vertexID > 0:
810             self.params.SetTriaVertex( vertexID )
811         from salome.smesh.smeshBuilder import AssureGeomPublished
812         for v in enfVertices:
813             AssureGeomPublished( self.mesh, v )
814         self.params.SetEnforcedNodes( enfVertices, pStructs )
815         self.params.SetCorners( corners )
816         return self.params
817
818     def QuadranglePreference(self, reversed=False, UseExisting=0):
819         """
820         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
821             quadrangles are built in the transition area along the finer meshed sides,
822             if the total quantity of segments on all four sides of the face is even.
823
824         Parameters:
825             reversed: if True, transition area is located along the coarser meshed sides.
826         UseExisting: if ==true - searches for the existing hypothesis created with
827             the same parameters, else (default) - Create a new one
828         """
829         
830         if reversed:
831             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
832         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
833
834     def TrianglePreference(self, UseExisting=0):
835         """
836         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
837             triangles are built in the transition area along the finer meshed sides.
838
839         Parameters:
840             UseExisting: if ==true - searches for the existing hypothesis created with
841                 the same parameters, else (default) - Create a new one
842         """
843     
844         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
845
846     def Reduced(self, UseExisting=0):
847         """
848         Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
849             quadrangles are built and the transition between the sides is made gradually,
850             layer by layer. This type has a limitation on the number of segments: one pair
851             of opposite sides must have the same number of segments, the other pair must
852             have an even difference between the numbers of segments on the sides.
853
854         Parameters:
855             UseExisting: if ==true - searches for the existing hypothesis created with
856                 the same parameters, else (default) - Create a new one
857         """
858         
859         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
860
861     def TriangleVertex(self, vertex, UseExisting=0):
862         """
863         Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
864
865         Parameters:
866             vertex: vertex of a trilateral geometrical face, around which triangles
867                 will be created while other elements will be quadrangles.
868                 Vertex can be either a GEOM_Object or a vertex ID within the
869                 shape to mesh
870              UseExisting: if ==true - searches for the existing hypothesis created with
871                 the same parameters, else (default) - Create a new one
872         """
873         
874         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
875
876     pass # end of StdMeshersBuilder_Quadrangle class
877
878 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
879     """
880     Defines a hexahedron 3D algorithm.
881     It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
882     """
883     
884
885     meshMethod = "Hexahedron"
886     """
887     name of the dynamic method in smeshBuilder.Mesh class
888     """
889     algoType   = Hexa
890     """
891     type of algorithm used with helper function in smeshBuilder.Mesh class
892     """
893     isDefault  = True
894     """
895     flag pointing whether this algorithm should be used by default in dynamic method
896         of smeshBuilder.Mesh class
897     """
898     docHelper  = "Create hexahedron 3D algorithm for volumes"
899     """
900     doc string of the method
901     """
902
903     def __init__(self, mesh, geom=0):
904         """
905         Private constructor.
906
907         Parameters:
908             mesh: parent mesh object algorithm is assigned to
909             geom: geometry (shape/sub-shape) algorithm is assigned to;
910                 if it is :code:`0` (default), the algorithm is assigned to the main shape
911         """
912         Mesh_Algorithm.__init__(self)
913         self.Create(mesh, geom, Hexa)
914         pass
915
916     pass # end of StdMeshersBuilder_Hexahedron class
917
918 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
919     """
920     Defines a projection 1D algorithm.
921     It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
922     """
923     
924
925     meshMethod = "Projection1D"
926     """
927     name of the dynamic method in smeshBuilder.Mesh class
928     """
929     algoType   = "Projection_1D"
930     """
931     type of algorithm used with helper function in smeshBuilder.Mesh class
932     """
933     isDefault  = True
934     """
935     flag pointing whether this algorithm should be used by default in dynamic method
936         of smeshBuilder.Mesh class
937     """
938     docHelper  = "Create projection 1D algorithm for edges"
939     """
940     doc string of the method
941     """
942     def __init__(self, mesh, geom=0):
943         """
944         Private constructor.
945
946         Parameters:
947             mesh: parent mesh object algorithm is assigned to
948             geom: geometry (shape/sub-shape) algorithm is assigned to;
949                 if it is :code:`0` (default), the algorithm is assigned to the main shape
950         """
951         Mesh_Algorithm.__init__(self)
952         self.Create(mesh, geom, self.algoType)
953         pass
954
955     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
956         """
957         Defines "Source Edge" hypothesis, specifying a meshed edge, from where
958             a mesh pattern is taken, and, optionally, the association of vertices
959             between the source edge and a target edge (to which a hypothesis is assigned)
960
961         Parameters:
962             edge: from which nodes distribution is taken
963             mesh: from which nodes distribution is taken (optional)
964             srcV: a vertex of *edge* to associate with *tgtV* (optional)
965             tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
966             UseExisting: if ==true - searches for the existing hypothesis created with
967                 the same parameters, else (default) - Create a new one
968         """
969         from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
970         AssureGeomPublished( self.mesh, edge )
971         AssureGeomPublished( self.mesh, srcV )
972         AssureGeomPublished( self.mesh, tgtV )
973         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
974                               UseExisting=0)
975         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
976                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
977         hyp.SetSourceEdge( edge )
978         if not mesh is None and isinstance(mesh, Mesh):
979             mesh = mesh.GetMesh()
980         hyp.SetSourceMesh( mesh )
981         hyp.SetVertexAssociation( srcV, tgtV )
982         return hyp
983
984     pass # end of StdMeshersBuilder_Projection1D class
985
986 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
987     """
988     Defines a projection 2D algorithm.
989     It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
990     """
991     
992
993     meshMethod = "Projection2D"
994     """
995     name of the dynamic method in smeshBuilder.Mesh class
996     """
997     algoType   = "Projection_2D"
998     """
999     type of algorithm used with helper function in smeshBuilder.Mesh class
1000     """
1001     isDefault  = True
1002     """
1003     flag pointing whether this algorithm should be used by default in dynamic method
1004         of smeshBuilder.Mesh class
1005     """
1006     docHelper  = "Create projection 2D algorithm for faces"
1007     """
1008     doc string of the method
1009     """
1010
1011     def __init__(self, mesh, geom=0):
1012         """
1013         Private constructor.
1014
1015         Parameters:
1016             mesh: parent mesh object algorithm is assigned to
1017             geom: geometry (shape/sub-shape) algorithm is assigned to;
1018             if it is :code:`0` (default), the algorithm is assigned to the main shape
1019         """
1020         Mesh_Algorithm.__init__(self)
1021         self.Create(mesh, geom, self.algoType)
1022         pass
1023
1024
1025     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1026                    srcV2=None, tgtV2=None, UseExisting=0):
1027         """
1028         Defines "Source Face" hypothesis, specifying a meshed face, from where
1029             a mesh pattern is taken, and, optionally, the association of vertices
1030             between the source face and the target face (to which a hypothesis is assigned)
1031
1032         Parameters:
1033             face: from which the mesh pattern is taken
1034             mesh: from which the mesh pattern is taken (optional)
1035             srcV1: a vertex of *face* to associate with *tgtV1* (optional)
1036             tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
1037             srcV2: a vertex of *face* to associate with *tgtV1* (optional)
1038             tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
1039             UseExisting: if ==true - forces the search for the existing hypothesis created with
1040                 he same parameters, else (default) - forces the creation a new one
1041
1042         Note: 
1043             all association vertices must belong to one edge of a face
1044         """
1045         from salome.smesh.smeshBuilder import Mesh
1046         if isinstance(mesh, Mesh):
1047             mesh = mesh.GetMesh()
1048         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
1049             from salome.smesh.smeshBuilder import AssureGeomPublished
1050             AssureGeomPublished( self.mesh, geom )
1051         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1052                               UseExisting=0, toAdd=False)
1053         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
1054                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1055         hyp.SetSourceFace( face )
1056         hyp.SetSourceMesh( mesh )
1057         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1058         self.mesh.AddHypothesis(hyp, self.geom)
1059         return hyp
1060
1061     pass # end of StdMeshersBuilder_Projection2D class
1062
1063 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1064     """
1065     Defines a projection 1D-2D algorithm.
1066     It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1067     """
1068     
1069
1070     meshMethod = "Projection1D2D"
1071     """
1072     name of the dynamic method in smeshBuilder.Mesh class
1073     """
1074     algoType   = "Projection_1D2D"
1075     """
1076     type of algorithm used with helper function in smeshBuilder.Mesh class
1077     """
1078     docHelper  = "Create projection 1D-2D algorithm for faces"
1079     """
1080     doc string of the method
1081     """
1082
1083     def __init__(self, mesh, geom=0):
1084         """
1085         Private constructor.
1086
1087         Parameters:
1088             mesh: parent mesh object algorithm is assigned to
1089             geom: geometry (shape/sub-shape) algorithm is assigned to;
1090                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1091         """
1092         StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1093         pass
1094
1095     pass # end of StdMeshersBuilder_Projection1D2D class
1096
1097 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1098     """
1099     Defines a projection 3D algorithm.
1100     It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1101     """
1102     
1103
1104     meshMethod = "Projection3D"
1105     """
1106     name of the dynamic method in smeshBuilder.Mesh class
1107     """
1108     algoType   = "Projection_3D"
1109     """
1110     type of algorithm used with helper function in smeshBuilder.Mesh class
1111     """
1112     docHelper  = "Create projection 3D algorithm for volumes"
1113     """
1114     doc string of the method
1115     """
1116
1117     def __init__(self, mesh, geom=0):
1118         """
1119         Private constructor.
1120
1121         Parameters:
1122             mesh: parent mesh object algorithm is assigned to
1123             geom" geometry (shape/sub-shape) algorithm is assigned to;
1124                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1125         """
1126         Mesh_Algorithm.__init__(self)
1127         self.Create(mesh, geom, self.algoType)
1128         pass
1129
1130     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1131                       srcV2=0, tgtV2=0, UseExisting=0):
1132         """
1133         Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1134             the mesh pattern is taken, and, optionally, the  association of vertices
1135             between the source and the target solid  (to which a hipothesis is assigned)
1136
1137         Parameters:
1138             solid: from where the mesh pattern is taken
1139             mesh: from where the mesh pattern is taken (optional)
1140             srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1141             tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1142             srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1143             tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1144             UseExisting: if ==true - searches for the existing hypothesis created with
1145                     the same parameters, else (default) - Create a new one
1146
1147         Note: 
1148             association vertices must belong to one edge of a solid
1149         """
1150         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1151             from salome.smesh.smeshBuilder import AssureGeomPublished
1152             AssureGeomPublished( self.mesh, geom )
1153         hyp = self.Hypothesis("ProjectionSource3D",
1154                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1155                               UseExisting=0)
1156         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1157                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1158         hyp.SetSource3DShape( solid )
1159         from salome.smesh.smeshBuilder import Mesh
1160         if isinstance(mesh, Mesh):
1161             mesh = mesh.GetMesh()
1162         if mesh:
1163             hyp.SetSourceMesh( mesh )
1164         if srcV1 and srcV2 and tgtV1 and tgtV2:
1165             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1166         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1167         return hyp
1168
1169     pass # end of StdMeshersBuilder_Projection3D class
1170
1171 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1172     """
1173     Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1174     It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1175     """
1176     
1177
1178     meshMethod = "Prism"
1179     """
1180     name of the dynamic method in smeshBuilder.Mesh class
1181     """
1182     algoType   = "Prism_3D"
1183     """
1184     type of algorithm used with helper function in smeshBuilder.Mesh class
1185     """
1186     docHelper  = "Create prism 3D algorithm for volumes"
1187     """
1188     doc string of the method
1189     """
1190     isDefault  = True
1191     """
1192     flag pointing whether this algorithm should be used by default in dynamic method
1193         of smeshBuilder.Mesh class
1194     """
1195
1196     def __init__(self, mesh, geom=0):
1197         """
1198         Private constructor.
1199
1200         Parameters:
1201             mesh: parent mesh object algorithm is assigned to
1202             geom: geometry (shape/sub-shape) algorithm is assigned to;
1203                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1204         """
1205         Mesh_Algorithm.__init__(self)
1206         
1207         shape = geom
1208         if not shape:
1209             shape = mesh.geom
1210         isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1211         if not isRadial:
1212             self.Create(mesh, geom, "Prism_3D")
1213             pass
1214         else:
1215             self.algoType = "RadialPrism_3D"
1216             self.Create(mesh, geom, "RadialPrism_3D")
1217             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1218             self.nbLayers = None
1219             pass
1220         pass
1221
1222     def Get3DHypothesis(self):
1223         """
1224         Returns: 
1225             3D hypothesis holding the 1D one
1226         """
1227         if self.algoType != "RadialPrism_3D":
1228             print("Prism_3D algorithm doesn't support any hypothesis")
1229             return None
1230         return self.distribHyp
1231
1232     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1233         """
1234         Private method creating a 1D hypothesis and storing it in the LayerDistribution
1235             hypothesis. 
1236
1237         Returns:
1238             the created hypothesis
1239         """
1240         if self.algoType != "RadialPrism_3D":
1241             print("Prism_3D algorithm doesn't support any hypothesis")
1242             return None
1243         if not self.nbLayers is None:
1244             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1245             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1246         self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1247         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1248         self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1249         if not self.distribHyp:
1250             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1251         self.distribHyp.SetLayerDistribution( hyp )
1252         return hyp
1253
1254     def NumberOfLayers(self, n, UseExisting=0):
1255         """
1256         Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1257             prisms to build between the inner and outer shells
1258
1259         Parameters:
1260             n: number of layers
1261             UseExisting: if ==true - searches for the existing hypothesis created with
1262                 the same parameters, else (default) - Create a new one
1263         """
1264         if self.algoType != "RadialPrism_3D":
1265             print("Prism_3D algorithm doesn't support any hypothesis")
1266             return None
1267         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1268         from salome.smesh.smeshBuilder import IsEqual
1269         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1270         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1271                                         CompareMethod=compFun)
1272         self.nbLayers.SetNumberOfLayers( n )
1273         return self.nbLayers
1274
1275     def LocalLength(self, l, p=1e-07):
1276         """
1277         Defines "LocalLength" hypothesis, specifying the segment length
1278             to build between the inner and the outer shells
1279
1280         Parameters:
1281             l: the length of segments
1282             p: the precision of rounding
1283         """
1284         if self.algoType != "RadialPrism_3D":
1285             print("Prism_3D algorithm doesn't support any hypothesis")
1286             return None
1287         hyp = self.OwnHypothesis("LocalLength", [l,p])
1288         hyp.SetLength(l)
1289         hyp.SetPrecision(p)
1290         return hyp
1291
1292     def NumberOfSegments(self, n, s=[]):
1293         """
1294         Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1295             prisms to build between the inner and the outer shells.
1296
1297         Parameters:
1298             n: the number of layers
1299             s: the scale factor (optional)
1300         """
1301         if self.algoType != "RadialPrism_3D":
1302             print("Prism_3D algorithm doesn't support any hypothesis")
1303             return None
1304         if not s:
1305             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1306         else:
1307             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1308             hyp.SetScaleFactor(s)
1309         hyp.SetNumberOfSegments(n)
1310         return hyp
1311
1312     def Arithmetic1D(self, start, end ):
1313         """
1314         Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1315             to build between the inner and the outer shells with a length that changes
1316             in arithmetic progression
1317
1318         Parameters:
1319             start:  the length of the first segment
1320             end:    the length of the last  segment
1321         """
1322         if self.algoType != "RadialPrism_3D":
1323             print("Prism_3D algorithm doesn't support any hypothesis")
1324             return None
1325         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1326         hyp.SetLength(start, 1)
1327         hyp.SetLength(end  , 0)
1328         return hyp
1329
1330     def GeometricProgression(self, start, ratio ):
1331         """
1332         Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1333             to build between the inner and the outer shells with a length that changes
1334             in Geometric progression
1335
1336         Parameters:
1337             start:  the length of the first segment
1338             ratio:  the common ratio of the geometric progression
1339         """
1340         if self.algoType != "RadialPrism_3D":
1341             print("Prism_3D algorithm doesn't support any hypothesis")
1342             return None
1343         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1344         hyp.SetStartLength( start )
1345         hyp.SetCommonRatio( ratio )
1346         return hyp
1347
1348     def StartEndLength(self, start, end):
1349         """
1350         Defines "StartEndLength" hypothesis, specifying distribution of segments
1351             to build between the inner and the outer shells as geometric length increasing
1352
1353         Parameters:
1354             start: for the length of the first segment
1355         end:   for the length of the last  segment
1356         """
1357         if self.algoType != "RadialPrism_3D":
1358             print("Prism_3D algorithm doesn't support any hypothesis")
1359             return None
1360         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1361         hyp.SetLength(start, 1)
1362         hyp.SetLength(end  , 0)
1363         return hyp
1364
1365     def AutomaticLength(self, fineness=0):
1366         """
1367         Defines "AutomaticLength" hypothesis, specifying the number of segments
1368             to build between the inner and outer shells
1369
1370         Parameters:
1371             fineness: defines the quality of the mesh within the range [0-1]
1372         """
1373         if self.algoType != "RadialPrism_3D":
1374             print("Prism_3D algorithm doesn't support any hypothesis")
1375             return None
1376         hyp = self.OwnHypothesis("AutomaticLength")
1377         hyp.SetFineness( fineness )
1378         return hyp
1379
1380     pass # end of StdMeshersBuilder_Prism3D class
1381
1382 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1383     """
1384     Defines Radial Prism 3D algorithm.
1385     It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1386     See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1387     build between the inner and outer shells.
1388     """
1389
1390     meshMethod = "Prism"
1391     """
1392     name of the dynamic method in smeshBuilder.Mesh class
1393     """
1394     algoType   = "RadialPrism_3D"
1395     """
1396     type of algorithm used with helper function in smeshBuilder.Mesh class
1397     """
1398     docHelper  = "Create Raial Prism 3D algorithm for volumes"
1399     """
1400     doc string of the method
1401     """
1402
1403     def __init__(self, mesh, geom=0):
1404         """
1405         Private constructor.
1406
1407         Parameters:
1408             mesh: parent mesh object algorithm is assigned to
1409             geom: geometry (shape/sub-shape) algorithm is assigned to;
1410             if it is :code:`0` (default), the algorithm is assigned to the main shape
1411         """
1412         Mesh_Algorithm.__init__(self)
1413         
1414         shape = geom
1415         if not shape:
1416             shape = mesh.geom
1417         self.Create(mesh, geom, "RadialPrism_3D")
1418         self.distribHyp = None
1419         self.nbLayers = None
1420         return
1421
1422 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1423     """
1424     Base class for algorithms supporting radial distribution hypotheses
1425     """ 
1426
1427     def __init__(self):
1428         Mesh_Algorithm.__init__(self)
1429
1430         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1431         self.nbLayers = None
1432         pass
1433
1434     def Get2DHypothesis(self):
1435         """
1436         Returns:
1437             2D hypothesis holding the 1D one
1438         """
1439         if not self.distribHyp:
1440             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1441         return self.distribHyp
1442
1443     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1444         """
1445         Private method creating a 1D hypothesis and storing it in the LayerDistribution
1446             hypothesis. 
1447
1448         Returns: 
1449             the created hypothesis
1450         """
1451         if self.nbLayers:
1452             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1453         if self.distribHyp is None:
1454             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1455         else:
1456             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1457         self.mesh.smeshpyD.SetEnablePublish( False )
1458         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1459         self.mesh.smeshpyD.SetEnablePublish( True )
1460         self.distribHyp.SetLayerDistribution( hyp )
1461         return hyp
1462
1463     def NumberOfLayers(self, n, UseExisting=0):
1464         """
1465         Defines "NumberOfLayers" hypothesis, specifying the number of layers
1466
1467         Parameters:
1468             n: number of layers
1469             UseExisting: if ==true - searches for the existing hypothesis created with
1470                 the same parameters, else (default) - Create a new one
1471         """
1472         if self.distribHyp:
1473             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1474         from salome.smesh.smeshBuilder import IsEqual
1475         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1476         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1477                                         CompareMethod=compFun)
1478         self.nbLayers.SetNumberOfLayers( n )
1479         return self.nbLayers
1480
1481     def LocalLength(self, l, p=1e-07):
1482         """
1483         Defines "LocalLength" hypothesis, specifying the segment length
1484
1485         Parameters:
1486             l: the length of segments
1487             p: the precision of rounding
1488         """
1489         hyp = self.OwnHypothesis("LocalLength", [l,p])
1490         hyp.SetLength(l)
1491         hyp.SetPrecision(p)
1492         return hyp
1493
1494     def NumberOfSegments(self, n, s=[]):
1495         """
1496         Defines "NumberOfSegments" hypothesis, specifying the number of layers
1497
1498         Parameters:
1499             n: the number of layers
1500             s: the scale factor (optional)
1501         """
1502         if s == []:
1503             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1504         else:
1505             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1506             hyp.SetDistrType( 1 )
1507             hyp.SetScaleFactor(s)
1508         hyp.SetNumberOfSegments(n)
1509         return hyp
1510
1511     def Arithmetic1D(self, start, end ):
1512         """
1513         Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1514             with a length that changes in arithmetic progression
1515
1516         Parameters:
1517             start:  the length of the first segment
1518             end:    the length of the last  segment
1519         """
1520         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1521         hyp.SetLength(start, 1)
1522         hyp.SetLength(end  , 0)
1523         return hyp
1524
1525     def GeometricProgression(self, start, ratio ):
1526         """
1527         Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1528             with a length that changes in Geometric progression
1529
1530         Parameters:
1531             start:  the length of the first segment
1532             ratio:  the common ratio of the geometric progression
1533         """
1534         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1535         hyp.SetStartLength( start )
1536         hyp.SetCommonRatio( ratio )
1537         return hyp
1538
1539     def StartEndLength(self, start, end):
1540         """
1541         Defines "StartEndLength" hypothesis, specifying distribution of segments
1542             as geometric length increasing
1543
1544         Parameters:
1545             start: for the length of the first segment
1546             end:   for the length of the last  segment
1547         """
1548         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1549         hyp.SetLength(start, 1)
1550         hyp.SetLength(end  , 0)
1551         return hyp
1552
1553     def AutomaticLength(self, fineness=0):
1554         """
1555         Defines "AutomaticLength" hypothesis, specifying the number of segments
1556
1557         Parameters:
1558             fineness: defines the quality of the mesh within the range [0-1]
1559         """
1560         hyp = self.OwnHypothesis("AutomaticLength")
1561         hyp.SetFineness( fineness )
1562         return hyp
1563
1564     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1565
1566 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1567     """
1568     Defines a Radial Quadrangle 1D-2D algorithm.
1569     It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1570     """
1571
1572     meshMethod = "Quadrangle"
1573     """
1574     name of the dynamic method in smeshBuilder.Mesh class
1575     """
1576     algoType   = RADIAL_QUAD
1577     """
1578     type of algorithm used with helper function in smeshBuilder.Mesh class
1579     """
1580     docHelper  = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1581     """
1582     doc string of the method
1583     """
1584
1585     def __init__(self, mesh, geom=0):
1586         """
1587         Private constructor.
1588
1589         Parameters:
1590             mesh: parent mesh object algorithm is assigned to
1591             geom: geometry (shape/sub-shape) algorithm is assigned to;
1592                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1593         """
1594         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1595         self.Create(mesh, geom, self.algoType)
1596
1597         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1598         self.nbLayers = None
1599         pass
1600
1601
1602 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1603     """
1604     Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1605     It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1606     """
1607
1608     meshMethod = "Quadrangle"
1609     """
1610     name of the dynamic method in smeshBuilder.Mesh class
1611     """
1612     algoType   = QUAD_MA_PROJ
1613     """
1614     type of algorithm used with helper function in smeshBuilder.Mesh class
1615     """
1616     docHelper  = "Create quadrangle 1D-2D algorithm for faces"
1617     """
1618     doc string of the method
1619     """
1620
1621     def __init__(self, mesh, geom=0):
1622         """
1623         Private constructor.
1624
1625         Parameters:
1626             mesh: parent mesh object algorithm is assigned to
1627             geom: geometry (shape/sub-shape) algorithm is assigned to;
1628                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1629         """
1630         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1631         self.Create(mesh, geom, self.algoType)
1632         pass
1633
1634     pass
1635
1636 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1637     """ Defines a Polygon Per Face 2D algorithm.
1638         It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1639     """
1640
1641     meshMethod = "Polygon"
1642     """
1643     name of the dynamic method in smeshBuilder.Mesh class
1644     """
1645     algoType   = POLYGON
1646     """
1647     type of algorithm used with helper function in smeshBuilder.Mesh class
1648     """
1649     isDefault  = True
1650     """
1651     flag pointing whether this algorithm should be used by default in dynamic method
1652         of smeshBuilder.Mesh class
1653     """
1654     docHelper  = "Create polygon 2D algorithm for faces"
1655     """
1656     doc string of the method
1657     """
1658
1659     def __init__(self, mesh, geom=0):
1660         """
1661         Private constructor.
1662
1663         Parameters:
1664             mesh: parent mesh object algorithm is assigned to
1665             geom: geometry (shape/sub-shape) algorithm is assigned to;
1666                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1667         """
1668         Mesh_Algorithm.__init__(self)
1669         self.Create(mesh, geom, self.algoType)
1670         pass
1671
1672     pass
1673
1674 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1675     """ Defines a Use Existing Elements 1D algorithm.
1676
1677     It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1678     """
1679     
1680
1681     meshMethod = "UseExisting1DElements"
1682     """
1683     name of the dynamic method in smeshBuilder.Mesh class
1684     """
1685     algoType   = "Import_1D"
1686     """
1687     type of algorithm used with helper function in smeshBuilder.Mesh class
1688     """
1689     isDefault  = True
1690     """
1691     flag pointing whether this algorithm should be used by default in dynamic method
1692         of smeshBuilder.Mesh class
1693     """
1694     docHelper  = "Create 1D algorithm for edges with reusing of existing mesh elements"
1695     """
1696     doc string of the method
1697     """
1698
1699     def __init__(self, mesh, geom=0):
1700         """
1701         Private constructor.
1702
1703         Parameters:
1704             mesh: parent mesh object algorithm is assigned to
1705             geom: geometry (shape/sub-shape) algorithm is assigned to;
1706                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1707         """
1708         Mesh_Algorithm.__init__(self)
1709         self.Create(mesh, geom, self.algoType)
1710         pass
1711
1712     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1713         """
1714         Defines "Source edges" hypothesis, specifying groups of edges to import
1715
1716         Parameters:
1717             groups: list of groups of edges
1718             toCopyMesh: if True, the whole mesh *groups* belong to is imported
1719             toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1720             UseExisting: if ==true - searches for the existing hypothesis created with
1721                 the same parameters, else (default) - Create a new one
1722         """
1723         for group in groups:
1724             from salome.smesh.smeshBuilder import AssureGeomPublished
1725             AssureGeomPublished( self.mesh, group )
1726         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1727                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1728         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1729                               UseExisting=UseExisting, CompareMethod=compFun)
1730         hyp.SetSourceEdges(groups)
1731         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1732         return hyp
1733
1734     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1735
1736 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1737     """ Defines a Use Existing Elements 1D-2D algorithm.
1738
1739     It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1740     """
1741     
1742
1743     meshMethod = "UseExisting2DElements"
1744     """
1745     name of the dynamic method in smeshBuilder.Mesh class
1746     """
1747     algoType   = "Import_1D2D"
1748     """
1749     type of algorithm used with helper function in smeshBuilder.Mesh class
1750     """
1751     isDefault  = True
1752     """
1753     flag pointing whether this algorithm should be used by default in dynamic method
1754         of smeshBuilder.Mesh class
1755     """
1756     docHelper  = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1757     """
1758     doc string of the method
1759     """
1760
1761     def __init__(self, mesh, geom=0):
1762         """
1763         Private constructor.
1764
1765         Parameters:
1766             mesh: parent mesh object algorithm is assigned to
1767             geom: geometry (shape/sub-shape) algorithm is assigned to;
1768                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1769         """
1770         Mesh_Algorithm.__init__(self)
1771         self.Create(mesh, geom, self.algoType)
1772         pass
1773
1774     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1775         """
1776         Defines "Source faces" hypothesis, specifying groups of faces to import
1777
1778         Parameters:
1779             groups: list of groups of faces
1780             toCopyMesh: if True, the whole mesh *groups* belong to is imported
1781             toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1782             UseExisting: if ==true - searches for the existing hypothesis created with
1783                 the same parameters, else (default) - Create a new one
1784         """
1785         import SMESH
1786         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1787                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1788         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1789                               UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1790         if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1791             groups = [groups]
1792         hyp.SetSourceFaces(groups)
1793         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1794         self.mesh.AddHypothesis(hyp, self.geom)
1795         return hyp
1796
1797     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1798
1799 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1800     """ Defines a Body Fitting 3D algorithm.
1801
1802     It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1803     """
1804     
1805
1806     meshMethod = "BodyFitted"
1807     """
1808     name of the dynamic method in smeshBuilder.Mesh class
1809     """
1810     algoType   = "Cartesian_3D"
1811     """
1812     type of algorithm used with helper function in smeshBuilder.Mesh class
1813     """
1814     isDefault  = True
1815     """
1816     flag pointing whether this algorithm should be used by default in dynamic method
1817         of smeshBuilder.Mesh class
1818     """
1819     docHelper  = "Create Body Fitting 3D algorithm for volumes"
1820     """
1821     doc string of the method
1822     """
1823
1824     def __init__(self, mesh, geom=0):
1825         """
1826         Private constructor.
1827
1828         Parameters:
1829             mesh: parent mesh object algorithm is assigned to
1830             geom: geometry (shape/sub-shape) algorithm is assigned to;
1831                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1832         """
1833         self.Create(mesh, geom, self.algoType)
1834         self.hyp = None
1835         pass
1836
1837     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1838         """
1839         Defines "Body Fitting parameters" hypothesis
1840
1841         Parameters:
1842             xGridDef: is definition of the grid along the X asix.
1843                 It can be in either of two following forms:
1844
1845                     - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1846                     - Functions f(t) defining grid spacing at each point on grid axis. If there are
1847                         several functions, they must be accompanied by relative coordinates of
1848                         points dividing the whole shape into ranges where the functions apply; points
1849                         coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1850                         function f(t) varies from 0.0 to 1.0 within a shape range. 
1851
1852         Examples:
1853             "10.5" - defines a grid with a constant spacing
1854             [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1855
1856         Parameters:
1857             yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1858             zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1859             sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1860                 a polyhedron of size less than hexSize/sizeThreshold is not created.
1861             implEdges: enables implementation of geometrical edges into the mesh.
1862         """
1863         if not self.hyp:
1864             compFun = lambda hyp, args: False
1865             self.hyp = self.Hypothesis("CartesianParameters3D",
1866                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1867                                        UseExisting=False, CompareMethod=compFun)
1868         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1869             self.mesh.AddHypothesis( self.hyp, self.geom )
1870
1871         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1872             if not gridDef: raise ValueError("Empty grid definition")
1873             if isinstance( gridDef, str ):
1874                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1875             elif isinstance( gridDef[0], str ):
1876                 self.hyp.SetGridSpacing( gridDef, [], axis )
1877             elif isinstance( gridDef[0], int ) or \
1878                  isinstance( gridDef[0], float ):
1879                 self.hyp.SetGrid(gridDef, axis )
1880             else:
1881                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1882         self.hyp.SetSizeThreshold( sizeThreshold )
1883         self.hyp.SetToAddEdges( implEdges )
1884         return self.hyp
1885
1886     def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1887         """
1888         Defines custom directions of axes of the grid
1889
1890         Parameters:
1891             xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1892             yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1893             zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1894         """
1895         import GEOM
1896         if hasattr( xAxis, "__getitem__" ):
1897             xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1898         elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1899             xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1900         if hasattr( yAxis, "__getitem__" ):
1901             yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1902         elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1903             yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1904         if hasattr( zAxis, "__getitem__" ):
1905             zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1906         elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1907             zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1908         if not self.hyp:
1909             self.hyp = self.Hypothesis("CartesianParameters3D")
1910         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1911             self.mesh.AddHypothesis( self.hyp, self.geom )
1912         self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1913         return self.hyp
1914
1915     def SetOptimalAxesDirs(self, isOrthogonal=True):
1916         """
1917         Automatically defines directions of axes of the grid at which
1918             a number of generated hexahedra is maximal
1919
1920         Parameters:
1921             isOrthogonal: defines whether the axes mush be orthogonal
1922         """
1923         if not self.hyp:
1924             self.hyp = self.Hypothesis("CartesianParameters3D")
1925         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1926             self.mesh.AddHypothesis( self.hyp, self.geom )
1927         x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1928         self.hyp.SetAxesDirs( x,y,z )
1929         return self.hyp
1930
1931     def SetFixedPoint( self, p, toUnset=False ):
1932         """
1933         Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1934             through the fixed point in each direction at which the grid is defined
1935             by spacing
1936
1937         Parameters:
1938             p: coordinates of the fixed point. Either SMESH.PointStruct or
1939                 a vertex or 3 components of coordinates.
1940             toUnset: defines whether the fixed point is defined or removed.
1941         """
1942         import SMESH, GEOM
1943         if toUnset:
1944             if not self.hyp: return
1945             p = SMESH.PointStruct(0,0,0)
1946         elif hasattr( p, "__getitem__" ):
1947             p = SMESH.PointStruct( p[0],p[1],p[2] )
1948         elif isinstance( p, GEOM._objref_GEOM_Object ):
1949             p = self.mesh.smeshpyD.GetPointStruct( p )
1950         if not self.hyp:
1951             self.hyp = self.Hypothesis("CartesianParameters3D")
1952         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1953             self.mesh.AddHypothesis( self.hyp, self.geom )
1954         self.hyp.SetFixedPoint( p, toUnset )
1955         return self.hyp
1956         
1957
1958     pass # end of StdMeshersBuilder_Cartesian_3D class
1959
1960 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1961     """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1962         segments usable by 2D algorithms.
1963
1964     It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1965     """
1966
1967
1968     meshMethod = "UseExistingSegments"
1969     """
1970     name of the dynamic method in smeshBuilder.Mesh class
1971     """
1972     algoType   = "UseExisting_1D"
1973     """
1974     type of algorithm used with helper function in smeshBuilder.Mesh class
1975     """
1976     docHelper  = "Create 1D algorithm allowing batch meshing of edges"
1977     """
1978     doc string of the method
1979     """
1980
1981     def __init__(self, mesh, geom=0):
1982         """
1983         Private constructor.
1984
1985         Parameters:
1986             mesh: parent mesh object algorithm is assigned to
1987             geom: geometry (shape/sub-shape) algorithm is assigned to;
1988                 if it is :code:`0` (default), the algorithm is assigned to the main shape
1989         """
1990         self.Create(mesh, geom, self.algoType)
1991         pass
1992
1993     pass # end of StdMeshersBuilder_UseExisting_1D class
1994
1995 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1996     """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1997     faces usable by 3D algorithms.
1998
1999     It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
2000     """
2001     
2002
2003     meshMethod = "UseExistingFaces"
2004     """
2005     name of the dynamic method in smeshBuilder.Mesh class
2006     """
2007     algoType   = "UseExisting_2D"
2008     """
2009     type of algorithm used with helper function in smeshBuilder.Mesh class
2010     """
2011     docHelper  = "Create 2D algorithm allowing batch meshing of faces"
2012     """
2013     doc string of the method
2014     """
2015
2016     def __init__(self, mesh, geom=0):
2017         """
2018         Private constructor.
2019
2020         Parameters:
2021             mesh: parent mesh object algorithm is assigned to
2022             geom: geometry (shape/sub-shape) algorithm is assigned to;
2023             if it is :code:`0` (default), the algorithm is assigned to the main shape
2024         """
2025         self.Create(mesh, geom, self.algoType)
2026         pass
2027
2028     pass # end of StdMeshersBuilder_UseExisting_2D class