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