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