Salome HOME
Merge remote-tracking branch 'origin/fbt/fix_french_translation'
[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 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             self.geom = store_geom
385             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
386         from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
387         AssureGeomPublished( self.mesh, self.geom )
388         name = GetName(self.geom)
389
390         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
391         if algo is None:
392             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
393             pass
394         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
395         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
396         #
397         from salome.smesh.smeshBuilder import IsEqual
398         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
399         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
400                               CompareMethod=comFun)
401         self.geom = store_geom
402         hyp.SetLength( length )
403         return hyp
404
405     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
406     #  If the 2D mesher sees that all boundary edges are quadratic,
407     #  it generates quadratic faces, else it generates linear faces using
408     #  medium nodes as if they are vertices.
409     #  The 3D mesher generates quadratic volumes only if all boundary faces
410     #  are quadratic, else it fails.
411     #
412     #  @ingroup l3_hypos_additi
413     def QuadraticMesh(self):
414         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
415         return hyp
416
417     pass # end of StdMeshersBuilder_Segment class
418
419 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
420 #
421 #  It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
422 #
423 #  @ingroup l3_algos_basic
424 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
425
426     ## name of the dynamic method in smeshBuilder.Mesh class
427     #  @internal
428     meshMethod = "Segment"
429     ## type of algorithm used with helper function in smeshBuilder.Mesh class
430     #  @internal
431     algoType   = COMPOSITE
432     ## flag pointing whether this algorithm should be used by default in dynamic method
433     #  of smeshBuilder.Mesh class
434     #  @internal
435     isDefault  = False
436     ## doc string of the method
437     #  @internal
438     docHelper  = "Creates segment 1D algorithm for edges"
439
440     ## Private constructor.
441     #  @param mesh parent mesh object algorithm is assigned to
442     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
443     #              if it is @c 0 (default), the algorithm is assigned to the main shape
444     def __init__(self, mesh, geom=0):
445         self.Create(mesh, geom, self.algoType)
446         pass
447
448     pass # end of StdMeshersBuilder_CompositeSegment class
449
450 ## Defines a segment 1D algorithm for discretization of edges with Python function
451 #
452 #  It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
453 #
454 #  @ingroup l3_algos_basic
455 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
456
457     ## name of the dynamic method in smeshBuilder.Mesh class
458     #  @internal
459     meshMethod = "Segment"
460     ## type of algorithm used with helper function in smeshBuilder.Mesh class
461     #  @internal
462     algoType   = PYTHON
463     ## doc string of the method
464     #  @internal
465     docHelper  = "Creates segment 1D algorithm for edges"
466
467     ## Private constructor.
468     #  @param mesh parent mesh object algorithm is assigned to
469     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
470     #              if it is @c 0 (default), the algorithm is assigned to the main shape
471     def __init__(self, mesh, geom=0):
472         import Python1dPlugin
473         self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
474         pass
475
476     ## Defines "PythonSplit1D" hypothesis
477     #  @param n for the number of segments that cut an edge
478     #  @param func for the python function that calculates the length of all segments
479     #  @param UseExisting if ==true - searches for the existing hypothesis created with
480     #                     the same parameters, else (default) - creates a new one
481     #  @ingroup l3_hypos_1dhyps
482     def PythonSplit1D(self, n, func, UseExisting=0):
483         compFun = lambda hyp, args: False
484         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
485                               UseExisting=UseExisting, CompareMethod=compFun)
486         hyp.SetNumberOfSegments(n)
487         hyp.SetPythonLog10RatioFunction(func)
488         return hyp
489
490     pass # end of StdMeshersBuilder_Segment_Python class
491
492 ## Triangle MEFISTO 2D algorithm
493 #
494 #  It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
495 #
496 #  @ingroup l3_algos_basic
497 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
498
499     ## name of the dynamic method in smeshBuilder.Mesh class
500     #  @internal
501     meshMethod = "Triangle"
502     ## type of algorithm used with helper function in smeshBuilder.Mesh class
503     #  @internal
504     algoType   = MEFISTO
505     ## flag pointing whether this algorithm should be used by default in dynamic method
506     #  of smeshBuilder.Mesh class
507     #  @internal
508     isDefault  = True
509     ## doc string of the method
510     #  @internal
511     docHelper  = "Creates triangle 2D algorithm for faces"
512
513     ## Private constructor.
514     #  @param mesh parent mesh object algorithm is assigned to
515     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
516     #              if it is @c 0 (default), the algorithm is assigned to the main shape
517     def __init__(self, mesh, geom=0):
518         Mesh_Algorithm.__init__(self)
519         self.Create(mesh, geom, self.algoType)
520         pass
521
522     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
523     #  @param area for the maximum area of each triangle
524     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
525     #                     same parameters, else (default) - creates a new one
526     #
527     #  @ingroup l3_hypos_2dhyps
528     def MaxElementArea(self, area, UseExisting=0):
529         from salome.smesh.smeshBuilder import IsEqual
530         comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
531         hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
532                               CompareMethod=comparator)
533         hyp.SetMaxElementArea(area)
534         return hyp
535
536     ## Defines "LengthFromEdges" hypothesis to build triangles
537     #  based on the length of the edges taken from the wire
538     #
539     #  @ingroup l3_hypos_2dhyps
540     def LengthFromEdges(self):
541         hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
542         return hyp
543
544     pass # end of StdMeshersBuilder_Triangle_MEFISTO class
545
546 ## Defines a quadrangle 2D algorithm
547
548 #  It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
549 #
550 #  @ingroup l3_algos_basic
551 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
552
553     ## name of the dynamic method in smeshBuilder.Mesh class
554     #  @internal
555     meshMethod = "Quadrangle"
556     ## type of algorithm used with helper function in smeshBuilder.Mesh class
557     #  @internal
558     algoType   = QUADRANGLE
559     ## flag pointing whether this algorithm should be used by default in dynamic method
560     #  of smeshBuilder.Mesh class
561     #  @internal
562     isDefault  = True
563     ## doc string of the method
564     #  @internal
565     docHelper  = "Creates quadrangle 2D algorithm for faces"
566     ## hypothesis associated with algorithm
567     #  @internal
568     params     = 0
569
570     ## Private constructor.
571     #  @param mesh parent mesh object algorithm is assigned to
572     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
573     #              if it is @c 0 (default), the algorithm is assigned to the main shape
574     def __init__(self, mesh, geom=0):
575         Mesh_Algorithm.__init__(self)
576         self.Create(mesh, geom, self.algoType)
577         pass
578
579     ## Defines "QuadrangleParameters" hypothesis
580     #  @param quadType defines the algorithm of transition between differently descretized
581     #                  sides of a geometrical face:
582     #  - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
583     #                    area along the finer meshed sides.
584     #  - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
585     #                    finer meshed sides.
586     #  - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
587     #                    the finer meshed sides, iff the total quantity of segments on
588     #                    all four sides of the face is even (divisible by 2).
589     #  - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
590     #                    area is located along the coarser meshed sides.
591     #  - QUAD_REDUCED - only quadrangles are built and the transition between the sides
592     #                    is made gradually, layer by layer. This type has a limitation on
593     #                    the number of segments: one pair of opposite sides must have the
594     #                    same number of segments, the other pair must have an even difference
595     #                    between the numbers of segments on the sides.
596     #  @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
597     #                    will be created while other elements will be quadrangles.
598     #                    Vertex can be either a GEOM_Object or a vertex ID within the
599     #                    shape to mesh
600     #  @param enfVertices: list of shapes defining positions where nodes (enforced nodes)
601     #                    must be created by the mesher. Shapes can be of any type,
602     #                    vertices of given shapes define positions of enforced nodes.
603     #                    Only vertices successfully projected to the face are used.
604     #  @param enfPoints: list of points giving positions of enforced nodes.
605     #                    Point can be defined either as SMESH.PointStruct's
606     #                    ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
607     #                    or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
608     #                    In the case if the defined QuadrangleParameters() refer to a sole face,
609     #                    all given points must lie on this face, else the mesher fails.
610     #  @param UseExisting: if \c True - searches for the existing hypothesis created with
611     #                    the same parameters, else (default) - creates a new one
612     #  @ingroup l3_hypos_quad
613     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
614                              enfVertices=[],enfPoints=[],UseExisting=0):
615         import GEOM, SMESH
616         vertexID = triangleVertex
617         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
618             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
619         if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
620             # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
621             UseExisting, enfVertices = enfVertices, []
622         pStructs, xyz = [], []
623         for p in enfPoints:
624             if isinstance( p, SMESH.PointStruct ):
625                 xyz.append(( p.x, p.y, p.z ))
626                 pStructs.append( p )
627             else:
628                 xyz.append(( p[0], p[1], p[2] ))
629                 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
630         if not self.params:
631             compFun = lambda hyp,args: \
632                       hyp.GetQuadType() == args[0] and \
633                       (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
634                       ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
635             entries = [ shape.GetStudyEntry() for shape in enfVertices ]
636             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
637                                           UseExisting = UseExisting, CompareMethod=compFun)
638             pass
639         if self.params.GetQuadType() != quadType:
640             self.params.SetQuadType(quadType)
641         if vertexID > 0:
642             self.params.SetTriaVertex( vertexID )
643         from salome.smesh.smeshBuilder import AssureGeomPublished
644         for v in enfVertices:
645             AssureGeomPublished( self.mesh, v )
646         self.params.SetEnforcedNodes( enfVertices, pStructs )
647         return self.params
648
649     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
650     #   quadrangles are built in the transition area along the finer meshed sides,
651     #   iff the total quantity of segments on all four sides of the face is even.
652     #  @param reversed if True, transition area is located along the coarser meshed sides.
653     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
654     #                  the same parameters, else (default) - creates a new one
655     #  @ingroup l3_hypos_quad
656     def QuadranglePreference(self, reversed=False, UseExisting=0):
657         if reversed:
658             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
659         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
660
661     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
662     #   triangles are built in the transition area along the finer meshed sides.
663     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
664     #                  the same parameters, else (default) - creates a new one
665     #  @ingroup l3_hypos_quad
666     def TrianglePreference(self, UseExisting=0):
667         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
668
669     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
670     #   quadrangles are built and the transition between the sides is made gradually,
671     #   layer by layer. This type has a limitation on the number of segments: one pair
672     #   of opposite sides must have the same number of segments, the other pair must
673     #   have an even difference between the numbers of segments on the sides.
674     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
675     #                  the same parameters, else (default) - creates a new one
676     #  @ingroup l3_hypos_quad
677     def Reduced(self, UseExisting=0):
678         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
679
680     ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
681     #  @param vertex: vertex of a trilateral geometrical face, around which triangles
682     #                 will be created while other elements will be quadrangles.
683     #                 Vertex can be either a GEOM_Object or a vertex ID within the
684     #                 shape to mesh
685     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
686     #                   the same parameters, else (default) - creates a new one
687     #  @ingroup l3_hypos_quad
688     def TriangleVertex(self, vertex, UseExisting=0):
689         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
690
691     pass # end of StdMeshersBuilder_Quadrangle class
692
693 ## Defines a hexahedron 3D algorithm
694
695 #  It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
696 #
697 #  @ingroup l3_algos_basic
698 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
699
700     ## name of the dynamic method in smeshBuilder.Mesh class
701     #  @internal
702     meshMethod = "Hexahedron"
703     ## type of algorithm used with helper function in smeshBuilder.Mesh class
704     #  @internal
705     algoType   = Hexa
706     ## flag pointing whether this algorithm should be used by default in dynamic method
707     #  of smeshBuilder.Mesh class
708     #  @internal
709     isDefault  = True
710     ## doc string of the method
711     #  @internal
712     docHelper  = "Creates hexahedron 3D algorithm for volumes"
713
714     ## Private constructor.
715     #  @param mesh parent mesh object algorithm is assigned to
716     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
717     #              if it is @c 0 (default), the algorithm is assigned to the main shape
718     def __init__(self, mesh, geom=0):
719         Mesh_Algorithm.__init__(self)
720         self.Create(mesh, geom, Hexa)
721         pass
722
723     pass # end of StdMeshersBuilder_Hexahedron class
724
725 ## Defines a projection 1D algorithm
726 #  
727 #  It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
728 #
729 #  @ingroup l3_algos_proj
730 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
731
732     ## name of the dynamic method in smeshBuilder.Mesh class
733     #  @internal
734     meshMethod = "Projection1D"
735     ## type of algorithm used with helper function in smeshBuilder.Mesh class
736     #  @internal
737     algoType   = "Projection_1D"
738     ## flag pointing whether this algorithm should be used by default in dynamic method
739     #  of smeshBuilder.Mesh class
740     #  @internal
741     isDefault  = True
742     ## doc string of the method
743     #  @internal
744     docHelper  = "Creates projection 1D algorithm for edges"
745
746     ## Private constructor.
747     #  @param mesh parent mesh object algorithm is assigned to
748     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
749     #              if it is @c 0 (default), the algorithm is assigned to the main shape
750     def __init__(self, mesh, geom=0):
751         Mesh_Algorithm.__init__(self)
752         self.Create(mesh, geom, self.algoType)
753         pass
754
755     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
756     #  a mesh pattern is taken, and, optionally, the association of vertices
757     #  between the source edge and a target edge (to which a hypothesis is assigned)
758     #  @param edge from which nodes distribution is taken
759     #  @param mesh from which nodes distribution is taken (optional)
760     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
761     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
762     #  to associate with \a srcV (optional)
763     #  @param UseExisting if ==true - searches for the existing hypothesis created with
764     #                     the same parameters, else (default) - creates a new one
765     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
766         from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
767         AssureGeomPublished( self.mesh, edge )
768         AssureGeomPublished( self.mesh, srcV )
769         AssureGeomPublished( self.mesh, tgtV )
770         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
771                               UseExisting=0)
772         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
773                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
774         hyp.SetSourceEdge( edge )
775         if not mesh is None and isinstance(mesh, Mesh):
776             mesh = mesh.GetMesh()
777         hyp.SetSourceMesh( mesh )
778         hyp.SetVertexAssociation( srcV, tgtV )
779         return hyp
780
781     pass # end of StdMeshersBuilder_Projection1D class
782
783 ## Defines a projection 2D algorithm
784 #  
785 #  It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
786 #
787 #  @ingroup l3_algos_proj
788 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
789
790     ## name of the dynamic method in smeshBuilder.Mesh class
791     #  @internal
792     meshMethod = "Projection2D"
793     ## type of algorithm used with helper function in smeshBuilder.Mesh class
794     #  @internal
795     algoType   = "Projection_2D"
796     ## flag pointing whether this algorithm should be used by default in dynamic method
797     #  of smeshBuilder.Mesh class
798     #  @internal
799     isDefault  = True
800     ## doc string of the method
801     #  @internal
802     docHelper  = "Creates projection 2D algorithm for faces"
803
804     ## Private constructor.
805     #  @param mesh parent mesh object algorithm is assigned to
806     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
807     #              if it is @c 0 (default), the algorithm is assigned to the main shape
808     def __init__(self, mesh, geom=0):
809         Mesh_Algorithm.__init__(self)
810         self.Create(mesh, geom, self.algoType)
811         pass
812
813     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
814     #  a mesh pattern is taken, and, optionally, the association of vertices
815     #  between the source face and the target face (to which a hypothesis is assigned)
816     #  @param face from which the mesh pattern is taken
817     #  @param mesh from which the mesh pattern is taken (optional)
818     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
819     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
820     #               to associate with \a srcV1 (optional)
821     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
822     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
823     #               to associate with \a srcV2 (optional)
824     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
825     #                     the same parameters, else (default) - forces the creation a new one
826     #
827     #  Note: all association vertices must belong to one edge of a face
828     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
829                    srcV2=None, tgtV2=None, UseExisting=0):
830         from salome.smesh.smeshBuilder import Mesh
831         if isinstance(mesh, Mesh):
832             mesh = mesh.GetMesh()
833         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
834             from salome.smesh.smeshBuilder import AssureGeomPublished
835             AssureGeomPublished( self.mesh, geom )
836         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
837                               UseExisting=0, toAdd=False)
838         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
839                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
840         hyp.SetSourceFace( face )
841         hyp.SetSourceMesh( mesh )
842         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
843         self.mesh.AddHypothesis(hyp, self.geom)
844         return hyp
845
846     pass # end of StdMeshersBuilder_Projection2D class
847
848 ## Defines a projection 1D-2D algorithm
849 #  
850 #  It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
851 #
852 #  @ingroup l3_algos_proj
853 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
854
855     ## name of the dynamic method in smeshBuilder.Mesh class
856     #  @internal
857     meshMethod = "Projection1D2D"
858     ## type of algorithm used with helper function in smeshBuilder.Mesh class
859     #  @internal
860     algoType   = "Projection_1D2D"
861     ## doc string of the method
862     #  @internal
863     docHelper  = "Creates projection 1D-2D algorithm for faces"
864
865     ## Private constructor.
866     #  @param mesh parent mesh object algorithm is assigned to
867     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
868     #              if it is @c 0 (default), the algorithm is assigned to the main shape
869     def __init__(self, mesh, geom=0):
870         StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
871         pass
872
873     pass # end of StdMeshersBuilder_Projection1D2D class
874
875 ## Defines a projection 3D algorithm
876
877 #  It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
878 #
879 #  @ingroup l3_algos_proj
880 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
881
882     ## name of the dynamic method in smeshBuilder.Mesh class
883     #  @internal
884     meshMethod = "Projection3D"
885     ## type of algorithm used with helper function in smeshBuilder.Mesh class
886     #  @internal
887     algoType   = "Projection_3D"
888     ## doc string of the method
889     #  @internal
890     docHelper  = "Creates projection 3D algorithm for volumes"
891
892     ## Private constructor.
893     #  @param mesh parent mesh object algorithm is assigned to
894     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
895     #              if it is @c 0 (default), the algorithm is assigned to the main shape
896     def __init__(self, mesh, geom=0):
897         Mesh_Algorithm.__init__(self)
898         self.Create(mesh, geom, self.algoType)
899         pass
900
901     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
902     #  the mesh pattern is taken, and, optionally, the  association of vertices
903     #  between the source and the target solid  (to which a hipothesis is assigned)
904     #  @param solid from where the mesh pattern is taken
905     #  @param mesh from where the mesh pattern is taken (optional)
906     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
907     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
908     #  to associate with \a srcV1 (optional)
909     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
910     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
911     #  to associate with \a srcV2 (optional)
912     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
913     #                     the same parameters, else (default) - creates a new one
914     #
915     #  Note: association vertices must belong to one edge of a solid
916     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
917                       srcV2=0, tgtV2=0, UseExisting=0):
918         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
919             from salome.smesh.smeshBuilder import AssureGeomPublished
920             AssureGeomPublished( self.mesh, geom )
921         hyp = self.Hypothesis("ProjectionSource3D",
922                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
923                               UseExisting=0)
924         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
925                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
926         hyp.SetSource3DShape( solid )
927         from salome.smesh.smeshBuilder import Mesh
928         if isinstance(mesh, Mesh):
929             mesh = mesh.GetMesh()
930         if mesh:
931             hyp.SetSourceMesh( mesh )
932         if srcV1 and srcV2 and tgtV1 and tgtV2:
933             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
934         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
935         return hyp
936
937     pass # end of StdMeshersBuilder_Projection3D class
938
939 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
940 #  depending on geometry
941
942 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
943 #
944 #  @ingroup l3_algos_3dextr
945 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
946
947     ## name of the dynamic method in smeshBuilder.Mesh class
948     #  @internal
949     meshMethod = "Prism"
950     ## type of algorithm used with helper function in smeshBuilder.Mesh class
951     #  @internal
952     algoType   = "Prism_3D"
953     ## doc string of the method
954     #  @internal
955     docHelper  = "Creates prism 3D algorithm for volumes"
956
957     ## Private constructor.
958     #  @param mesh parent mesh object algorithm is assigned to
959     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
960     #              if it is @c 0 (default), the algorithm is assigned to the main shape
961     def __init__(self, mesh, geom=0):
962         Mesh_Algorithm.__init__(self)
963         
964         shape = geom
965         if not shape:
966             shape = mesh.geom
967         isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
968         if not isRadial:
969             self.Create(mesh, geom, "Prism_3D")
970             pass
971         else:
972             self.algoType = "RadialPrism_3D"
973             self.Create(mesh, geom, "RadialPrism_3D")
974             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
975             self.nbLayers = None
976             pass
977         pass
978
979     ## Return 3D hypothesis holding the 1D one
980     def Get3DHypothesis(self):
981         if self.algoType != "RadialPrism_3D":
982             print "Prism_3D algorith doesn't support any hyposesis"
983             return None
984         return self.distribHyp
985
986     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
987     #  hypothesis. Returns the created hypothesis
988     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
989         if self.algoType != "RadialPrism_3D":
990             print "Prism_3D algorith doesn't support any hyposesis"
991             return None
992         if not self.nbLayers is None:
993             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
994             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
995         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
996         self.mesh.smeshpyD.SetCurrentStudy( None )
997         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
998         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
999         if not self.distribHyp:
1000             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1001         self.distribHyp.SetLayerDistribution( hyp )
1002         return hyp
1003
1004     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1005     #  prisms to build between the inner and outer shells
1006     #  @param n number of layers
1007     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1008     #                     the same parameters, else (default) - creates a new one
1009     def NumberOfLayers(self, n, UseExisting=0):
1010         if self.algoType != "RadialPrism_3D":
1011             print "Prism_3D algorith doesn't support any hyposesis"
1012             return None
1013         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1014         from salome.smesh.smeshBuilder import IsEqual
1015         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1016         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1017                                         CompareMethod=compFun)
1018         self.nbLayers.SetNumberOfLayers( n )
1019         return self.nbLayers
1020
1021     ## Defines "LocalLength" hypothesis, specifying the segment length
1022     #  to build between the inner and the outer shells
1023     #  @param l the length of segments
1024     #  @param p the precision of rounding
1025     def LocalLength(self, l, p=1e-07):
1026         if self.algoType != "RadialPrism_3D":
1027             print "Prism_3D algorith doesn't support any hyposesis"
1028             return None
1029         hyp = self.OwnHypothesis("LocalLength", [l,p])
1030         hyp.SetLength(l)
1031         hyp.SetPrecision(p)
1032         return hyp
1033
1034     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1035     #  prisms to build between the inner and the outer shells.
1036     #  @param n the number of layers
1037     #  @param s the scale factor (optional)
1038     def NumberOfSegments(self, n, s=[]):
1039         if self.algoType != "RadialPrism_3D":
1040             print "Prism_3D algorith doesn't support any hyposesis"
1041             return None
1042         if not s:
1043             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1044         else:
1045             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1046             hyp.SetScaleFactor(s)
1047         hyp.SetNumberOfSegments(n)
1048         return hyp
1049
1050     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1051     #  to build between the inner and the outer shells with a length that changes
1052     #  in arithmetic progression
1053     #  @param start  the length of the first segment
1054     #  @param end    the length of the last  segment
1055     def Arithmetic1D(self, start, end ):
1056         if self.algoType != "RadialPrism_3D":
1057             print "Prism_3D algorith doesn't support any hyposesis"
1058             return None
1059         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1060         hyp.SetLength(start, 1)
1061         hyp.SetLength(end  , 0)
1062         return hyp
1063
1064     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1065     #  to build between the inner and the outer shells with a length that changes
1066     #  in Geometric progression
1067     #  @param start  the length of the first segment
1068     #  @param ratio  the common ratio of the geometric progression
1069     def GeometricProgression(self, start, ratio ):
1070         if self.algoType != "RadialPrism_3D":
1071             print "Prism_3D algorith doesn't support any hyposesis"
1072             return None
1073         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1074         hyp.SetStartLength( start )
1075         hyp.SetCommonRatio( ratio )
1076         return hyp
1077
1078     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1079     #  to build between the inner and the outer shells as geometric length increasing
1080     #  @param start for the length of the first segment
1081     #  @param end   for the length of the last  segment
1082     def StartEndLength(self, start, end):
1083         if self.algoType != "RadialPrism_3D":
1084             print "Prism_3D algorith doesn't support any hyposesis"
1085             return None
1086         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1087         hyp.SetLength(start, 1)
1088         hyp.SetLength(end  , 0)
1089         return hyp
1090
1091     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1092     #  to build between the inner and outer shells
1093     #  @param fineness defines the quality of the mesh within the range [0-1]
1094     def AutomaticLength(self, fineness=0):
1095         if self.algoType != "RadialPrism_3D":
1096             print "Prism_3D algorith doesn't support any hyposesis"
1097             return None
1098         hyp = self.OwnHypothesis("AutomaticLength")
1099         hyp.SetFineness( fineness )
1100         return hyp
1101
1102     pass # end of StdMeshersBuilder_Prism3D class
1103
1104 ## Defines Radial Prism 3D algorithm
1105
1106 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1107 #
1108 #  @ingroup l3_algos_3dextr
1109 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1110
1111     ## name of the dynamic method in smeshBuilder.Mesh class
1112     #  @internal
1113     meshMethod = "Prism"
1114     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1115     #  @internal
1116     algoType   = "RadialPrism_3D"
1117     ## doc string of the method
1118     #  @internal
1119     docHelper  = "Creates Raial Prism 3D algorithm for volumes"
1120
1121     ## Private constructor.
1122     #  @param mesh parent mesh object algorithm is assigned to
1123     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1124     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1125     def __init__(self, mesh, geom=0):
1126         Mesh_Algorithm.__init__(self)
1127         
1128         shape = geom
1129         if not shape:
1130             shape = mesh.geom
1131         self.Create(mesh, geom, "RadialPrism_3D")
1132         self.distribHyp = None
1133         self.nbLayers = None
1134         return
1135
1136 ## Base class for algorithms supporting radial distribution hypotheses
1137
1138 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1139
1140     def __init__(self):
1141         Mesh_Algorithm.__init__(self)
1142
1143         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1144         self.nbLayers = None
1145         pass
1146
1147     ## Return 2D hypothesis holding the 1D one
1148     def Get2DHypothesis(self):
1149         if not self.distribHyp:
1150             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1151         return self.distribHyp
1152
1153     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1154     #  hypothesis. Returns the created hypothesis
1155     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1156         if self.nbLayers:
1157             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1158         if self.distribHyp is None:
1159             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1160         else:
1161             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1162         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1163         self.mesh.smeshpyD.SetCurrentStudy( None )
1164         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1165         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1166         self.distribHyp.SetLayerDistribution( hyp )
1167         return hyp
1168
1169     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1170     #  @param n number of layers
1171     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1172     #                     the same parameters, else (default) - creates a new one
1173     def NumberOfLayers(self, n, UseExisting=0):
1174         if self.distribHyp:
1175             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1176         from salome.smesh.smeshBuilder import IsEqual
1177         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1178         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1179                                         CompareMethod=compFun)
1180         self.nbLayers.SetNumberOfLayers( n )
1181         return self.nbLayers
1182
1183     ## Defines "LocalLength" hypothesis, specifying the segment length
1184     #  @param l the length of segments
1185     #  @param p the precision of rounding
1186     def LocalLength(self, l, p=1e-07):
1187         hyp = self.OwnHypothesis("LocalLength", [l,p])
1188         hyp.SetLength(l)
1189         hyp.SetPrecision(p)
1190         return hyp
1191
1192     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1193     #  @param n the number of layers
1194     #  @param s the scale factor (optional)
1195     def NumberOfSegments(self, n, s=[]):
1196         if s == []:
1197             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1198         else:
1199             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1200             hyp.SetDistrType( 1 )
1201             hyp.SetScaleFactor(s)
1202         hyp.SetNumberOfSegments(n)
1203         return hyp
1204
1205     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1206     #  with a length that changes in arithmetic progression
1207     #  @param start  the length of the first segment
1208     #  @param end    the length of the last  segment
1209     def Arithmetic1D(self, start, end ):
1210         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1211         hyp.SetLength(start, 1)
1212         hyp.SetLength(end  , 0)
1213         return hyp
1214
1215     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1216     #  with a length that changes in Geometric progression
1217     #  @param start  the length of the first segment
1218     #  @param ratio  the common ratio of the geometric progression
1219     def GeometricProgression(self, start, ratio ):
1220         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1221         hyp.SetStartLength( start )
1222         hyp.SetCommonRatio( ratio )
1223         return hyp
1224
1225     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1226     #  as geometric length increasing
1227     #  @param start for the length of the first segment
1228     #  @param end   for the length of the last  segment
1229     def StartEndLength(self, start, end):
1230         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1231         hyp.SetLength(start, 1)
1232         hyp.SetLength(end  , 0)
1233         return hyp
1234
1235     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1236     #  @param fineness defines the quality of the mesh within the range [0-1]
1237     def AutomaticLength(self, fineness=0):
1238         hyp = self.OwnHypothesis("AutomaticLength")
1239         hyp.SetFineness( fineness )
1240         return hyp
1241
1242     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1243
1244 ## Defines a Radial Quadrangle 1D-2D algorithm
1245
1246 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1247 #
1248 #  @ingroup l2_algos_radialq
1249 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1250
1251     ## name of the dynamic method in smeshBuilder.Mesh class
1252     #  @internal
1253     meshMethod = "Quadrangle"
1254     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1255     #  @internal
1256     algoType   = RADIAL_QUAD
1257     ## doc string of the method
1258     #  @internal
1259     docHelper  = "Creates quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1260
1261     ## Private constructor.
1262     #  @param mesh parent mesh object algorithm is assigned to
1263     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1264     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1265     def __init__(self, mesh, geom=0):
1266         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1267         self.Create(mesh, geom, self.algoType)
1268
1269         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1270         self.nbLayers = None
1271         pass
1272
1273
1274 ## Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm
1275
1276 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1277 #
1278 #  @ingroup l2_algos_quad_ma
1279 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1280
1281     ## name of the dynamic method in smeshBuilder.Mesh class
1282     #  @internal
1283     meshMethod = "Quadrangle"
1284     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1285     #  @internal
1286     algoType   = QUAD_MA_PROJ
1287     ## doc string of the method
1288     #  @internal
1289     docHelper  = "Creates quadrangle 1D-2D algorithm for faces"
1290
1291     ## Private constructor.
1292     #  @param mesh parent mesh object algorithm is assigned to
1293     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1294     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1295     def __init__(self, mesh, geom=0):
1296         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1297         self.Create(mesh, geom, self.algoType)
1298         pass
1299
1300     pass
1301
1302 ## Defines a Polygon Per Face 2D algorithm
1303
1304 #  It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1305 #
1306 #  @ingroup l2_algos_quad_ma
1307 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1308
1309     ## name of the dynamic method in smeshBuilder.Mesh class
1310     #  @internal
1311     meshMethod = "Polygon"
1312     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1313     #  @internal
1314     algoType   = POLYGON
1315     ## flag pointing whether this algorithm should be used by default in dynamic method
1316     #  of smeshBuilder.Mesh class
1317     #  @internal
1318     isDefault  = True
1319     ## doc string of the method
1320     #  @internal
1321     docHelper  = "Creates polygon 2D algorithm for faces"
1322
1323     ## Private constructor.
1324     #  @param mesh parent mesh object algorithm is assigned to
1325     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1326     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1327     def __init__(self, mesh, geom=0):
1328         Mesh_Algorithm.__init__(self)
1329         self.Create(mesh, geom, self.algoType)
1330         pass
1331
1332     pass
1333
1334 ## Defines a Use Existing Elements 1D algorithm
1335 #
1336 #  It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1337 #
1338 #  @ingroup l3_algos_basic
1339 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1340
1341     ## name of the dynamic method in smeshBuilder.Mesh class
1342     #  @internal
1343     meshMethod = "UseExisting1DElements"
1344     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1345     #  @internal
1346     algoType   = "Import_1D"
1347     ## flag pointing whether this algorithm should be used by default in dynamic method
1348     #  of smeshBuilder.Mesh class
1349     #  @internal
1350     isDefault  = True
1351     ## doc string of the method
1352     #  @internal
1353     docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1354
1355     ## Private constructor.
1356     #  @param mesh parent mesh object algorithm is assigned to
1357     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1358     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1359     def __init__(self, mesh, geom=0):
1360         Mesh_Algorithm.__init__(self)
1361         self.Create(mesh, geom, self.algoType)
1362         pass
1363
1364     ## Defines "Source edges" hypothesis, specifying groups of edges to import
1365     #  @param groups list of groups of edges
1366     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1367     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1368     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1369     #                     the same parameters, else (default) - creates a new one
1370     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1371         for group in groups:
1372             from salome.smesh.smeshBuilder import AssureGeomPublished
1373             AssureGeomPublished( self.mesh, group )
1374         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1375                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1376         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1377                               UseExisting=UseExisting, CompareMethod=compFun)
1378         hyp.SetSourceEdges(groups)
1379         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1380         return hyp
1381
1382     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1383
1384 ## Defines a Use Existing Elements 1D-2D algorithm
1385 #
1386 #  It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1387 #
1388 #  @ingroup l3_algos_basic
1389 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1390
1391     ## name of the dynamic method in smeshBuilder.Mesh class
1392     #  @internal
1393     meshMethod = "UseExisting2DElements"
1394     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1395     #  @internal
1396     algoType   = "Import_1D2D"
1397     ## flag pointing whether this algorithm should be used by default in dynamic method
1398     #  of smeshBuilder.Mesh class
1399     #  @internal
1400     isDefault  = True
1401     ## doc string of the method
1402     #  @internal
1403     docHelper  = "Creates 1D-2D algorithm for faces with reusing of existing mesh elements"
1404
1405     ## Private constructor.
1406     #  @param mesh parent mesh object algorithm is assigned to
1407     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1408     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1409     def __init__(self, mesh, geom=0):
1410         Mesh_Algorithm.__init__(self)
1411         self.Create(mesh, geom, self.algoType)
1412         pass
1413
1414     ## Defines "Source faces" hypothesis, specifying groups of faces to import
1415     #  @param groups list of groups of faces
1416     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1417     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1418     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1419     #                     the same parameters, else (default) - creates a new one
1420     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1421         import SMESH
1422         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1423                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1424         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1425                               UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1426         if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1427             groups = [groups]
1428         hyp.SetSourceFaces(groups)
1429         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1430         self.mesh.AddHypothesis(hyp, self.geom)
1431         return hyp
1432
1433     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1434
1435 ## Defines a Body Fitting 3D algorithm
1436 #
1437 #  It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1438 #
1439 #  @ingroup l3_algos_basic
1440 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1441
1442     ## name of the dynamic method in smeshBuilder.Mesh class
1443     #  @internal
1444     meshMethod = "BodyFitted"
1445     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1446     #  @internal
1447     algoType   = "Cartesian_3D"
1448     ## flag pointing whether this algorithm should be used by default in dynamic method
1449     #  of smeshBuilder.Mesh class
1450     #  @internal
1451     isDefault  = True
1452     ## doc string of the method
1453     #  @internal
1454     docHelper  = "Creates Body Fitting 3D algorithm for volumes"
1455
1456     ## Private constructor.
1457     #  @param mesh parent mesh object algorithm is assigned to
1458     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1459     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1460     def __init__(self, mesh, geom=0):
1461         self.Create(mesh, geom, self.algoType)
1462         self.hyp = None
1463         pass
1464
1465     ## Defines "Body Fitting parameters" hypothesis
1466     #  @param xGridDef is definition of the grid along the X asix.
1467     #  It can be in either of two following forms:
1468     #  - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1469     #  - Functions f(t) defining grid spacing at each point on grid axis. If there are
1470     #    several functions, they must be accompanied by relative coordinates of
1471     #    points dividing the whole shape into ranges where the functions apply; points
1472     #    coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1473     #    function f(t) varies from 0.0 to 1.0 witin a shape range. 
1474     #    Examples:
1475     #    - "10.5" - defines a grid with a constant spacing
1476     #    - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1477     #  @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1478     #  @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1479     #  @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1480     #         a polyhedron of size less than hexSize/sizeThreshold is not created.
1481     #  @param implEdges enables implementation of geometrical edges into the mesh.
1482     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1483         if not self.hyp:
1484             compFun = lambda hyp, args: False
1485             self.hyp = self.Hypothesis("CartesianParameters3D",
1486                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1487                                        UseExisting=False, CompareMethod=compFun)
1488         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1489             self.mesh.AddHypothesis( self.hyp, self.geom )
1490
1491         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1492             if not gridDef: raise ValueError, "Empty grid definition"
1493             if isinstance( gridDef, str ):
1494                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1495             elif isinstance( gridDef[0], str ):
1496                 self.hyp.SetGridSpacing( gridDef, [], axis )
1497             elif isinstance( gridDef[0], int ) or \
1498                  isinstance( gridDef[0], float ):
1499                 self.hyp.SetGrid(gridDef, axis )
1500             else:
1501                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1502         self.hyp.SetSizeThreshold( sizeThreshold )
1503         self.hyp.SetToAddEdges( implEdges )
1504         return self.hyp
1505
1506     ## Defines custom directions of axes of the grid
1507     #  @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1508     #  @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1509     #  @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1510     def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1511         import GEOM
1512         if hasattr( xAxis, "__getitem__" ):
1513             xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1514         elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1515             xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1516         if hasattr( yAxis, "__getitem__" ):
1517             yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1518         elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1519             yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1520         if hasattr( zAxis, "__getitem__" ):
1521             zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1522         elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1523             zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1524         if not self.hyp:
1525             self.hyp = self.Hypothesis("CartesianParameters3D")
1526         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1527             self.mesh.AddHypothesis( self.hyp, self.geom )
1528         self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1529         return self.hyp
1530
1531     ## Automatically defines directions of axes of the grid at which
1532     #  a number of generated hexahedra is maximal
1533     #  @param isOrthogonal defines whether the axes mush be orthogonal
1534     def SetOptimalAxesDirs(self, isOrthogonal=True):
1535         if not self.hyp:
1536             self.hyp = self.Hypothesis("CartesianParameters3D")
1537         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1538             self.mesh.AddHypothesis( self.hyp, self.geom )
1539         x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1540         self.hyp.SetAxesDirs( x,y,z )
1541         return self.hyp
1542
1543     ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1544     #  through the fixed point in each direction at which the grid is defined
1545     #  by spacing
1546     #  @param p coordinates of the fixed point. Either SMESH.PointStruct or
1547     #         a vertex or 3 components of coordinates.
1548     #  @param toUnset defines whether the fixed point is defined or removed.
1549     def SetFixedPoint( self, p, toUnset=False ):
1550         import SMESH, GEOM
1551         if toUnset:
1552             if not self.hyp: return
1553             p = SMESH.PointStruct(0,0,0)
1554         elif hasattr( p, "__getitem__" ):
1555             p = SMESH.PointStruct( p[0],p[1],p[2] )
1556         elif isinstance( p, GEOM._objref_GEOM_Object ):
1557             p = self.mesh.smeshpyD.GetPointStruct( p )
1558         if not self.hyp:
1559             self.hyp = self.Hypothesis("CartesianParameters3D")
1560         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1561             self.mesh.AddHypothesis( self.hyp, self.geom )
1562         self.hyp.SetFixedPoint( p, toUnset )
1563         return self.hyp
1564         
1565
1566     pass # end of StdMeshersBuilder_Cartesian_3D class
1567
1568 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1569 #  segments usable by 2D algoritms
1570 #
1571 #  It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1572 #
1573 #  @ingroup l3_algos_basic
1574 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1575
1576     ## name of the dynamic method in smeshBuilder.Mesh class
1577     #  @internal
1578     meshMethod = "UseExistingSegments"
1579     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1580     #  @internal
1581     algoType   = "UseExisting_1D"
1582     ## doc string of the method
1583     #  @internal
1584     docHelper  = "Creates 1D algorithm allowing batch meshing of edges"
1585
1586     ## Private constructor.
1587     #  @param mesh parent mesh object algorithm is assigned to
1588     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1589     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1590     def __init__(self, mesh, geom=0):
1591         self.Create(mesh, geom, self.algoType)
1592         pass
1593
1594     pass # end of StdMeshersBuilder_UseExisting_1D class
1595
1596 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1597 #  faces usable by 3D algoritms
1598 #
1599 #  It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1600 #
1601 #  @ingroup l3_algos_basic
1602 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1603
1604     ## name of the dynamic method in smeshBuilder.Mesh class
1605     #  @internal
1606     meshMethod = "UseExistingFaces"
1607     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1608     #  @internal
1609     algoType   = "UseExisting_2D"
1610     ## doc string of the method
1611     #  @internal
1612     docHelper  = "Creates 2D algorithm allowing batch meshing of faces"
1613
1614     ## Private constructor.
1615     #  @param mesh parent mesh object algorithm is assigned to
1616     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1617     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1618     def __init__(self, mesh, geom=0):
1619         self.Create(mesh, geom, self.algoType)
1620         pass
1621
1622     pass # end of StdMeshersBuilder_UseExisting_2D class