Salome HOME
Merge 'master' branch into 'V9_dev' branch.
[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 isinstance(vertex, int):
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("Attempt to create SegmentAroundVertex_0D algorithm 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     ## flag pointing whether this algorithm should be used by default in dynamic method
957     #  of smeshBuilder.Mesh class
958     #  @internal
959     isDefault  = True
960
961     ## Private constructor.
962     #  @param mesh parent mesh object algorithm is assigned to
963     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
964     #              if it is @c 0 (default), the algorithm is assigned to the main shape
965     def __init__(self, mesh, geom=0):
966         Mesh_Algorithm.__init__(self)
967         
968         shape = geom
969         if not shape:
970             shape = mesh.geom
971         isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
972         if not isRadial:
973             self.Create(mesh, geom, "Prism_3D")
974             pass
975         else:
976             self.algoType = "RadialPrism_3D"
977             self.Create(mesh, geom, "RadialPrism_3D")
978             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
979             self.nbLayers = None
980             pass
981         pass
982
983     ## Return 3D hypothesis holding the 1D one
984     def Get3DHypothesis(self):
985         if self.algoType != "RadialPrism_3D":
986             print("Prism_3D algorithm doesn't support any hypothesis")
987             return None
988         return self.distribHyp
989
990     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
991     #  hypothesis. Returns the created hypothesis
992     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
993         if self.algoType != "RadialPrism_3D":
994             print("Prism_3D algorithm doesn't support any hypothesis")
995             return None
996         if not self.nbLayers is None:
997             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
998             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
999         self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1000         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1001         self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1002         if not self.distribHyp:
1003             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1004         self.distribHyp.SetLayerDistribution( hyp )
1005         return hyp
1006
1007     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1008     #  prisms to build between the inner and outer shells
1009     #  @param n number of layers
1010     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1011     #                     the same parameters, else (default) - creates a new one
1012     def NumberOfLayers(self, n, UseExisting=0):
1013         if self.algoType != "RadialPrism_3D":
1014             print("Prism_3D algorithm doesn't support any hypothesis")
1015             return None
1016         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1017         from salome.smesh.smeshBuilder import IsEqual
1018         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1019         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1020                                         CompareMethod=compFun)
1021         self.nbLayers.SetNumberOfLayers( n )
1022         return self.nbLayers
1023
1024     ## Defines "LocalLength" hypothesis, specifying the segment length
1025     #  to build between the inner and the outer shells
1026     #  @param l the length of segments
1027     #  @param p the precision of rounding
1028     def LocalLength(self, l, p=1e-07):
1029         if self.algoType != "RadialPrism_3D":
1030             print("Prism_3D algorithm doesn't support any hypothesis")
1031             return None
1032         hyp = self.OwnHypothesis("LocalLength", [l,p])
1033         hyp.SetLength(l)
1034         hyp.SetPrecision(p)
1035         return hyp
1036
1037     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1038     #  prisms to build between the inner and the outer shells.
1039     #  @param n the number of layers
1040     #  @param s the scale factor (optional)
1041     def NumberOfSegments(self, n, s=[]):
1042         if self.algoType != "RadialPrism_3D":
1043             print("Prism_3D algorithm doesn't support any hypothesis")
1044             return None
1045         if not s:
1046             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1047         else:
1048             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1049             hyp.SetScaleFactor(s)
1050         hyp.SetNumberOfSegments(n)
1051         return hyp
1052
1053     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1054     #  to build between the inner and the outer shells with a length that changes
1055     #  in arithmetic progression
1056     #  @param start  the length of the first segment
1057     #  @param end    the length of the last  segment
1058     def Arithmetic1D(self, start, end ):
1059         if self.algoType != "RadialPrism_3D":
1060             print("Prism_3D algorithm doesn't support any hypothesis")
1061             return None
1062         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1063         hyp.SetLength(start, 1)
1064         hyp.SetLength(end  , 0)
1065         return hyp
1066
1067     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1068     #  to build between the inner and the outer shells with a length that changes
1069     #  in Geometric progression
1070     #  @param start  the length of the first segment
1071     #  @param ratio  the common ratio of the geometric progression
1072     def GeometricProgression(self, start, ratio ):
1073         if self.algoType != "RadialPrism_3D":
1074             print("Prism_3D algorithm doesn't support any hypothesis")
1075             return None
1076         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1077         hyp.SetStartLength( start )
1078         hyp.SetCommonRatio( ratio )
1079         return hyp
1080
1081     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1082     #  to build between the inner and the outer shells as geometric length increasing
1083     #  @param start for the length of the first segment
1084     #  @param end   for the length of the last  segment
1085     def StartEndLength(self, start, end):
1086         if self.algoType != "RadialPrism_3D":
1087             print("Prism_3D algorithm doesn't support any hypothesis")
1088             return None
1089         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1090         hyp.SetLength(start, 1)
1091         hyp.SetLength(end  , 0)
1092         return hyp
1093
1094     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1095     #  to build between the inner and outer shells
1096     #  @param fineness defines the quality of the mesh within the range [0-1]
1097     def AutomaticLength(self, fineness=0):
1098         if self.algoType != "RadialPrism_3D":
1099             print("Prism_3D algorithm doesn't support any hypothesis")
1100             return None
1101         hyp = self.OwnHypothesis("AutomaticLength")
1102         hyp.SetFineness( fineness )
1103         return hyp
1104
1105     pass # end of StdMeshersBuilder_Prism3D class
1106
1107 ## Defines Radial Prism 3D algorithm
1108
1109 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1110 #
1111 #  @ingroup l3_algos_3dextr
1112 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1113
1114     ## name of the dynamic method in smeshBuilder.Mesh class
1115     #  @internal
1116     meshMethod = "Prism"
1117     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1118     #  @internal
1119     algoType   = "RadialPrism_3D"
1120     ## doc string of the method
1121     #  @internal
1122     docHelper  = "Creates Raial Prism 3D algorithm for volumes"
1123
1124     ## Private constructor.
1125     #  @param mesh parent mesh object algorithm is assigned to
1126     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1127     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1128     def __init__(self, mesh, geom=0):
1129         Mesh_Algorithm.__init__(self)
1130         
1131         shape = geom
1132         if not shape:
1133             shape = mesh.geom
1134         self.Create(mesh, geom, "RadialPrism_3D")
1135         self.distribHyp = None
1136         self.nbLayers = None
1137         return
1138
1139 ## Base class for algorithms supporting radial distribution hypotheses
1140
1141 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1142
1143     def __init__(self):
1144         Mesh_Algorithm.__init__(self)
1145
1146         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1147         self.nbLayers = None
1148         pass
1149
1150     ## Return 2D hypothesis holding the 1D one
1151     def Get2DHypothesis(self):
1152         if not self.distribHyp:
1153             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1154         return self.distribHyp
1155
1156     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1157     #  hypothesis. Returns the created hypothesis
1158     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1159         if self.nbLayers:
1160             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1161         if self.distribHyp is None:
1162             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1163         else:
1164             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1165         self.mesh.smeshpyD.SetEnablePublish( False )
1166         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1167         self.mesh.smeshpyD.SetEnablePublish( True )
1168         self.distribHyp.SetLayerDistribution( hyp )
1169         return hyp
1170
1171     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1172     #  @param n number of layers
1173     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1174     #                     the same parameters, else (default) - creates a new one
1175     def NumberOfLayers(self, n, UseExisting=0):
1176         if self.distribHyp:
1177             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1178         from salome.smesh.smeshBuilder import IsEqual
1179         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1180         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1181                                         CompareMethod=compFun)
1182         self.nbLayers.SetNumberOfLayers( n )
1183         return self.nbLayers
1184
1185     ## Defines "LocalLength" hypothesis, specifying the segment length
1186     #  @param l the length of segments
1187     #  @param p the precision of rounding
1188     def LocalLength(self, l, p=1e-07):
1189         hyp = self.OwnHypothesis("LocalLength", [l,p])
1190         hyp.SetLength(l)
1191         hyp.SetPrecision(p)
1192         return hyp
1193
1194     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1195     #  @param n the number of layers
1196     #  @param s the scale factor (optional)
1197     def NumberOfSegments(self, n, s=[]):
1198         if s == []:
1199             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1200         else:
1201             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1202             hyp.SetDistrType( 1 )
1203             hyp.SetScaleFactor(s)
1204         hyp.SetNumberOfSegments(n)
1205         return hyp
1206
1207     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1208     #  with a length that changes in arithmetic progression
1209     #  @param start  the length of the first segment
1210     #  @param end    the length of the last  segment
1211     def Arithmetic1D(self, start, end ):
1212         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1213         hyp.SetLength(start, 1)
1214         hyp.SetLength(end  , 0)
1215         return hyp
1216
1217     ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1218     #  with a length that changes in Geometric progression
1219     #  @param start  the length of the first segment
1220     #  @param ratio  the common ratio of the geometric progression
1221     def GeometricProgression(self, start, ratio ):
1222         hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1223         hyp.SetStartLength( start )
1224         hyp.SetCommonRatio( ratio )
1225         return hyp
1226
1227     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1228     #  as geometric length increasing
1229     #  @param start for the length of the first segment
1230     #  @param end   for the length of the last  segment
1231     def StartEndLength(self, start, end):
1232         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1233         hyp.SetLength(start, 1)
1234         hyp.SetLength(end  , 0)
1235         return hyp
1236
1237     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1238     #  @param fineness defines the quality of the mesh within the range [0-1]
1239     def AutomaticLength(self, fineness=0):
1240         hyp = self.OwnHypothesis("AutomaticLength")
1241         hyp.SetFineness( fineness )
1242         return hyp
1243
1244     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1245
1246 ## Defines a Radial Quadrangle 1D-2D algorithm
1247
1248 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1249 #
1250 #  @ingroup l2_algos_radialq
1251 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1252
1253     ## name of the dynamic method in smeshBuilder.Mesh class
1254     #  @internal
1255     meshMethod = "Quadrangle"
1256     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1257     #  @internal
1258     algoType   = RADIAL_QUAD
1259     ## doc string of the method
1260     #  @internal
1261     docHelper  = "Creates quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1262
1263     ## Private constructor.
1264     #  @param mesh parent mesh object algorithm is assigned to
1265     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1266     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1267     def __init__(self, mesh, geom=0):
1268         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1269         self.Create(mesh, geom, self.algoType)
1270
1271         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1272         self.nbLayers = None
1273         pass
1274
1275
1276 ## Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm
1277
1278 #  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1279 #
1280 #  @ingroup l2_algos_quad_ma
1281 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1282
1283     ## name of the dynamic method in smeshBuilder.Mesh class
1284     #  @internal
1285     meshMethod = "Quadrangle"
1286     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1287     #  @internal
1288     algoType   = QUAD_MA_PROJ
1289     ## doc string of the method
1290     #  @internal
1291     docHelper  = "Creates quadrangle 1D-2D algorithm for faces"
1292
1293     ## Private constructor.
1294     #  @param mesh parent mesh object algorithm is assigned to
1295     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1296     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1297     def __init__(self, mesh, geom=0):
1298         StdMeshersBuilder_RadialAlgorithm.__init__(self)
1299         self.Create(mesh, geom, self.algoType)
1300         pass
1301
1302     pass
1303
1304 ## Defines a Polygon Per Face 2D algorithm
1305
1306 #  It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1307 #
1308 #  @ingroup l2_algos_quad_ma
1309 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1310
1311     ## name of the dynamic method in smeshBuilder.Mesh class
1312     #  @internal
1313     meshMethod = "Polygon"
1314     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1315     #  @internal
1316     algoType   = POLYGON
1317     ## flag pointing whether this algorithm should be used by default in dynamic method
1318     #  of smeshBuilder.Mesh class
1319     #  @internal
1320     isDefault  = True
1321     ## doc string of the method
1322     #  @internal
1323     docHelper  = "Creates polygon 2D algorithm for faces"
1324
1325     ## Private constructor.
1326     #  @param mesh parent mesh object algorithm is assigned to
1327     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1328     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1329     def __init__(self, mesh, geom=0):
1330         Mesh_Algorithm.__init__(self)
1331         self.Create(mesh, geom, self.algoType)
1332         pass
1333
1334     pass
1335
1336 ## Defines a Use Existing Elements 1D algorithm
1337 #
1338 #  It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1339 #
1340 #  @ingroup l3_algos_basic
1341 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1342
1343     ## name of the dynamic method in smeshBuilder.Mesh class
1344     #  @internal
1345     meshMethod = "UseExisting1DElements"
1346     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1347     #  @internal
1348     algoType   = "Import_1D"
1349     ## flag pointing whether this algorithm should be used by default in dynamic method
1350     #  of smeshBuilder.Mesh class
1351     #  @internal
1352     isDefault  = True
1353     ## doc string of the method
1354     #  @internal
1355     docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1356
1357     ## Private constructor.
1358     #  @param mesh parent mesh object algorithm is assigned to
1359     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1360     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1361     def __init__(self, mesh, geom=0):
1362         Mesh_Algorithm.__init__(self)
1363         self.Create(mesh, geom, self.algoType)
1364         pass
1365
1366     ## Defines "Source edges" hypothesis, specifying groups of edges to import
1367     #  @param groups list of groups of edges
1368     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1369     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1370     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1371     #                     the same parameters, else (default) - creates a new one
1372     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1373         for group in groups:
1374             from salome.smesh.smeshBuilder import AssureGeomPublished
1375             AssureGeomPublished( self.mesh, group )
1376         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1377                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1378         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1379                               UseExisting=UseExisting, CompareMethod=compFun)
1380         hyp.SetSourceEdges(groups)
1381         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1382         return hyp
1383
1384     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1385
1386 ## Defines a Use Existing Elements 1D-2D algorithm
1387 #
1388 #  It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1389 #
1390 #  @ingroup l3_algos_basic
1391 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1392
1393     ## name of the dynamic method in smeshBuilder.Mesh class
1394     #  @internal
1395     meshMethod = "UseExisting2DElements"
1396     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1397     #  @internal
1398     algoType   = "Import_1D2D"
1399     ## flag pointing whether this algorithm should be used by default in dynamic method
1400     #  of smeshBuilder.Mesh class
1401     #  @internal
1402     isDefault  = True
1403     ## doc string of the method
1404     #  @internal
1405     docHelper  = "Creates 1D-2D algorithm for faces with reusing of existing mesh elements"
1406
1407     ## Private constructor.
1408     #  @param mesh parent mesh object algorithm is assigned to
1409     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1410     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1411     def __init__(self, mesh, geom=0):
1412         Mesh_Algorithm.__init__(self)
1413         self.Create(mesh, geom, self.algoType)
1414         pass
1415
1416     ## Defines "Source faces" hypothesis, specifying groups of faces to import
1417     #  @param groups list of groups of faces
1418     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1419     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1420     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1421     #                     the same parameters, else (default) - creates a new one
1422     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1423         import SMESH
1424         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1425                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1426         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1427                               UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1428         if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1429             groups = [groups]
1430         hyp.SetSourceFaces(groups)
1431         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1432         self.mesh.AddHypothesis(hyp, self.geom)
1433         return hyp
1434
1435     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1436
1437 ## Defines a Body Fitting 3D algorithm
1438 #
1439 #  It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1440 #
1441 #  @ingroup l3_algos_basic
1442 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1443
1444     ## name of the dynamic method in smeshBuilder.Mesh class
1445     #  @internal
1446     meshMethod = "BodyFitted"
1447     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1448     #  @internal
1449     algoType   = "Cartesian_3D"
1450     ## flag pointing whether this algorithm should be used by default in dynamic method
1451     #  of smeshBuilder.Mesh class
1452     #  @internal
1453     isDefault  = True
1454     ## doc string of the method
1455     #  @internal
1456     docHelper  = "Creates Body Fitting 3D algorithm for volumes"
1457
1458     ## Private constructor.
1459     #  @param mesh parent mesh object algorithm is assigned to
1460     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1461     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1462     def __init__(self, mesh, geom=0):
1463         self.Create(mesh, geom, self.algoType)
1464         self.hyp = None
1465         pass
1466
1467     ## Defines "Body Fitting parameters" hypothesis
1468     #  @param xGridDef is definition of the grid along the X asix.
1469     #  It can be in either of two following forms:
1470     #  - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1471     #  - Functions f(t) defining grid spacing at each point on grid axis. If there are
1472     #    several functions, they must be accompanied by relative coordinates of
1473     #    points dividing the whole shape into ranges where the functions apply; points
1474     #    coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1475     #    function f(t) varies from 0.0 to 1.0 within a shape range. 
1476     #    Examples:
1477     #    - "10.5" - defines a grid with a constant spacing
1478     #    - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1479     #  @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1480     #  @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1481     #  @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1482     #         a polyhedron of size less than hexSize/sizeThreshold is not created.
1483     #  @param implEdges enables implementation of geometrical edges into the mesh.
1484     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1485         if not self.hyp:
1486             compFun = lambda hyp, args: False
1487             self.hyp = self.Hypothesis("CartesianParameters3D",
1488                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1489                                        UseExisting=False, CompareMethod=compFun)
1490         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1491             self.mesh.AddHypothesis( self.hyp, self.geom )
1492
1493         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1494             if not gridDef: raise ValueError("Empty grid definition")
1495             if isinstance( gridDef, str ):
1496                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1497             elif isinstance( gridDef[0], str ):
1498                 self.hyp.SetGridSpacing( gridDef, [], axis )
1499             elif isinstance( gridDef[0], int ) or \
1500                  isinstance( gridDef[0], float ):
1501                 self.hyp.SetGrid(gridDef, axis )
1502             else:
1503                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1504         self.hyp.SetSizeThreshold( sizeThreshold )
1505         self.hyp.SetToAddEdges( implEdges )
1506         return self.hyp
1507
1508     ## Defines custom directions of axes of the grid
1509     #  @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1510     #  @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1511     #  @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1512     def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1513         import GEOM
1514         if hasattr( xAxis, "__getitem__" ):
1515             xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1516         elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1517             xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1518         if hasattr( yAxis, "__getitem__" ):
1519             yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1520         elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1521             yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1522         if hasattr( zAxis, "__getitem__" ):
1523             zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1524         elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1525             zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1526         if not self.hyp:
1527             self.hyp = self.Hypothesis("CartesianParameters3D")
1528         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1529             self.mesh.AddHypothesis( self.hyp, self.geom )
1530         self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1531         return self.hyp
1532
1533     ## Automatically defines directions of axes of the grid at which
1534     #  a number of generated hexahedra is maximal
1535     #  @param isOrthogonal defines whether the axes mush be orthogonal
1536     def SetOptimalAxesDirs(self, isOrthogonal=True):
1537         if not self.hyp:
1538             self.hyp = self.Hypothesis("CartesianParameters3D")
1539         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1540             self.mesh.AddHypothesis( self.hyp, self.geom )
1541         x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1542         self.hyp.SetAxesDirs( x,y,z )
1543         return self.hyp
1544
1545     ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1546     #  through the fixed point in each direction at which the grid is defined
1547     #  by spacing
1548     #  @param p coordinates of the fixed point. Either SMESH.PointStruct or
1549     #         a vertex or 3 components of coordinates.
1550     #  @param toUnset defines whether the fixed point is defined or removed.
1551     def SetFixedPoint( self, p, toUnset=False ):
1552         import SMESH, GEOM
1553         if toUnset:
1554             if not self.hyp: return
1555             p = SMESH.PointStruct(0,0,0)
1556         elif hasattr( p, "__getitem__" ):
1557             p = SMESH.PointStruct( p[0],p[1],p[2] )
1558         elif isinstance( p, GEOM._objref_GEOM_Object ):
1559             p = self.mesh.smeshpyD.GetPointStruct( p )
1560         if not self.hyp:
1561             self.hyp = self.Hypothesis("CartesianParameters3D")
1562         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1563             self.mesh.AddHypothesis( self.hyp, self.geom )
1564         self.hyp.SetFixedPoint( p, toUnset )
1565         return self.hyp
1566         
1567
1568     pass # end of StdMeshersBuilder_Cartesian_3D class
1569
1570 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1571 #  segments usable by 2D algorithms
1572 #
1573 #  It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1574 #
1575 #  @ingroup l3_algos_basic
1576 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1577
1578     ## name of the dynamic method in smeshBuilder.Mesh class
1579     #  @internal
1580     meshMethod = "UseExistingSegments"
1581     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1582     #  @internal
1583     algoType   = "UseExisting_1D"
1584     ## doc string of the method
1585     #  @internal
1586     docHelper  = "Creates 1D algorithm allowing batch meshing of edges"
1587
1588     ## Private constructor.
1589     #  @param mesh parent mesh object algorithm is assigned to
1590     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1591     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1592     def __init__(self, mesh, geom=0):
1593         self.Create(mesh, geom, self.algoType)
1594         pass
1595
1596     pass # end of StdMeshersBuilder_UseExisting_1D class
1597
1598 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1599 #  faces usable by 3D algorithms
1600 #
1601 #  It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1602 #
1603 #  @ingroup l3_algos_basic
1604 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1605
1606     ## name of the dynamic method in smeshBuilder.Mesh class
1607     #  @internal
1608     meshMethod = "UseExistingFaces"
1609     ## type of algorithm used with helper function in smeshBuilder.Mesh class
1610     #  @internal
1611     algoType   = "UseExisting_2D"
1612     ## doc string of the method
1613     #  @internal
1614     docHelper  = "Creates 2D algorithm allowing batch meshing of faces"
1615
1616     ## Private constructor.
1617     #  @param mesh parent mesh object algorithm is assigned to
1618     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1619     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1620     def __init__(self, mesh, geom=0):
1621         self.Create(mesh, geom, self.algoType)
1622         pass
1623
1624     pass # end of StdMeshersBuilder_UseExisting_2D class