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