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