Salome HOME
203a9ff480e4b8483270e56d4f1f5fc3da6dd428
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersBuilder.py
1 # Copyright (C) 2007-2016  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 # @package StdMeshersBuilder
22 # Python API for the standard meshing plug-in module.
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 ## Algorithm type: Regular 1D algorithm, see StdMeshersBuilder_Segment
34 REGULAR     = "Regular_1D"
35 ## Algorithm type: Python 1D algorithm, see StdMeshersBuilder_Segment_Python
36 PYTHON      = "Python_1D"
37 ## Algorithm type: Composite segment 1D algorithm, see StdMeshersBuilder_CompositeSegment
38 COMPOSITE   = "CompositeSegment_1D"
39 ## Algorithm type: Triangle MEFISTO 2D algorithm, see StdMeshersBuilder_Triangle_MEFISTO
40 MEFISTO     = "MEFISTO_2D"
41 ## Algorithm type: Hexahedron 3D (i-j-k) algorithm, see StdMeshersBuilder_Hexahedron
42 Hexa        = "Hexa_3D"
43 ## Algorithm type: Quadrangle 2D algorithm, see StdMeshersBuilder_Quadrangle
44 QUADRANGLE  = "Quadrangle_2D"
45 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersBuilder_RadialQuadrangle1D2D
46 RADIAL_QUAD = "RadialQuadrangle_1D2D"
47 ## Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see StdMeshersBuilder_QuadMA_1D2D
48 QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
49 ## Algorithm type: Polygon Per Face 2D algorithm, see StdMeshersBuilder_PolygonPerFace
50 POLYGON     = "PolygonPerFace_2D"
51
52 # import items of enums
53 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
54 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
55
56 #----------------------
57 # Algorithms
58 #----------------------
59
60 ## Defines segment 1D algorithm for edges discretization.
61 #
62 #  It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
63 #
64 #  @ingroup l3_algos_basic
65 class StdMeshersBuilder_Segment(Mesh_Algorithm):
66
67     ## name of the dynamic method in smeshBuilder.Mesh class
68     #  @internal
69     meshMethod = "Segment"
70     ## type of algorithm used with helper function in smeshBuilder.Mesh class
71     #  @internal
72     algoType   = REGULAR
73     ## flag pointing whether this algorithm should be used by default in dynamic method
74     #  of smeshBuilder.Mesh class
75     #  @internal
76     isDefault  = True
77     ## doc string of the method
78     #  @internal
79     docHelper  = "Creates segment 1D algorithm for edges"
80
81     ## Private constructor.
82     #  @param mesh parent mesh object algorithm is assigned to
83     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
84     #              if it is @c 0 (default), the algorithm is assigned to the main shape
85     def __init__(self, mesh, geom=0):
86         Mesh_Algorithm.__init__(self)
87         self.Create(mesh, geom, self.algoType)
88         pass
89
90     ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
91     #  @param l for the length of segments that cut an edge
92     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
93     #                    the same parameters, else (default) - creates a new one
94     #  @param p precision, used for calculation of the number of segments.
95     #           The precision should be a positive, meaningful value within the range [0,1].
96     #           In general, the number of segments is calculated with the formula:
97     #           nb = ceil((edge_length / l) - p)
98     #           Function ceil rounds its argument to the higher integer.
99     #           So, p=0 means rounding of (edge_length / l) to the higher integer,
100     #               p=0.5 means rounding of (edge_length / l) to the nearest integer,
101     #               p=1 means rounding of (edge_length / l) to the lower integer.
102     #           Default value is 1e-07.
103     #  @return an instance of StdMeshers_LocalLength hypothesis
104     #  @ingroup l3_hypos_1dhyps
105     def LocalLength(self, l, UseExisting=0, p=1e-07):
106         from salome.smesh.smeshBuilder import IsEqual
107         comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
108         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
109         hyp.SetLength(l)
110         hyp.SetPrecision(p)
111         return hyp
112
113     ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
114     #  @param length is optional maximal allowed length of segment, if it is omitted
115     #                the preestimated length is used that depends on geometry size
116     #  @param UseExisting if ==true - searches for an existing hypothesis created with
117     #                     the same parameters, else (default) - creates a new one
118     #  @return an instance of StdMeshers_MaxLength hypothesis
119     #  @ingroup l3_hypos_1dhyps
120     def MaxSize(self, length=0.0, UseExisting=0):
121         hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
122         if length > 0.0:
123             # set given length
124             hyp.SetLength(length)
125         if not UseExisting:
126             # set preestimated length
127             gen = self.mesh.smeshpyD
128             initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
129                                                        self.mesh.GetMesh(), self.mesh.GetShape(),
130                                                        False) # <- byMesh
131             preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
132             if preHyp:
133                 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
134                 pass
135             pass
136         hyp.SetUsePreestimatedLength( length == 0.0 )
137         return hyp
138
139     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
140     #  @param n for the number of segments that cut an edge
141     #  @param s for the scale factor (optional)
142     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
143     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
144     #  @param UseExisting if ==true - searches for an existing hypothesis created with
145     #                     the same parameters, else (default) - create a new one
146     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
147     #  @ingroup l3_hypos_1dhyps
148     def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
149         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
150             reversedEdges, UseExisting = [], reversedEdges
151         entry = self.MainShapeEntry()
152         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
153         if not s:
154             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
155                                   UseExisting=UseExisting,
156                                   CompareMethod=self._compareNumberOfSegments)
157         else:
158             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
159                                   UseExisting=UseExisting,
160                                   CompareMethod=self._compareNumberOfSegments)
161             hyp.SetScaleFactor(s)
162         hyp.SetNumberOfSegments(n)
163         hyp.SetReversedEdges( reversedEdgeInd )
164         hyp.SetObjectEntry( entry )
165         return hyp
166
167     ## Private method
168     #  
169     #  Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
170     def _compareNumberOfSegments(self, hyp, args):
171         if hyp.GetNumberOfSegments() == args[0]:
172             if len(args) == 3:
173                 if hyp.GetReversedEdges() == args[1]:
174                     if not args[1] or hyp.GetObjectEntry() == args[2]:
175                         return True
176             else:
177                 from salome.smesh.smeshBuilder import IsEqual
178                 if hyp.GetReversedEdges() == args[2]:
179                     if not args[2] or hyp.GetObjectEntry() == args[3]:
180                         if hyp.GetDistrType() == 1:
181                             if IsEqual(hyp.GetScaleFactor(), args[1]):
182                                 return True
183         return False
184
185     ## Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
186     #  within the given range and considering (1) deflection of segments from the edge
187     #  and (2) distance from segments to closest edges and faces to have segment length
188     #  not longer than two times shortest distances to edges and faces.
189     #  @param minSize defines the minimal allowed segment length
190     #  @param maxSize defines the maximal allowed segment length
191     #  @param deflection defines the maximal allowed distance from a segment to an edge
192     #  @param UseExisting if ==true - searches for an existing hypothesis created with
193     #                     the same parameters, else (default) - creates a new one
194     #  @return an instance of StdMeshers_Adaptive1D hypothesis
195     #  @ingroup l3_hypos_1dhyps
196     def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
197         from salome.smesh.smeshBuilder import IsEqual
198         compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
199                                       IsEqual(hyp.GetMaxSize(), args[1]) and \
200                                       IsEqual(hyp.GetDeflection(), args[2]))
201         hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
202                               UseExisting=UseExisting, CompareMethod=compFun)
203         hyp.SetMinSize(minSize)
204         hyp.SetMaxSize(maxSize)
205         hyp.SetDeflection(deflection)
206         return hyp
207
208     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
209     #  that changes in arithmetic progression
210     #  @param start defines the length of the first segment
211     #  @param end   defines the length of the last  segment
212     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
213     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
214     #  @param UseExisting if ==true - searches for an existing hypothesis created with
215     #                     the same parameters, else (default) - creates a new one
216     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
217     #  @ingroup l3_hypos_1dhyps
218     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
219         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
220             reversedEdges, UseExisting = [], reversedEdges
221         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
222         entry = self.MainShapeEntry()
223         from salome.smesh.smeshBuilder import IsEqual
224         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
225                                       IsEqual(hyp.GetLength(0), args[1]) and \
226                                       hyp.GetReversedEdges() == args[2]  and \
227                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
228         hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
229                               UseExisting=UseExisting, CompareMethod=compFun)
230         hyp.SetStartLength(start)
231         hyp.SetEndLength(end)
232         hyp.SetReversedEdges( reversedEdgeInd )
233         hyp.SetObjectEntry( entry )
234         return hyp
235
236     ## Defines "GeometricProgression" hypothesis to cut an edge in several
237     #  segments with a length that changes in Geometric progression
238     #  @param start defines the length of the first segment
239     #  @param ratio defines the common ratio of the geometric progression
240     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
241     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
242     #  @param UseExisting if ==true - searches for an existing hypothesis created with
243     #                     the same parameters, else (default) - creates a new one
244     #  @return an instance of StdMeshers_Geometric1D hypothesis
245     #  @ingroup l3_hypos_1dhyps
246     def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
247         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
248         entry = self.MainShapeEntry()
249         from salome.smesh.smeshBuilder import IsEqual
250         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
251                                       IsEqual(hyp.GetLength(0), args[1]) and \
252                                       hyp.GetReversedEdges() == args[2]  and \
253                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
254         hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
255                               UseExisting=UseExisting, CompareMethod=compFun)
256         hyp.SetStartLength( start )
257         hyp.SetCommonRatio( ratio )
258         hyp.SetReversedEdges( reversedEdgeInd )
259         hyp.SetObjectEntry( entry )
260         return hyp
261
262     ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
263     # on curve from 0 to 1 (additionally it is neecessary to check
264     # orientation of edges and create list of reversed edges if it is
265     # needed) and sets numbers of segments between given points (default
266     # values are equals 1
267     #  @param points defines the list of parameters on curve
268     #  @param nbSegs defines the list of numbers of segments
269     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
270     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
271     #  @param UseExisting if ==true - searches for an existing hypothesis created with
272     #                     the same parameters, else (default) - creates a new one
273     #  @return an instance of StdMeshers_FixedPoints1D hypothesis
274     #  @ingroup l3_hypos_1dhyps
275     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
276         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
277             reversedEdges, UseExisting = [], reversedEdges
278         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
279         entry = self.MainShapeEntry()
280         compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
281                                       hyp.GetNbSegments() == args[1] and \
282                                       hyp.GetReversedEdges() == args[2] and \
283                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
284         hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
285                               UseExisting=UseExisting, CompareMethod=compFun)
286         hyp.SetPoints(points)
287         hyp.SetNbSegments(nbSegs)
288         hyp.SetReversedEdges(reversedEdgeInd)
289         hyp.SetObjectEntry(entry)
290         return hyp
291
292     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
293     #  @param start defines the length of the first segment
294     #  @param end   defines the length of the last  segment
295     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
296     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
297     #  @param UseExisting if ==true - searches for an existing hypothesis created with
298     #                     the same parameters, else (default) - creates a new one
299     #  @return an instance of StdMeshers_StartEndLength hypothesis
300     #  @ingroup l3_hypos_1dhyps
301     def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
302         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
303             reversedEdges, UseExisting = [], reversedEdges
304         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
305         entry = self.MainShapeEntry()
306         from salome.smesh.smeshBuilder import IsEqual
307         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
308                                       IsEqual(hyp.GetLength(0), args[1]) and \
309                                       hyp.GetReversedEdges() == args[2]  and \
310                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
311         hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
312                               UseExisting=UseExisting, CompareMethod=compFun)
313         hyp.SetStartLength(start)
314         hyp.SetEndLength(end)
315         hyp.SetReversedEdges( reversedEdgeInd )
316         hyp.SetObjectEntry( entry )
317         return hyp
318
319     ## Defines "Deflection1D" hypothesis
320     #  @param d for the deflection
321     #  @param UseExisting if ==true - searches for an existing hypothesis created with
322     #                     the same parameters, else (default) - create a new one
323     #  @ingroup l3_hypos_1dhyps
324     def Deflection1D(self, d, UseExisting=0):
325         from salome.smesh.smeshBuilder import IsEqual
326         compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
327         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
328         hyp.SetDeflection(d)
329         return hyp
330
331     ## Defines "Propagation" hypothesis that propagates 1D hypotheses
332     #  from an edge where this hypothesis is assigned to
333     #  on all other edges that are at the opposite side in case of quadrangular faces
334     #  This hypothesis should be assigned to an edge to propagate a hypothesis from.
335     #  @ingroup l3_hypos_additi
336     def Propagation(self):
337         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
338
339     ## Defines "Propagation of Node Distribution" hypothesis that propagates
340     #  distribution of nodes from an edge where this hypothesis is assigned to,
341     #  to opposite edges of quadrangular faces, so that number of segments on all these
342     #  edges will be the same, as well as relations between segment lengths. 
343     #  @ingroup l3_hypos_additi
344     def PropagationOfDistribution(self):
345         return self.Hypothesis("PropagOfDistribution", UseExisting=1,
346                                CompareMethod=self.CompareEqualHyp)
347
348     ## Defines "AutomaticLength" hypothesis
349     #  @param fineness for the fineness [0-1]
350     #  @param UseExisting if ==true - searches for an existing hypothesis created with the
351     #                     same parameters, else (default) - create a new one
352     #  @ingroup l3_hypos_1dhyps
353     def AutomaticLength(self, fineness=0, UseExisting=0):
354         from salome.smesh.smeshBuilder import IsEqual
355         compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
356         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
357                               CompareMethod=compFun)
358         hyp.SetFineness( fineness )
359         return hyp
360
361     ## Defines "SegmentLengthAroundVertex" hypothesis
362     #  @param length for the segment length
363     #  @param vertex for the length localization: the vertex index [0,1] | vertex object.
364     #         Any other integer value means that the hypothesis will be set on the
365     #         whole 1D shape, where Mesh_Segment algorithm is assigned.
366     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
367     #                   the same parameters, else (default) - creates a new one
368     #  @ingroup l3_algos_segmarv
369     def LengthNearVertex(self, length, vertex=0, UseExisting=0):
370         import types
371         store_geom = self.geom
372         if type(vertex) is types.IntType:
373             if vertex == 0 or vertex == 1:
374                 from salome.geom import geomBuilder
375                 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
376                 self.geom = vertex
377                 pass
378             pass
379         else:
380             self.geom = vertex
381             pass
382         # 0D algorithm
383         if self.geom is None:
384             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
385         from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
386         AssureGeomPublished( self.mesh, self.geom )
387         name = GetName(self.geom)
388
389         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
390         if algo is None:
391             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
392             pass
393         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
394         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
395         #
396         from salome.smesh.smeshBuilder import IsEqual
397         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
398         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
399                               CompareMethod=comFun)
400         self.geom = store_geom
401         hyp.SetLength( length )
402         return hyp
403
404     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
405     #  If the 2D mesher sees that all boundary edges are quadratic,
406     #  it generates quadratic faces, else it generates linear faces using
407     #  medium nodes as if they are vertices.
408     #  The 3D mesher generates quadratic volumes only if all boundary faces
409     #  are quadratic, else it fails.
410     #
411     #  @ingroup l3_hypos_additi
412     def QuadraticMesh(self):
413         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
414         return hyp
415
416     pass # end of StdMeshersBuilder_Segment class
417
418 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
419 #
420 #  It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
421 #
422 #  @ingroup l3_algos_basic
423 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
424
425     ## name of the dynamic method in smeshBuilder.Mesh class
426     #  @internal
427     meshMethod = "Segment"
428     ## type of algorithm used with helper function in smeshBuilder.Mesh class
429     #  @internal
430     algoType   = COMPOSITE
431     ## flag pointing whether this algorithm should be used by default in dynamic method
432     #  of smeshBuilder.Mesh class
433     #  @internal
434     isDefault  = False
435     ## doc string of the method
436     #  @internal
437     docHelper  = "Creates segment 1D algorithm for edges"
438
439     ## Private constructor.
440     #  @param mesh parent mesh object algorithm is assigned to
441     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
442     #              if it is @c 0 (default), the algorithm is assigned to the main shape
443     def __init__(self, mesh, geom=0):
444         self.Create(mesh, geom, self.algoType)
445         pass
446
447     pass # end of StdMeshersBuilder_CompositeSegment class
448
449 ## Defines a segment 1D algorithm for discretization of edges with Python function
450 #
451 #  It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
452 #
453 #  @ingroup l3_algos_basic
454 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
455
456     ## name of the dynamic method in smeshBuilder.Mesh class
457     #  @internal
458     meshMethod = "Segment"
459     ## type of algorithm used with helper function in smeshBuilder.Mesh class
460     #  @internal
461     algoType   = PYTHON
462     ## doc string of the method
463     #  @internal
464     docHelper  = "Creates segment 1D algorithm for edges"
465
466     ## Private constructor.
467     #  @param mesh parent mesh object algorithm is assigned to
468     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
469     #              if it is @c 0 (default), the algorithm is assigned to the main shape
470     def __init__(self, mesh, geom=0):
471         import Python1dPlugin
472         self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
473         pass
474
475     ## Defines "PythonSplit1D" hypothesis
476     #  @param n for the number of segments that cut an edge
477     #  @param func for the python function that calculates the length of all segments
478     #  @param UseExisting if ==true - searches for the existing hypothesis created with
479     #                     the same parameters, else (default) - creates a new one
480     #  @ingroup l3_hypos_1dhyps
481     def PythonSplit1D(self, n, func, UseExisting=0):
482         compFun = lambda hyp, args: False
483         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
484                               UseExisting=UseExisting, CompareMethod=compFun)
485         hyp.SetNumberOfSegments(n)
486         hyp.SetPythonLog10RatioFunction(func)
487         return hyp
488
489     pass # end of StdMeshersBuilder_Segment_Python class
490
491 ## Triangle MEFISTO 2D algorithm
492 #
493 #  It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
494 #
495 #  @ingroup l3_algos_basic
496 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
497
498     ## name of the dynamic method in smeshBuilder.Mesh class
499     #  @internal
500     meshMethod = "Triangle"
501     ## type of algorithm used with helper function in smeshBuilder.Mesh class
502     #  @internal
503     algoType   = MEFISTO
504     ## flag pointing whether this algorithm should be used by default in dynamic method
505     #  of smeshBuilder.Mesh class
506     #  @internal
507     isDefault  = True
508     ## doc string of the method
509     #  @internal
510     docHelper  = "Creates triangle 2D algorithm for faces"
511
512     ## Private constructor.
513     #  @param mesh parent mesh object algorithm is assigned to
514     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
515     #              if it is @c 0 (default), the algorithm is assigned to the main shape
516     def __init__(self, mesh, geom=0):
517         Mesh_Algorithm.__init__(self)
518         self.Create(mesh, geom, self.algoType)
519         pass
520
521     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
522     #  @param area for the maximum area of each triangle
523     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
524     #                     same parameters, else (default) - creates a new one
525     #
526     #  @ingroup l3_hypos_2dhyps
527     def MaxElementArea(self, area, UseExisting=0):
528         from salome.smesh.smeshBuilder import IsEqual
529         comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
530         hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
531                               CompareMethod=comparator)
532         hyp.SetMaxElementArea(area)
533         return hyp
534
535     ## Defines "LengthFromEdges" hypothesis to build triangles
536     #  based on the length of the edges taken from the wire
537     #
538     #  @ingroup l3_hypos_2dhyps
539     def LengthFromEdges(self):
540         hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
541         return hyp
542
543     pass # end of StdMeshersBuilder_Triangle_MEFISTO class
544
545 ## Defines a quadrangle 2D algorithm
546
547 #  It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
548 #
549 #  @ingroup l3_algos_basic
550 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
551
552     ## name of the dynamic method in smeshBuilder.Mesh class
553     #  @internal
554     meshMethod = "Quadrangle"
555     ## type of algorithm used with helper function in smeshBuilder.Mesh class
556     #  @internal
557     algoType   = QUADRANGLE
558     ## flag pointing whether this algorithm should be used by default in dynamic method
559     #  of smeshBuilder.Mesh class
560     #  @internal
561     isDefault  = True
562     ## doc string of the method
563     #  @internal
564     docHelper  = "Creates quadrangle 2D algorithm for faces"
565     ## hypothesis associated with algorithm
566     #  @internal
567     params     = 0
568
569     ## Private constructor.
570     #  @param mesh parent mesh object algorithm is assigned to
571     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
572     #              if it is @c 0 (default), the algorithm is assigned to the main shape
573     def __init__(self, mesh, geom=0):
574         Mesh_Algorithm.__init__(self)
575         self.Create(mesh, geom, self.algoType)
576         pass
577
578     ## Defines "QuadrangleParameters" hypothesis
579     #  @param quadType defines the algorithm of transition between differently descretized
580     #                  sides of a geometrical face:
581     #  - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
582     #                    area along the finer meshed sides.
583     #  - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
584     #                    finer meshed sides.
585     #  - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
586     #                    the finer meshed sides, iff the total quantity of segments on
587     #                    all four sides of the face is even (divisible by 2).
588     #  - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
589     #                    area is located along the coarser meshed sides.
590     #  - QUAD_REDUCED - only quadrangles are built and the transition between the sides
591     #                    is made gradually, layer by layer. This type has a limitation on
592     #                    the number of segments: one pair of opposite sides must have the
593     #                    same number of segments, the other pair must have an even difference
594     #                    between the numbers of segments on the sides.
595     #  @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
596     #                    will be created while other elements will be quadrangles.
597     #                    Vertex can be either a GEOM_Object or a vertex ID within the
598     #                    shape to mesh
599     #  @param enfVertices: list of shapes defining positions where nodes (enforced nodes)
600     #                    must be created by the mesher. Shapes can be of any type,
601     #                    vertices of given shapes define positions of enforced nodes.
602     #                    Only vertices successfully projected to the face are used.
603     #  @param enfPoints: list of points giving positions of enforced nodes.
604     #                    Point can be defined either as SMESH.PointStruct's
605     #                    ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
606     #                    or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
607     #                    In the case if the defined QuadrangleParameters() refer to a sole face,
608     #                    all given points must lie on this face, else the mesher fails.
609     #  @param UseExisting: if \c True - searches for the existing hypothesis created with
610     #                    the same parameters, else (default) - creates a new one
611     #  @ingroup l3_hypos_quad
612     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
613                              enfVertices=[],enfPoints=[],UseExisting=0):
614         import GEOM, SMESH
615         vertexID = triangleVertex
616         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
617             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
618         if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
619             # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
620             UseExisting, enfVertices = enfVertices, []
621         pStructs, xyz = [], []
622         for p in enfPoints:
623             if isinstance( p, SMESH.PointStruct ):
624                 xyz.append(( p.x, p.y, p.z ))
625                 pStructs.append( p )
626             else:
627                 xyz.append(( p[0], p[1], p[2] ))
628                 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
629         if not self.params:
630             compFun = lambda hyp,args: \
631                       hyp.GetQuadType() == args[0] and \
632                       (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
633                       ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
634             entries = [ shape.GetStudyEntry() for shape in enfVertices ]
635             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
636                                           UseExisting = UseExisting, CompareMethod=compFun)
637             pass
638         if self.params.GetQuadType() != quadType:
639             self.params.SetQuadType(quadType)
640         if vertexID > 0:
641             self.params.SetTriaVertex( vertexID )
642         from salome.smesh.smeshBuilder import AssureGeomPublished
643         for v in enfVertices:
644             AssureGeomPublished( self.mesh, v )
645         self.params.SetEnforcedNodes( enfVertices, pStructs )
646         return self.params
647
648     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
649     #   quadrangles are built in the transition area along the finer meshed sides,
650     #   iff the total quantity of segments on all four sides of the face is even.
651     #  @param reversed if True, transition area is located along the coarser meshed sides.
652     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
653     #                  the same parameters, else (default) - creates a new one
654     #  @ingroup l3_hypos_quad
655     def QuadranglePreference(self, reversed=False, UseExisting=0):
656         if reversed:
657             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
658         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
659
660     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
661     #   triangles are built in the transition area along the finer meshed sides.
662     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
663     #                  the same parameters, else (default) - creates a new one
664     #  @ingroup l3_hypos_quad
665     def TrianglePreference(self, UseExisting=0):
666         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
667
668     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
669     #   quadrangles are built and the transition between the sides is made gradually,
670     #   layer by layer. This type has a limitation on the number of segments: one pair
671     #   of opposite sides must have the same number of segments, the other pair must
672     #   have an even difference between the numbers of segments on the sides.
673     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
674     #                  the same parameters, else (default) - creates a new one
675     #  @ingroup l3_hypos_quad
676     def Reduced(self, UseExisting=0):
677         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
678
679     ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
680     #  @param vertex: vertex of a trilateral geometrical face, around which triangles
681     #                 will be created while other elements will be quadrangles.
682     #                 Vertex can be either a GEOM_Object or a vertex ID within the
683     #                 shape to mesh
684     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
685     #                   the same parameters, else (default) - creates a new one
686     #  @ingroup l3_hypos_quad
687     def TriangleVertex(self, vertex, UseExisting=0):
688         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
689
690     pass # end of StdMeshersBuilder_Quadrangle class
691
692 ## Defines a hexahedron 3D algorithm
693
694 #  It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
695 #
696 #  @ingroup l3_algos_basic
697 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
698
699     ## name of the dynamic method in smeshBuilder.Mesh class
700     #  @internal
701     meshMethod = "Hexahedron"
702     ## type of algorithm used with helper function in smeshBuilder.Mesh class
703     #  @internal
704     algoType   = Hexa
705     ## flag pointing whether this algorithm should be used by default in dynamic method
706     #  of smeshBuilder.Mesh class
707     #  @internal
708     isDefault  = True
709     ## doc string of the method
710     #  @internal
711     docHelper  = "Creates hexahedron 3D algorithm for volumes"
712
713     ## Private constructor.
714     #  @param mesh parent mesh object algorithm is assigned to
715     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
716     #              if it is @c 0 (default), the algorithm is assigned to the main shape
717     def __init__(self, mesh, geom=0):
718         Mesh_Algorithm.__init__(self)
719         self.Create(mesh, geom, Hexa)
720         pass
721
722     pass # end of StdMeshersBuilder_Hexahedron class
723
724 ## Defines a projection 1D algorithm
725 #  
726 #  It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
727 #
728 #  @ingroup l3_algos_proj
729 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
730
731     ## name of the dynamic method in smeshBuilder.Mesh class
732     #  @internal
733     meshMethod = "Projection1D"
734     ## type of algorithm used with helper function in smeshBuilder.Mesh class
735     #  @internal
736     algoType   = "Projection_1D"
737     ## flag pointing whether this algorithm should be used by default in dynamic method
738     #  of smeshBuilder.Mesh class
739     #  @internal
740     isDefault  = True
741     ## doc string of the method
742     #  @internal
743     docHelper  = "Creates projection 1D algorithm for edges"
744
745     ## Private constructor.
746     #  @param mesh parent mesh object algorithm is assigned to
747     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
748     #              if it is @c 0 (default), the algorithm is assigned to the main shape
749     def __init__(self, mesh, geom=0):
750         Mesh_Algorithm.__init__(self)
751         self.Create(mesh, geom, self.algoType)
752         pass
753
754     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
755     #  a mesh pattern is taken, and, optionally, the association of vertices
756     #  between the source edge and a target edge (to which a hypothesis is assigned)
757     #  @param edge from which nodes distribution is taken
758     #  @param mesh from which nodes distribution is taken (optional)
759     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
760     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
761     #  to associate with \a srcV (optional)
762     #  @param UseExisting if ==true - searches for the existing hypothesis created with
763     #                     the same parameters, else (default) - creates a new one
764     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
765         from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
766         AssureGeomPublished( self.mesh, edge )
767         AssureGeomPublished( self.mesh, srcV )
768         AssureGeomPublished( self.mesh, tgtV )
769         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
770                               UseExisting=0)
771         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
772                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
773         hyp.SetSourceEdge( edge )
774         if not mesh is None and isinstance(mesh, Mesh):
775             mesh = mesh.GetMesh()
776         hyp.SetSourceMesh( mesh )
777         hyp.SetVertexAssociation( srcV, tgtV )
778         return hyp
779
780     pass # end of StdMeshersBuilder_Projection1D class
781
782 ## Defines a projection 2D algorithm
783 #  
784 #  It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
785 #
786 #  @ingroup l3_algos_proj
787 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
788
789     ## name of the dynamic method in smeshBuilder.Mesh class
790     #  @internal
791     meshMethod = "Projection2D"
792     ## type of algorithm used with helper function in smeshBuilder.Mesh class
793     #  @internal
794     algoType   = "Projection_2D"
795     ## flag pointing whether this algorithm should be used by default in dynamic method
796     #  of smeshBuilder.Mesh class
797     #  @internal
798     isDefault  = True
799     ## doc string of the method
800     #  @internal
801     docHelper  = "Creates projection 2D algorithm for faces"
802
803     ## Private constructor.
804     #  @param mesh parent mesh object algorithm is assigned to
805     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
806     #              if it is @c 0 (default), the algorithm is assigned to the main shape
807     def __init__(self, mesh, geom=0):
808         Mesh_Algorithm.__init__(self)
809         self.Create(mesh, geom, self.algoType)
810         pass
811
812     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
813     #  a mesh pattern is taken, and, optionally, the association of vertices
814     #  between the source face and the target face (to which a hypothesis is assigned)
815     #  @param face from which the mesh pattern is taken
816     #  @param mesh from which the mesh pattern is taken (optional)
817     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
818     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
819     #               to associate with \a srcV1 (optional)
820     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
821     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
822     #               to associate with \a srcV2 (optional)
823     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
824     #                     the same parameters, else (default) - forces the creation a new one
825     #
826     #  Note: all association vertices must belong to one edge of a face
827     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
828                    srcV2=None, tgtV2=None, UseExisting=0):
829         from salome.smesh.smeshBuilder import Mesh
830         if isinstance(mesh, Mesh):
831             mesh = mesh.GetMesh()
832         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
833             from salome.smesh.smeshBuilder import AssureGeomPublished
834             AssureGeomPublished( self.mesh, geom )
835         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
836                               UseExisting=0, toAdd=False)
837         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
838                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
839         hyp.SetSourceFace( face )
840         hyp.SetSourceMesh( mesh )
841         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
842         self.mesh.AddHypothesis(hyp, self.geom)
843         return hyp
844
845     pass # end of StdMeshersBuilder_Projection2D class
846
847 ## Defines a projection 1D-2D algorithm
848 #  
849 #  It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
850 #
851 #  @ingroup l3_algos_proj
852 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
853
854     ## name of the dynamic method in smeshBuilder.Mesh class
855     #  @internal
856     meshMethod = "Projection1D2D"
857     ## type of algorithm used with helper function in smeshBuilder.Mesh class
858     #  @internal
859     algoType   = "Projection_1D2D"
860     ## doc string of the method
861     #  @internal
862     docHelper  = "Creates projection 1D-2D algorithm for faces"
863
864     ## Private constructor.
865     #  @param mesh parent mesh object algorithm is assigned to
866     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
867     #              if it is @c 0 (default), the algorithm is assigned to the main shape
868     def __init__(self, mesh, geom=0):
869         StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
870         pass
871
872     pass # end of StdMeshersBuilder_Projection1D2D class
873
874 ## Defines a projection 3D algorithm
875
876 #  It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
877 #
878 #  @ingroup l3_algos_proj
879 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
880
881     ## name of the dynamic method in smeshBuilder.Mesh class
882     #  @internal
883     meshMethod = "Projection3D"
884     ## type of algorithm used with helper function in smeshBuilder.Mesh class
885     #  @internal
886     algoType   = "Projection_3D"
887     ## doc string of the method
888     #  @internal
889     docHelper  = "Creates projection 3D algorithm for volumes"
890
891     ## Private constructor.
892     #  @param mesh parent mesh object algorithm is assigned to
893     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
894     #              if it is @c 0 (default), the algorithm is assigned to the main shape
895     def __init__(self, mesh, geom=0):
896         Mesh_Algorithm.__init__(self)
897         self.Create(mesh, geom, self.algoType)
898         pass
899
900     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
901     #  the mesh pattern is taken, and, optionally, the  association of vertices
902     #  between the source and the target solid  (to which a hipothesis is assigned)
903     #  @param solid from where the mesh pattern is taken
904     #  @param mesh from where the mesh pattern is taken (optional)
905     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
906     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
907     #  to associate with \a srcV1 (optional)
908     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
909     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
910     #  to associate with \a srcV2 (optional)
911     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
912     #                     the same parameters, else (default) - creates a new one
913     #
914     #  Note: association vertices must belong to one edge of a solid
915     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
916                       srcV2=0, tgtV2=0, UseExisting=0):
917         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
918             from salome.smesh.smeshBuilder import AssureGeomPublished
919             AssureGeomPublished( self.mesh, geom )
920         hyp = self.Hypothesis("ProjectionSource3D",
921                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
922                               UseExisting=0)
923         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
924                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
925         hyp.SetSource3DShape( solid )
926         from salome.smesh.smeshBuilder import Mesh
927         if isinstance(mesh, Mesh):
928             mesh = mesh.GetMesh()
929         if mesh:
930             hyp.SetSourceMesh( mesh )
931         if srcV1 and srcV2 and tgtV1 and tgtV2:
932             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
933         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
934         return hyp
935
936     pass # end of StdMeshersBuilder_Projection3D class
937
938 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
939 #  depending on geometry
940
941 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
942 #
943 #  @ingroup l3_algos_3dextr
944 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
945
946     ## name of the dynamic method in smeshBuilder.Mesh class
947     #  @internal
948     meshMethod = "Prism"
949     ## type of algorithm used with helper function in smeshBuilder.Mesh class
950     #  @internal
951     algoType   = "Prism_3D"
952     ## doc string of the method
953     #  @internal
954     docHelper  = "Creates prism 3D algorithm for volumes"
955
956     ## Private constructor.
957     #  @param mesh parent mesh object algorithm is assigned to
958     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
959     #              if it is @c 0 (default), the algorithm is assigned to the main shape
960     def __init__(self, mesh, geom=0):
961         Mesh_Algorithm.__init__(self)
962         
963         shape = geom
964         if not shape:
965             shape = mesh.geom
966         isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
967         if not isRadial:
968             self.Create(mesh, geom, "Prism_3D")
969             pass
970         else:
971             self.algoType = "RadialPrism_3D"
972             self.Create(mesh, geom, "RadialPrism_3D")
973             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
974             self.nbLayers = None
975             pass
976         pass
977
978     ## Return 3D hypothesis holding the 1D one
979     def Get3DHypothesis(self):
980         if self.algoType != "RadialPrism_3D":
981             print "Prism_3D algorith doesn't support any hyposesis"
982             return None
983         return self.distribHyp
984
985     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
986     #  hypothesis. Returns the created hypothesis
987     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
988         if self.algoType != "RadialPrism_3D":
989             print "Prism_3D algorith doesn't support any hyposesis"
990             return None
991         if not self.nbLayers is None:
992             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
993             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
994         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
995         self.mesh.smeshpyD.SetCurrentStudy( None )
996         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
997         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
998         if not self.distribHyp:
999             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1000         self.distribHyp.SetLayerDistribution( hyp )
1001         return hyp
1002
1003     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1004     #  prisms to build between the inner and outer shells
1005     #  @param n number of layers
1006     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1007     #                     the same parameters, else (default) - creates a new one
1008     def NumberOfLayers(self, n, UseExisting=0):
1009         if self.algoType != "RadialPrism_3D":
1010             print "Prism_3D algorith doesn't support any hyposesis"
1011             return None
1012         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1013         from salome.smesh.smeshBuilder import IsEqual
1014         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1015         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1016                                         CompareMethod=compFun)
1017         self.nbLayers.SetNumberOfLayers( n )
1018         return self.nbLayers
1019
1020     ## Defines "LocalLength" hypothesis, specifying the segment length
1021     #  to build between the inner and the outer shells
1022     #  @param l the length of segments
1023     #  @param p the precision of rounding
1024     def LocalLength(self, l, p=1e-07):
1025         if self.algoType != "RadialPrism_3D":
1026             print "Prism_3D algorith doesn't support any hyposesis"
1027             return None
1028         hyp = self.OwnHypothesis("LocalLength", [l,p])
1029         hyp.SetLength(l)
1030         hyp.SetPrecision(p)
1031         return hyp
1032
1033     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1034     #  prisms to build between the inner and the outer shells.
1035     #  @param n the number of layers
1036     #  @param s the scale factor (optional)
1037     def NumberOfSegments(self, n, s=[]):
1038         if self.algoType != "RadialPrism_3D":
1039             print "Prism_3D algorith doesn't support any hyposesis"
1040             return None
1041         if not s:
1042             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1043         else:
1044             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1045             hyp.SetScaleFactor(s)
1046         hyp.SetNumberOfSegments(n)
1047         return hyp
1048
1049     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1050     #  to build between the inner and the outer shells with a length that changes
1051     #  in arithmetic progression
1052     #  @param start  the length of the first segment
1053     #  @param end    the length of the last  segment
1054     def Arithmetic1D(self, start, end ):
1055         if self.algoType != "RadialPrism_3D":
1056             print "Prism_3D algorith doesn't support any hyposesis"
1057             return None
1058         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1059         hyp.SetLength(start, 1)
1060         hyp.SetLength(end  , 0)
1061         return hyp
1062
1063     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1064     #  to build between the inner and the outer shells with a length that changes
1065     #  in Geometric progression
1066     #  @param start  the length of the first segment
1067     #  @param ratio  the common ratio of the geometric progression
1068     def GeometricProgression(self, start, ratio ):
1069         if self.algoType != "RadialPrism_3D":
1070             print "Prism_3D algorith doesn't support any hyposesis"
1071             return None
1072         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1073         hyp.SetStartLength( start )
1074         hyp.SetCommonRatio( ratio )
1075         return hyp
1076
1077     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1078     #  to build between the inner and the outer shells as geometric length increasing
1079     #  @param start for the length of the first segment
1080     #  @param end   for the length of the last  segment
1081     def StartEndLength(self, start, end):
1082         if self.algoType != "RadialPrism_3D":
1083             print "Prism_3D algorith doesn't support any hyposesis"
1084             return None
1085         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1086         hyp.SetLength(start, 1)
1087         hyp.SetLength(end  , 0)
1088         return hyp
1089
1090     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1091     #  to build between the inner and outer shells
1092     #  @param fineness defines the quality of the mesh within the range [0-1]
1093     def AutomaticLength(self, fineness=0):
1094         if self.algoType != "RadialPrism_3D":
1095             print "Prism_3D algorith doesn't support any hyposesis"
1096             return None
1097         hyp = self.OwnHypothesis("AutomaticLength")
1098         hyp.SetFineness( fineness )
1099         return hyp
1100
1101     pass # end of StdMeshersBuilder_Prism3D class
1102
1103 ## Defines Radial Prism 3D algorithm
1104
1105 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1106 #
1107 #  @ingroup l3_algos_3dextr
1108 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1109
1110     ## name of the dynamic method in smeshBuilder.Mesh class
1111     #  @internal
1112     meshMethod = "Prism"
1113     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1114     #  @internal
1115     algoType   = "RadialPrism_3D"
1116     ## doc string of the method
1117     #  @internal
1118     docHelper  = "Creates Raial Prism 3D algorithm for volumes"
1119
1120     ## Private constructor.
1121     #  @param mesh parent mesh object algorithm is assigned to
1122     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1123     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1124     def __init__(self, mesh, geom=0):
1125         Mesh_Algorithm.__init__(self)
1126         
1127         shape = geom
1128         if not shape:
1129             shape = mesh.geom
1130         self.Create(mesh, geom, "RadialPrism_3D")
1131         self.distribHyp = None
1132         self.nbLayers = None
1133         return
1134
1135 ## Base class for algorithms supporting radial distribution hypotheses
1136
1137 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1138
1139     def __init__(self):
1140         Mesh_Algorithm.__init__(self)
1141
1142         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1143         self.nbLayers = None
1144         pass
1145
1146     ## Return 2D hypothesis holding the 1D one
1147     def Get2DHypothesis(self):
1148         if not self.distribHyp:
1149             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1150         return self.distribHyp
1151
1152     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1153     #  hypothesis. Returns the created hypothesis
1154     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1155         if self.nbLayers:
1156             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1157         if self.distribHyp is None:
1158             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1159         else:
1160             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1161         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1162         self.mesh.smeshpyD.SetCurrentStudy( None )
1163         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1164         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1165         self.distribHyp.SetLayerDistribution( hyp )
1166         return hyp
1167
1168     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1169     #  @param n number of layers
1170     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1171     #                     the same parameters, else (default) - creates a new one
1172     def NumberOfLayers(self, n, UseExisting=0):
1173         if self.distribHyp:
1174             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1175         from salome.smesh.smeshBuilder import IsEqual
1176         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1177         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1178                                         CompareMethod=compFun)
1179         self.nbLayers.SetNumberOfLayers( n )
1180         return self.nbLayers
1181
1182     ## Defines "LocalLength" hypothesis, specifying the segment length
1183     #  @param l the length of segments
1184     #  @param p the precision of rounding
1185     def LocalLength(self, l, p=1e-07):
1186         hyp = self.OwnHypothesis("LocalLength", [l,p])
1187         hyp.SetLength(l)
1188         hyp.SetPrecision(p)
1189         return hyp
1190
1191     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1192     #  @param n the number of layers
1193     #  @param s the scale factor (optional)
1194     def NumberOfSegments(self, n, s=[]):
1195         if s == []:
1196             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1197         else:
1198             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1199             hyp.SetDistrType( 1 )
1200             hyp.SetScaleFactor(s)
1201         hyp.SetNumberOfSegments(n)
1202         return hyp
1203
1204     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1205     #  with a length that changes in arithmetic progression
1206     #  @param start  the length of the first segment
1207     #  @param end    the length of the last  segment
1208     def Arithmetic1D(self, start, end ):
1209         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1210         hyp.SetLength(start, 1)
1211         hyp.SetLength(end  , 0)
1212         return hyp
1213
1214     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1215     #  with a length that changes in Geometric progression
1216     #  @param start  the length of the first segment
1217     #  @param ratio  the common ratio of the geometric progression
1218     def GeometricProgression(self, start, ratio ):
1219         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1220         hyp.SetStartLength( start )
1221         hyp.SetCommonRatio( ratio )
1222         return hyp
1223
1224     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1225     #  as geometric length increasing
1226     #  @param start for the length of the first segment
1227     #  @param end   for the length of the last  segment
1228     def StartEndLength(self, start, end):
1229         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1230         hyp.SetLength(start, 1)
1231         hyp.SetLength(end  , 0)
1232         return hyp
1233
1234     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1235     #  @param fineness defines the quality of the mesh within the range [0-1]
1236     def AutomaticLength(self, fineness=0):
1237         hyp = self.OwnHypothesis("AutomaticLength")
1238         hyp.SetFineness( fineness )
1239         return hyp
1240
1241     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1242
1243 ## Defines a Radial Quadrangle 1D-2D algorithm
1244
1245 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1246 #
1247 #  @ingroup l2_algos_radialq
1248 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1249
1250     ## name of the dynamic method in smeshBuilder.Mesh class
1251     #  @internal
1252     meshMethod = "Quadrangle"
1253     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1254     #  @internal
1255     algoType   = RADIAL_QUAD
1256     ## doc string of the method
1257     #  @internal
1258     docHelper  = "Creates quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1259
1260     ## Private constructor.
1261     #  @param mesh parent mesh object algorithm is assigned to
1262     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1263     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1264     def __init__(self, mesh, geom=0):
1265         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1266         self.Create(mesh, geom, self.algoType)
1267
1268         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1269         self.nbLayers = None
1270         pass
1271
1272
1273 ## Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm
1274
1275 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1276 #
1277 #  @ingroup l2_algos_quad_ma
1278 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1279
1280     ## name of the dynamic method in smeshBuilder.Mesh class
1281     #  @internal
1282     meshMethod = "Quadrangle"
1283     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1284     #  @internal
1285     algoType   = QUAD_MA_PROJ
1286     ## doc string of the method
1287     #  @internal
1288     docHelper  = "Creates quadrangle 1D-2D algorithm for faces"
1289
1290     ## Private constructor.
1291     #  @param mesh parent mesh object algorithm is assigned to
1292     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1293     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1294     def __init__(self, mesh, geom=0):
1295         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1296         self.Create(mesh, geom, self.algoType)
1297         pass
1298
1299     pass
1300
1301 ## Defines a Polygon Per Face 2D algorithm
1302
1303 #  It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1304 #
1305 #  @ingroup l2_algos_quad_ma
1306 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1307
1308     ## name of the dynamic method in smeshBuilder.Mesh class
1309     #  @internal
1310     meshMethod = "Polygon"
1311     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1312     #  @internal
1313     algoType   = POLYGON
1314     ## flag pointing whether this algorithm should be used by default in dynamic method
1315     #  of smeshBuilder.Mesh class
1316     #  @internal
1317     isDefault  = True
1318     ## doc string of the method
1319     #  @internal
1320     docHelper  = "Creates polygon 2D algorithm for faces"
1321
1322     ## Private constructor.
1323     #  @param mesh parent mesh object algorithm is assigned to
1324     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1325     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1326     def __init__(self, mesh, geom=0):
1327         Mesh_Algorithm.__init__(self)
1328         self.Create(mesh, geom, self.algoType)
1329         pass
1330
1331     pass
1332
1333 ## Defines a Use Existing Elements 1D algorithm
1334 #
1335 #  It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1336 #
1337 #  @ingroup l3_algos_basic
1338 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1339
1340     ## name of the dynamic method in smeshBuilder.Mesh class
1341     #  @internal
1342     meshMethod = "UseExisting1DElements"
1343     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1344     #  @internal
1345     algoType   = "Import_1D"
1346     ## flag pointing whether this algorithm should be used by default in dynamic method
1347     #  of smeshBuilder.Mesh class
1348     #  @internal
1349     isDefault  = True
1350     ## doc string of the method
1351     #  @internal
1352     docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1353
1354     ## Private constructor.
1355     #  @param mesh parent mesh object algorithm is assigned to
1356     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1357     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1358     def __init__(self, mesh, geom=0):
1359         Mesh_Algorithm.__init__(self)
1360         self.Create(mesh, geom, self.algoType)
1361         pass
1362
1363     ## Defines "Source edges" hypothesis, specifying groups of edges to import
1364     #  @param groups list of groups of edges
1365     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1366     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1367     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1368     #                     the same parameters, else (default) - creates a new one
1369     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1370         for group in groups:
1371             from salome.smesh.smeshBuilder import AssureGeomPublished
1372             AssureGeomPublished( self.mesh, group )
1373         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1374                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1375         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1376                               UseExisting=UseExisting, CompareMethod=compFun)
1377         hyp.SetSourceEdges(groups)
1378         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1379         return hyp
1380
1381     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1382
1383 ## Defines a Use Existing Elements 1D-2D algorithm
1384 #
1385 #  It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1386 #
1387 #  @ingroup l3_algos_basic
1388 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1389
1390     ## name of the dynamic method in smeshBuilder.Mesh class
1391     #  @internal
1392     meshMethod = "UseExisting2DElements"
1393     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1394     #  @internal
1395     algoType   = "Import_1D2D"
1396     ## flag pointing whether this algorithm should be used by default in dynamic method
1397     #  of smeshBuilder.Mesh class
1398     #  @internal
1399     isDefault  = True
1400     ## doc string of the method
1401     #  @internal
1402     docHelper  = "Creates 1D-2D algorithm for faces with reusing of existing mesh elements"
1403
1404     ## Private constructor.
1405     #  @param mesh parent mesh object algorithm is assigned to
1406     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1407     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1408     def __init__(self, mesh, geom=0):
1409         Mesh_Algorithm.__init__(self)
1410         self.Create(mesh, geom, self.algoType)
1411         pass
1412
1413     ## Defines "Source faces" hypothesis, specifying groups of faces to import
1414     #  @param groups list of groups of faces
1415     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1416     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1417     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1418     #                     the same parameters, else (default) - creates a new one
1419     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1420         import SMESH
1421         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1422                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1423         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1424                               UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1425         if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1426             groups = [groups]
1427         hyp.SetSourceFaces(groups)
1428         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1429         self.mesh.AddHypothesis(hyp, self.geom)
1430         return hyp
1431
1432     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1433
1434 ## Defines a Body Fitting 3D algorithm
1435 #
1436 #  It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1437 #
1438 #  @ingroup l3_algos_basic
1439 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1440
1441     ## name of the dynamic method in smeshBuilder.Mesh class
1442     #  @internal
1443     meshMethod = "BodyFitted"
1444     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1445     #  @internal
1446     algoType   = "Cartesian_3D"
1447     ## flag pointing whether this algorithm should be used by default in dynamic method
1448     #  of smeshBuilder.Mesh class
1449     #  @internal
1450     isDefault  = True
1451     ## doc string of the method
1452     #  @internal
1453     docHelper  = "Creates Body Fitting 3D algorithm for volumes"
1454
1455     ## Private constructor.
1456     #  @param mesh parent mesh object algorithm is assigned to
1457     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1458     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1459     def __init__(self, mesh, geom=0):
1460         self.Create(mesh, geom, self.algoType)
1461         self.hyp = None
1462         pass
1463
1464     ## Defines "Body Fitting parameters" hypothesis
1465     #  @param xGridDef is definition of the grid along the X asix.
1466     #  It can be in either of two following forms:
1467     #  - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1468     #  - Functions f(t) defining grid spacing at each point on grid axis. If there are
1469     #    several functions, they must be accompanied by relative coordinates of
1470     #    points dividing the whole shape into ranges where the functions apply; points
1471     #    coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1472     #    function f(t) varies from 0.0 to 1.0 witin a shape range. 
1473     #    Examples:
1474     #    - "10.5" - defines a grid with a constant spacing
1475     #    - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1476     #  @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1477     #  @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1478     #  @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1479     #         a polyhedron of size less than hexSize/sizeThreshold is not created.
1480     #  @param implEdges enables implementation of geometrical edges into the mesh.
1481     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1482         if not self.hyp:
1483             compFun = lambda hyp, args: False
1484             self.hyp = self.Hypothesis("CartesianParameters3D",
1485                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1486                                        UseExisting=False, CompareMethod=compFun)
1487         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1488             self.mesh.AddHypothesis( self.hyp, self.geom )
1489
1490         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1491             if not gridDef: raise ValueError, "Empty grid definition"
1492             if isinstance( gridDef, str ):
1493                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1494             elif isinstance( gridDef[0], str ):
1495                 self.hyp.SetGridSpacing( gridDef, [], axis )
1496             elif isinstance( gridDef[0], int ) or \
1497                  isinstance( gridDef[0], float ):
1498                 self.hyp.SetGrid(gridDef, axis )
1499             else:
1500                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1501         self.hyp.SetSizeThreshold( sizeThreshold )
1502         self.hyp.SetToAddEdges( implEdges )
1503         return self.hyp
1504
1505     ## Defines custom directions of axes of the grid
1506     #  @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1507     #  @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1508     #  @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1509     def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1510         import GEOM
1511         if hasattr( xAxis, "__getitem__" ):
1512             xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1513         elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1514             xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1515         if hasattr( yAxis, "__getitem__" ):
1516             yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1517         elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1518             yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1519         if hasattr( zAxis, "__getitem__" ):
1520             zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1521         elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1522             zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1523         if not self.hyp:
1524             self.hyp = self.Hypothesis("CartesianParameters3D")
1525         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1526             self.mesh.AddHypothesis( self.hyp, self.geom )
1527         self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1528         return self.hyp
1529
1530     ## Automatically defines directions of axes of the grid at which
1531     #  a number of generated hexahedra is maximal
1532     #  @param isOrthogonal defines whether the axes mush be orthogonal
1533     def SetOptimalAxesDirs(self, isOrthogonal=True):
1534         if not self.hyp:
1535             self.hyp = self.Hypothesis("CartesianParameters3D")
1536         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1537             self.mesh.AddHypothesis( self.hyp, self.geom )
1538         x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1539         self.hyp.SetAxesDirs( x,y,z )
1540         return self.hyp
1541
1542     ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1543     #  through the fixed point in each direction at which the grid is defined
1544     #  by spacing
1545     #  @param p coordinates of the fixed point. Either SMESH.PointStruct or
1546     #         a vertex or 3 components of coordinates.
1547     #  @param toUnset defines whether the fixed point is defined or removed.
1548     def SetFixedPoint( self, p, toUnset=False ):
1549         import SMESH, GEOM
1550         if toUnset:
1551             if not self.hyp: return
1552             p = SMESH.PointStruct(0,0,0)
1553         elif hasattr( p, "__getitem__" ):
1554             p = SMESH.PointStruct( p[0],p[1],p[2] )
1555         elif isinstance( p, GEOM._objref_GEOM_Object ):
1556             p = self.mesh.smeshpyD.GetPointStruct( p )
1557         if not self.hyp:
1558             self.hyp = self.Hypothesis("CartesianParameters3D")
1559         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1560             self.mesh.AddHypothesis( self.hyp, self.geom )
1561         self.hyp.SetFixedPoint( p, toUnset )
1562         return self.hyp
1563         
1564
1565     pass # end of StdMeshersBuilder_Cartesian_3D class
1566
1567 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1568 #  segments usable by 2D algoritms
1569 #
1570 #  It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1571 #
1572 #  @ingroup l3_algos_basic
1573 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1574
1575     ## name of the dynamic method in smeshBuilder.Mesh class
1576     #  @internal
1577     meshMethod = "UseExistingSegments"
1578     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1579     #  @internal
1580     algoType   = "UseExisting_1D"
1581     ## doc string of the method
1582     #  @internal
1583     docHelper  = "Creates 1D algorithm allowing batch meshing of edges"
1584
1585     ## Private constructor.
1586     #  @param mesh parent mesh object algorithm is assigned to
1587     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1588     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1589     def __init__(self, mesh, geom=0):
1590         self.Create(mesh, geom, self.algoType)
1591         pass
1592
1593     pass # end of StdMeshersBuilder_UseExisting_1D class
1594
1595 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1596 #  faces usable by 3D algoritms
1597 #
1598 #  It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1599 #
1600 #  @ingroup l3_algos_basic
1601 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1602
1603     ## name of the dynamic method in smeshBuilder.Mesh class
1604     #  @internal
1605     meshMethod = "UseExistingFaces"
1606     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1607     #  @internal
1608     algoType   = "UseExisting_2D"
1609     ## doc string of the method
1610     #  @internal
1611     docHelper  = "Creates 2D algorithm allowing batch meshing of faces"
1612
1613     ## Private constructor.
1614     #  @param mesh parent mesh object algorithm is assigned to
1615     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1616     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1617     def __init__(self, mesh, geom=0):
1618         self.Create(mesh, geom, self.algoType)
1619         pass
1620
1621     pass # end of StdMeshersBuilder_UseExisting_2D class