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