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