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