Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersDC.py
1 # Copyright (C) 2007-2012  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.
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 from smesh import Mesh_Algorithm, AssureGeomPublished, IsEqual, ParseParameters
21 from smesh import GetName, TreatHypoStatus
22 from smeshDC import Mesh
23
24 import StdMeshers
25
26 # Types of algorithms
27 REGULAR     = "Regular_1D"
28 PYTHON      = "Python_1D"
29 COMPOSITE   = "CompositeSegment_1D"
30 MEFISTO     = "MEFISTO_2D"
31 Hexa        = "Hexa_3D"
32 QUADRANGLE  = "Quadrangle_2D"
33 RADIAL_QUAD = "RadialQuadrangle_1D2D"
34
35
36 # import items of enum QuadType
37 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
38
39
40 # Public class: Mesh_Segment
41 # --------------------------
42
43 ## Class to define a REGULAR 1D algorithm for discretization. It is created by
44 #  calling Mesh.Segment(geom=0)
45 #
46 #  @ingroup l3_algos_basic
47 class StdMeshersDC_Segment(Mesh_Algorithm):
48
49     ## Name of method of class Mesh creating an instance of this class
50     meshMethod = "Segment"
51     ## Name of algorithm type
52     algoType   = REGULAR
53     isDefault  = True
54
55     ## Private constructor.
56     def __init__(self, mesh, geom=0):
57         Mesh_Algorithm.__init__(self)
58         self.Create(mesh, geom, self.algoType)
59
60     ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
61     #  @param l for the length of segments that cut an edge
62     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
63     #                    the same parameters, else (default) - creates a new one
64     #  @param p precision, used for calculation of the number of segments.
65     #           The precision should be a positive, meaningful value within the range [0,1].
66     #           In general, the number of segments is calculated with the formula:
67     #           nb = ceil((edge_length / l) - p)
68     #           Function ceil rounds its argument to the higher integer.
69     #           So, p=0 means rounding of (edge_length / l) to the higher integer,
70     #               p=0.5 means rounding of (edge_length / l) to the nearest integer,
71     #               p=1 means rounding of (edge_length / l) to the lower integer.
72     #           Default value is 1e-07.
73     #  @return an instance of StdMeshers_LocalLength hypothesis
74     #  @ingroup l3_hypos_1dhyps
75     def LocalLength(self, l, UseExisting=0, p=1e-07):
76         comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
77         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
78         hyp.SetLength(l)
79         hyp.SetPrecision(p)
80         return hyp
81
82     ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
83     #  @param length is optional maximal allowed length of segment, if it is omitted
84     #                the preestimated length is used that depends on geometry size
85     #  @param UseExisting if ==true - searches for an existing hypothesis created with
86     #                     the same parameters, else (default) - creates a new one
87     #  @return an instance of StdMeshers_MaxLength hypothesis
88     #  @ingroup l3_hypos_1dhyps
89     def MaxSize(self, length=0.0, UseExisting=0):
90         hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
91         if length > 0.0:
92             # set given length
93             hyp.SetLength(length)
94         if not UseExisting:
95             # set preestimated length
96             gen = self.mesh.smeshpyD
97             initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
98                                                        self.mesh.GetMesh(), self.mesh.GetShape(),
99                                                        False) # <- byMesh
100             preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
101             if preHyp:
102                 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
103                 pass
104             pass
105         hyp.SetUsePreestimatedLength( length == 0.0 )
106         return hyp
107
108     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
109     #  @param n for the number of segments that cut an edge
110     #  @param s for the scale factor (optional)
111     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
112     #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
113     #  @param UseExisting if ==true - searches for an existing hypothesis created with
114     #                     the same parameters, else (default) - create a new one
115     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
116     #  @ingroup l3_hypos_1dhyps
117     def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
118         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
119             reversedEdges, UseExisting = [], reversedEdges
120         entry = self.MainShapeEntry()
121         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
122         if s == []:
123             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
124                                   UseExisting=UseExisting,
125                                   CompareMethod=self._compareNumberOfSegments)
126         else:
127             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
128                                   UseExisting=UseExisting,
129                                   CompareMethod=self._compareNumberOfSegments)
130             hyp.SetDistrType( 1 )
131             hyp.SetScaleFactor(s)
132         hyp.SetNumberOfSegments(n)
133         hyp.SetReversedEdges( reversedEdgeInd )
134         hyp.SetObjectEntry( entry )
135         return hyp
136
137     ## Private method
138     ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
139     def _compareNumberOfSegments(self, hyp, args):
140         if hyp.GetNumberOfSegments() == args[0]:
141             if len(args) == 3:
142                 if hyp.GetReversedEdges() == args[1]:
143                     if not args[1] or hyp.GetObjectEntry() == args[2]:
144                         return True
145             else:
146                 if hyp.GetReversedEdges() == args[2]:
147                     if not args[2] or hyp.GetObjectEntry() == args[3]:
148                         if hyp.GetDistrType() == 1:
149                             if IsEqual(hyp.GetScaleFactor(), args[1]):
150                                 return True
151         return False
152
153     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
154     #  @param start defines the length of the first segment
155     #  @param end   defines the length of the last  segment
156     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
157     #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
158     #  @param UseExisting if ==true - searches for an existing hypothesis created with
159     #                     the same parameters, else (default) - creates a new one
160     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
161     #  @ingroup l3_hypos_1dhyps
162     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
163         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
164             reversedEdges, UseExisting = [], reversedEdges
165         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
166         entry = self.MainShapeEntry()
167         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
168                                       IsEqual(hyp.GetLength(0), args[1]) and \
169                                       hyp.GetReversedEdges() == args[2]  and \
170                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
171         hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
172                               UseExisting=UseExisting, CompareMethod=compFun)
173         hyp.SetStartLength(start)
174         hyp.SetEndLength(end)
175         hyp.SetReversedEdges( reversedEdgeInd )
176         hyp.SetObjectEntry( entry )
177         return hyp
178
179     ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
180     # on curve from 0 to 1 (additionally it is neecessary to check
181     # orientation of edges and create list of reversed edges if it is
182     # needed) and sets numbers of segments between given points (default
183     # values are equals 1
184     #  @param points defines the list of parameters on curve
185     #  @param nbSegs defines the list of numbers of segments
186     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
187     #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
188     #  @param UseExisting if ==true - searches for an existing hypothesis created with
189     #                     the same parameters, else (default) - creates a new one
190     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
191     #  @ingroup l3_hypos_1dhyps
192     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
193         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
194             reversedEdges, UseExisting = [], reversedEdges
195         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
196         entry = self.MainShapeEntry()
197         compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
198                                       hyp.GetNbSegments() == args[1] and \
199                                       hyp.GetReversedEdges() == args[2] and \
200                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
201         hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
202                               UseExisting=UseExisting, CompareMethod=compFun)
203         hyp.SetPoints(points)
204         hyp.SetNbSegments(nbSegs)
205         hyp.SetReversedEdges(reversedEdgeInd)
206         hyp.SetObjectEntry(entry)
207         return hyp
208
209     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
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_StartEndLength hypothesis
217     #  @ingroup l3_hypos_1dhyps
218     def StartEndLength(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         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
224                                       IsEqual(hyp.GetLength(0), args[1]) and \
225                                       hyp.GetReversedEdges() == args[2]  and \
226                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
227         hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
228                               UseExisting=UseExisting, CompareMethod=compFun)
229         hyp.SetStartLength(start)
230         hyp.SetEndLength(end)
231         hyp.SetReversedEdges( reversedEdgeInd )
232         hyp.SetObjectEntry( entry )
233         return hyp
234
235     ## Defines "Deflection1D" hypothesis
236     #  @param d for the deflection
237     #  @param UseExisting if ==true - searches for an existing hypothesis created with
238     #                     the same parameters, else (default) - create a new one
239     #  @ingroup l3_hypos_1dhyps
240     def Deflection1D(self, d, UseExisting=0):
241         compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
242         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
243         hyp.SetDeflection(d)
244         return hyp
245
246     ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
247     #  the opposite side in case of quadrangular faces
248     #  @ingroup l3_hypos_additi
249     def Propagation(self):
250         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
251
252     ## Defines "AutomaticLength" hypothesis
253     #  @param fineness for the fineness [0-1]
254     #  @param UseExisting if ==true - searches for an existing hypothesis created with the
255     #                     same parameters, else (default) - create a new one
256     #  @ingroup l3_hypos_1dhyps
257     def AutomaticLength(self, fineness=0, UseExisting=0):
258         compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
259         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
260                               CompareMethod=compFun)
261         hyp.SetFineness( fineness )
262         return hyp
263
264     ## Defines "SegmentLengthAroundVertex" hypothesis
265     #  @param length for the segment length
266     #  @param vertex for the length localization: the vertex index [0,1] | vertex object.
267     #         Any other integer value means that the hypothesis will be set on the
268     #         whole 1D shape, where Mesh_Segment algorithm is assigned.
269     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
270     #                   the same parameters, else (default) - creates a new one
271     #  @ingroup l3_algos_segmarv
272     def LengthNearVertex(self, length, vertex=0, UseExisting=0):
273         import types
274         store_geom = self.geom
275         if type(vertex) is types.IntType:
276             if vertex == 0 or vertex == 1:
277                 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geompyDC.ShapeType["VERTEX"],True)[vertex]
278                 self.geom = vertex
279                 pass
280             pass
281         else:
282             self.geom = vertex
283             pass
284         ### 0D algorithm
285         if self.geom is None:
286             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
287         AssureGeomPublished( self.mesh, self.geom )
288         name = GetName(self.geom)
289
290         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
291         if algo is None:
292             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
293             pass
294         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
295         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
296         ###
297         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
298         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
299                               CompareMethod=comFun)
300         self.geom = store_geom
301         hyp.SetLength( length )
302         return hyp
303
304     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
305     #  If the 2D mesher sees that all boundary edges are quadratic,
306     #  it generates quadratic faces, else it generates linear faces using
307     #  medium nodes as if they are vertices.
308     #  The 3D mesher generates quadratic volumes only if all boundary faces
309     #  are quadratic, else it fails.
310     #
311     #  @ingroup l3_hypos_additi
312     def QuadraticMesh(self):
313         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
314         return hyp
315
316 # Public class: Mesh_CompositeSegment
317 # --------------------------
318
319 ## A regular 1D algorithm for discretization of a set of adjacent edges as one.
320 #  It is created by calling Mesh.Segment(COMPOSITE,geom=0)
321 #
322 #  @ingroup l3_algos_basic
323 class StdMeshersDC_CompositeSegment(StdMeshersDC_Segment):
324
325     ## Name of method of class Mesh creating an instance of this class
326     meshMethod = "Segment"
327     ## Name of algorithm type
328     algoType   = COMPOSITE
329     isDefault  = False
330
331     ## Private constructor.
332     def __init__(self, mesh, geom=0):
333         self.Create(mesh, geom, self.algoType)
334
335
336 # Public class: Mesh_Segment_Python
337 # ---------------------------------
338
339 ## Defines a segment 1D algorithm for discretization with python function
340 #  It is created by calling Mesh.Segment(PYTHON,geom=0)
341 #
342 #  @ingroup l3_algos_basic
343 class StdMeshersDC_Segment_Python(Mesh_Algorithm):
344
345     ## Name of method of class Mesh creating an instance of this class
346     meshMethod = "Segment"
347     ## Name of algorithm type
348     algoType   = PYTHON
349
350     ## Private constructor.
351     def __init__(self, mesh, geom=0):
352         import Python1dPlugin
353         self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
354
355     ## Defines "PythonSplit1D" hypothesis
356     #  @param n for the number of segments that cut an edge
357     #  @param func for the python function that calculates the length of all segments
358     #  @param UseExisting if ==true - searches for the existing hypothesis created with
359     #                     the same parameters, else (default) - creates a new one
360     #  @ingroup l3_hypos_1dhyps
361     def PythonSplit1D(self, n, func, UseExisting=0):
362         compFun = lambda hyp, args: False
363         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
364                               UseExisting=UseExisting, CompareMethod=compFun)
365         hyp.SetNumberOfSegments(n)
366         hyp.SetPythonLog10RatioFunction(func)
367         return hyp
368
369 # Public class: Mesh_Triangle_MEFISTO
370 # -----------------------------------
371
372 ## Triangle MEFISTO 2D algorithm
373 #  It is created by calling Mesh.Triangle(MEFISTO,geom=0)
374 #
375 #  @ingroup l3_algos_basic
376 class StdMeshersDC_Triangle_MEFISTO(Mesh_Algorithm):
377
378     ## Name of method of class Mesh creating an instance of this class
379     meshMethod = "Triangle"
380     ## Name of algorithm type
381     algoType   = MEFISTO
382     isDefault  = True
383
384     ## Private constructor.
385     def __init__(self, mesh, geom=0):
386         Mesh_Algorithm.__init__(self)
387         self.Create(mesh, geom, self.algoType)
388
389     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
390     #  @param area for the maximum area of each triangle
391     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
392     #                     same parameters, else (default) - creates a new one
393     #
394     #  @ingroup l3_hypos_2dhyps
395     def MaxElementArea(self, area, UseExisting=0):
396         comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
397         hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
398                               CompareMethod=comparator)
399         hyp.SetMaxElementArea(area)
400         return hyp
401
402     ## Defines "LengthFromEdges" hypothesis to build triangles
403     #  based on the length of the edges taken from the wire
404     #
405     #  @ingroup l3_hypos_2dhyps
406     def LengthFromEdges(self):
407         hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
408         return hyp
409
410 # Public class: Mesh_Quadrangle
411 # -----------------------------
412
413 ## Defines a quadrangle 2D algorithm
414 #  It is created by calling Mesh.Quadrangle(geom=0)
415 #
416 #  @ingroup l3_algos_basic
417 class StdMeshersDC_Quadrangle(Mesh_Algorithm):
418
419     ## Name of method of class Mesh creating an instance of this class
420     meshMethod = "Quadrangle"
421     ## Name of algorithm type
422     algoType   = QUADRANGLE
423     isDefault  = True
424
425     params=0
426
427     ## Private constructor.
428     def __init__(self, mesh, geom=0):
429         Mesh_Algorithm.__init__(self)
430         self.Create(mesh, geom, self.algoType)
431         return
432
433     ## Defines "QuadrangleParameters" hypothesis
434     #  @param quadType defines the algorithm of transition between differently descretized
435     #                  sides of a geometrical face:
436     #  - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
437     #                    area along the finer meshed sides.
438     #  - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
439     #                    finer meshed sides.
440     #  - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
441     #                    the finer meshed sides, iff the total quantity of segments on
442     #                    all four sides of the face is even (divisible by 2).
443     #  - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
444     #                    area is located along the coarser meshed sides.
445     #  - QUAD_REDUCED - only quadrangles are built and the transition between the sides
446     #                    is made gradually, layer by layer. This type has a limitation on
447     #                    the number of segments: one pair of opposite sides must have the
448     #                    same number of segments, the other pair must have an even difference
449     #                    between the numbers of segments on the sides.
450     #  @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
451     #                  will be created while other elements will be quadrangles.
452     #                  Vertex can be either a GEOM_Object or a vertex ID within the
453     #                  shape to mesh
454     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
455     #                  the same parameters, else (default) - creates a new one
456     #  @ingroup l3_hypos_quad
457     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0, UseExisting=0):
458         import GEOM
459         vertexID = triangleVertex
460         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
461             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
462         if not self.params:
463             compFun = lambda hyp,args: \
464                       hyp.GetQuadType() == args[0] and \
465                       ( hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1))
466             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID],
467                                           UseExisting = UseExisting, CompareMethod=compFun)
468             pass
469         if self.params.GetQuadType() != quadType:
470             self.params.SetQuadType(quadType)
471         if vertexID > 0:
472             self.params.SetTriaVertex( vertexID )
473         return self.params
474
475     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
476     #   quadrangles are built in the transition area along the finer meshed sides,
477     #   iff the total quantity of segments on all four sides of the face is even.
478     #  @param reversed if True, transition area is located along the coarser meshed sides.
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_quad
482     def QuadranglePreference(self, reversed=False, UseExisting=0):
483         if reversed:
484             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
485         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
486
487     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
488     #   triangles are built in the transition area along the finer meshed sides.
489     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
490     #                  the same parameters, else (default) - creates a new one
491     #  @ingroup l3_hypos_quad
492     def TrianglePreference(self, UseExisting=0):
493         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
494
495     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
496     #   quadrangles are built and the transition between the sides is made gradually,
497     #   layer by layer. This type has a limitation on the number of segments: one pair
498     #   of opposite sides must have the same number of segments, the other pair must
499     #   have an even difference between the numbers of segments on the sides.
500     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
501     #                  the same parameters, else (default) - creates a new one
502     #  @ingroup l3_hypos_quad
503     def Reduced(self, UseExisting=0):
504         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
505
506     ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
507     #  @param vertex: vertex of a trilateral geometrical face, around which triangles
508     #                 will be created while other elements will be quadrangles.
509     #                 Vertex can be either a GEOM_Object or a vertex ID within the
510     #                 shape to mesh
511     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
512     #                   the same parameters, else (default) - creates a new one
513     #  @ingroup l3_hypos_quad
514     def TriangleVertex(self, vertex, UseExisting=0):
515         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
516
517
518 # Public class: Mesh_Hexahedron
519 # ------------------------------
520
521 ## Defines a hexahedron 3D algorithm
522 #  It is created by calling Mesh.Hexahedron(geom=0)
523 #
524 #  @ingroup l3_algos_basic
525 class StdMeshersDC_Hexahedron(Mesh_Algorithm):
526
527     ## Name of method of class Mesh creating an instance of this class
528     meshMethod = "Hexahedron"
529     ## Name of algorithm type
530     algoType   = Hexa
531     isDefault  = True
532
533     ## Private constructor.
534     def __init__(self, mesh, geom=0):
535         Mesh_Algorithm.__init__(self)
536         self.Create(mesh, geom, Hexa)
537         pass
538
539 # Public class: Mesh_Projection1D
540 # -------------------------------
541
542 ## Defines a projection 1D algorithm
543 #  It is created by calling Mesh.Projection1D(geom=0)
544 #  @ingroup l3_algos_proj
545 #
546 class StdMeshersDC_Projection1D(Mesh_Algorithm):
547
548     ## Name of method of class Mesh creating an instance of this class
549     meshMethod = "Projection1D"
550     ## Name of algorithm type
551     algoType   = "Projection_1D"
552     isDefault  = True
553
554     ## Private constructor.
555     def __init__(self, mesh, geom=0):
556         Mesh_Algorithm.__init__(self)
557         self.Create(mesh, geom, self.algoType)
558
559     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
560     #  a mesh pattern is taken, and, optionally, the association of vertices
561     #  between the source edge and a target edge (to which a hypothesis is assigned)
562     #  @param edge from which nodes distribution is taken
563     #  @param mesh from which nodes distribution is taken (optional)
564     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
565     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
566     #  to associate with \a srcV (optional)
567     #  @param UseExisting if ==true - searches for the existing hypothesis created with
568     #                     the same parameters, else (default) - creates a new one
569     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
570         AssureGeomPublished( self.mesh, edge )
571         AssureGeomPublished( self.mesh, srcV )
572         AssureGeomPublished( self.mesh, tgtV )
573         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
574                               UseExisting=0)
575         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
576                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
577         hyp.SetSourceEdge( edge )
578         if not mesh is None and isinstance(mesh, Mesh):
579             mesh = mesh.GetMesh()
580         hyp.SetSourceMesh( mesh )
581         hyp.SetVertexAssociation( srcV, tgtV )
582         return hyp
583
584
585 # Public class: Mesh_Projection2D
586 # ------------------------------
587
588 ## Defines a projection 2D algorithm
589 #  It is created by calling Mesh.Projection2D(geom=0)
590 #  @ingroup l3_algos_proj
591 #
592 class StdMeshersDC_Projection2D(Mesh_Algorithm):
593
594     ## Name of method of class Mesh creating an instance of this class
595     meshMethod = "Projection2D"
596     ## Name of algorithm type
597     algoType   = "Projection_2D"
598     isDefault  = True
599
600     ## Private constructor.
601     def __init__(self, mesh, geom=0):
602         Mesh_Algorithm.__init__(self)
603         self.Create(mesh, geom, self.algoType)
604
605     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
606     #  a mesh pattern is taken, and, optionally, the association of vertices
607     #  between the source face and the target face (to which a hypothesis is assigned)
608     #  @param face from which the mesh pattern is taken
609     #  @param mesh from which the mesh pattern is taken (optional)
610     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
611     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
612     #               to associate with \a srcV1 (optional)
613     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
614     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
615     #               to associate with \a srcV2 (optional)
616     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
617     #                     the same parameters, else (default) - forces the creation a new one
618     #
619     #  Note: all association vertices must belong to one edge of a face
620     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
621                    srcV2=None, tgtV2=None, UseExisting=0):
622         from smeshDC import Mesh
623         if isinstance(mesh, Mesh):
624             mesh = mesh.GetMesh()
625         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
626             AssureGeomPublished( self.mesh, geom )
627         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
628                               UseExisting=0)
629         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
630                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
631         hyp.SetSourceFace( face )
632         hyp.SetSourceMesh( mesh )
633         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
634         return hyp
635
636 # Public class: Mesh_Projection1D2D
637 # ---------------------------------
638
639 ## Defines a projection 1D-2D algorithm
640 #  It is created by calling Mesh.Projection1D2D(geom=0)
641 #
642 #  @ingroup l3_algos_proj
643
644 class StdMeshersDC_Projection1D2D(StdMeshersDC_Projection2D):
645
646     ## Name of method of class Mesh creating an instance of this class
647     meshMethod = "Projection1D2D"
648     ## Name of algorithm type
649     algoType   = "Projection_1D2D"
650
651     ## Private constructor.
652     def __init__(self, mesh, geom=0):
653         StdMeshersDC_Projection2D.__init__(self, mesh, geom)
654
655 # Public class: Mesh_Projection3D
656 # ------------------------------
657
658 ## Defines a projection 3D algorithm
659 #  It is created by calling Mesh.Projection3D(COMPOSITE)
660 #
661 #  @ingroup l3_algos_proj
662 #
663 class StdMeshersDC_Projection3D(Mesh_Algorithm):
664
665     ## Name of method of class Mesh creating an instance of this class
666     meshMethod = "Projection3D"
667     ## Name of algorithm type
668     algoType   = "Projection_3D"
669
670     ## Private constructor.
671     def __init__(self, mesh, geom=0):
672         Mesh_Algorithm.__init__(self)
673         self.Create(mesh, geom, self.algoType)
674
675     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
676     #  the mesh pattern is taken, and, optionally, the  association of vertices
677     #  between the source and the target solid  (to which a hipothesis is assigned)
678     #  @param solid from where the mesh pattern is taken
679     #  @param mesh from where the mesh pattern is taken (optional)
680     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
681     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
682     #  to associate with \a srcV1 (optional)
683     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
684     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
685     #  to associate with \a srcV2 (optional)
686     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
687     #                     the same parameters, else (default) - creates a new one
688     #
689     #  Note: association vertices must belong to one edge of a solid
690     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
691                       srcV2=0, tgtV2=0, UseExisting=0):
692         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
693             AssureGeomPublished( self.mesh, geom )
694         hyp = self.Hypothesis("ProjectionSource3D",
695                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
696                               UseExisting=0)
697         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
698                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
699         hyp.SetSource3DShape( solid )
700         if isinstance(mesh, Mesh):
701             mesh = mesh.GetMesh()
702         if mesh:
703             hyp.SetSourceMesh( mesh )
704         if srcV1 and srcV2 and tgtV1 and tgtV2:
705             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
706         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
707         return hyp
708
709 # Public class: Mesh_Prism
710 # ------------------------
711
712 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
713 #  depending on geometry
714 #  It is created by calling Mesh.Prism(geom=0)
715 #
716 #  @ingroup l3_algos_3dextr
717 #
718 class StdMeshersDC_Prism3D(Mesh_Algorithm):
719
720     ## Name of method of class Mesh creating an instance of this class
721     meshMethod = "Prism"
722     ## Name of algorithm type
723     algoType   = "Prism_3D"
724
725     ## Private constructor.
726     def __init__(self, mesh, geom=0):
727         Mesh_Algorithm.__init__(self)
728         
729         shape = geom
730         if not shape:
731             shape = mesh.geom
732         from geompy import SubShapeAll, ShapeType
733         nbSolids = len( SubShapeAll( shape, ShapeType["SOLID"] ))
734         nbShells = len( SubShapeAll( shape, ShapeType["SHELL"] ))
735         if nbSolids == 0 or nbSolids == nbShells:
736             self.Create(mesh, geom, "Prism_3D")
737         else:
738             self.algoType = "RadialPrism_3D"
739             self.Create(mesh, geom, "RadialPrism_3D")
740             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
741             self.nbLayers = None
742
743     ## Return 3D hypothesis holding the 1D one
744     def Get3DHypothesis(self):
745         if self.algoType != "RadialPrism_3D":
746             print "Prism_3D algorith doesn't support any hyposesis"
747             return None
748         return self.distribHyp
749
750     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
751     #  hypothesis. Returns the created hypothesis
752     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
753         if self.algoType != "RadialPrism_3D":
754             print "Prism_3D algorith doesn't support any hyposesis"
755             return None
756         if not self.nbLayers is None:
757             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
758             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
759         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
760         self.mesh.smeshpyD.SetCurrentStudy( None )
761         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
762         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
763         self.distribHyp.SetLayerDistribution( hyp )
764         return hyp
765
766     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
767     #  prisms to build between the inner and outer shells
768     #  @param n number of layers
769     #  @param UseExisting if ==true - searches for the existing hypothesis created with
770     #                     the same parameters, else (default) - creates a new one
771     def NumberOfLayers(self, n, UseExisting=0):
772         if self.algoType != "RadialPrism_3D":
773             print "Prism_3D algorith doesn't support any hyposesis"
774             return None
775         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
776         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
777         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
778                                         CompareMethod=compFun)
779         self.nbLayers.SetNumberOfLayers( n )
780         return self.nbLayers
781
782     ## Defines "LocalLength" hypothesis, specifying the segment length
783     #  to build between the inner and the outer shells
784     #  @param l the length of segments
785     #  @param p the precision of rounding
786     def LocalLength(self, l, p=1e-07):
787         if self.algoType != "RadialPrism_3D":
788             print "Prism_3D algorith doesn't support any hyposesis"
789             return None
790         hyp = self.OwnHypothesis("LocalLength", [l,p])
791         hyp.SetLength(l)
792         hyp.SetPrecision(p)
793         return hyp
794
795     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
796     #  prisms to build between the inner and the outer shells.
797     #  @param n the number of layers
798     #  @param s the scale factor (optional)
799     def NumberOfSegments(self, n, s=[]):
800         if self.algoType != "RadialPrism_3D":
801             print "Prism_3D algorith doesn't support any hyposesis"
802             return None
803         if s == []:
804             hyp = self.OwnHypothesis("NumberOfSegments", [n])
805         else:
806             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
807             hyp.SetDistrType( 1 )
808             hyp.SetScaleFactor(s)
809         hyp.SetNumberOfSegments(n)
810         return hyp
811
812     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
813     #  to build between the inner and the outer shells with a length that changes in arithmetic progression
814     #  @param start  the length of the first segment
815     #  @param end    the length of the last  segment
816     def Arithmetic1D(self, start, end ):
817         if self.algoType != "RadialPrism_3D":
818             print "Prism_3D algorith doesn't support any hyposesis"
819             return None
820         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
821         hyp.SetLength(start, 1)
822         hyp.SetLength(end  , 0)
823         return hyp
824
825     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
826     #  to build between the inner and the outer shells as geometric length increasing
827     #  @param start for the length of the first segment
828     #  @param end   for the length of the last  segment
829     def StartEndLength(self, start, end):
830         if self.algoType != "RadialPrism_3D":
831             print "Prism_3D algorith doesn't support any hyposesis"
832             return None
833         hyp = self.OwnHypothesis("StartEndLength", [start, end])
834         hyp.SetLength(start, 1)
835         hyp.SetLength(end  , 0)
836         return hyp
837
838     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
839     #  to build between the inner and outer shells
840     #  @param fineness defines the quality of the mesh within the range [0-1]
841     def AutomaticLength(self, fineness=0):
842         if self.algoType != "RadialPrism_3D":
843             print "Prism_3D algorith doesn't support any hyposesis"
844             return None
845         hyp = self.OwnHypothesis("AutomaticLength")
846         hyp.SetFineness( fineness )
847         return hyp
848
849
850 # Public class: Mesh_RadialQuadrangle1D2D
851 # -------------------------------
852
853 ## Defines a Radial Quadrangle 1D2D algorithm
854 #  It is created by calling Mesh.Quadrangle(RADIAL_QUAD,geom=0)
855 #
856 #  @ingroup l2_algos_radialq
857 class StdMeshersDC_RadialQuadrangle1D2D(Mesh_Algorithm):
858
859     ## Name of method of class Mesh creating an instance of this class
860     meshMethod = "Quadrangle"
861     ## Name of algorithm type
862     algoType   = RADIAL_QUAD
863
864     ## Private constructor.
865     def __init__(self, mesh, geom=0):
866         Mesh_Algorithm.__init__(self)
867         self.Create(mesh, geom, self.algoType)
868
869         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
870         self.nbLayers = None
871
872     ## Return 2D hypothesis holding the 1D one
873     def Get2DHypothesis(self):
874         if not self.distribHyp:
875             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
876         return self.distribHyp
877
878     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
879     #  hypothesis. Returns the created hypothesis
880     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
881         if self.nbLayers:
882             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
883         if self.distribHyp is None:
884             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
885         else:
886             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
887         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
888         self.mesh.smeshpyD.SetCurrentStudy( None )
889         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
890         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
891         self.distribHyp.SetLayerDistribution( hyp )
892         return hyp
893
894     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
895     #  @param n number of layers
896     #  @param UseExisting if ==true - searches for the existing hypothesis created with
897     #                     the same parameters, else (default) - creates a new one
898     def NumberOfLayers(self, n, UseExisting=0):
899         if self.distribHyp:
900             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
901         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
902         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
903                                         CompareMethod=compFun)
904         self.nbLayers.SetNumberOfLayers( n )
905         return self.nbLayers
906
907     ## Defines "LocalLength" hypothesis, specifying the segment length
908     #  @param l the length of segments
909     #  @param p the precision of rounding
910     def LocalLength(self, l, p=1e-07):
911         hyp = self.OwnHypothesis("LocalLength", [l,p])
912         hyp.SetLength(l)
913         hyp.SetPrecision(p)
914         return hyp
915
916     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
917     #  @param n the number of layers
918     #  @param s the scale factor (optional)
919     def NumberOfSegments(self, n, s=[]):
920         if s == []:
921             hyp = self.OwnHypothesis("NumberOfSegments", [n])
922         else:
923             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
924             hyp.SetDistrType( 1 )
925             hyp.SetScaleFactor(s)
926         hyp.SetNumberOfSegments(n)
927         return hyp
928
929     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
930     #  with a length that changes in arithmetic progression
931     #  @param start  the length of the first segment
932     #  @param end    the length of the last  segment
933     def Arithmetic1D(self, start, end ):
934         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
935         hyp.SetLength(start, 1)
936         hyp.SetLength(end  , 0)
937         return hyp
938
939     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
940     #  as geometric length increasing
941     #  @param start for the length of the first segment
942     #  @param end   for the length of the last  segment
943     def StartEndLength(self, start, end):
944         hyp = self.OwnHypothesis("StartEndLength", [start, end])
945         hyp.SetLength(start, 1)
946         hyp.SetLength(end  , 0)
947         return hyp
948
949     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
950     #  @param fineness defines the quality of the mesh within the range [0-1]
951     def AutomaticLength(self, fineness=0):
952         hyp = self.OwnHypothesis("AutomaticLength")
953         hyp.SetFineness( fineness )
954         return hyp
955
956
957 # Public class: Mesh_UseExistingElements
958 # --------------------------------------
959 ## Defines a Radial Quadrangle 1D2D algorithm
960 #  It is created by calling Mesh.UseExisting1DElements(geom=0)
961 #
962 #  @ingroup l3_algos_basic
963 class StdMeshersDC_UseExistingElements_1D(Mesh_Algorithm):
964
965     ## Name of method of class Mesh creating an instance of this class
966     meshMethod = "UseExisting1DElements"
967     ## Name of algorithm type
968     algoType   = "Import_1D"
969     isDefault  = True
970
971     def __init__(self, mesh, geom=0):
972         Mesh_Algorithm.__init__(self)
973         self.Create(mesh, geom, self.algoType)
974         return
975
976     ## Defines "Source edges" hypothesis, specifying groups of edges to import
977     #  @param groups list of groups of edges
978     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
979     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
980     #  @param UseExisting if ==true - searches for the existing hypothesis created with
981     #                     the same parameters, else (default) - creates a new one
982     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
983         for group in groups:
984             AssureGeomPublished( self.mesh, group )
985         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
986                                       hyp.GetCopySourceMesh() == args[1], args[2] )
987         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
988                               UseExisting=UseExisting, CompareMethod=compFun)
989         hyp.SetSourceEdges(groups)
990         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
991         return hyp
992
993 # Public class: Mesh_UseExistingElements
994 # --------------------------------------
995 ## Defines a Radial Quadrangle 1D2D algorithm
996 #  It is created by calling Mesh.UseExisting2DElements(geom=0)
997 #
998 #  @ingroup l3_algos_basic
999 class StdMeshersDC_UseExistingElements_1D2D(Mesh_Algorithm):
1000
1001     ## Name of method of class Mesh creating an instance of this class
1002     meshMethod = "UseExisting2DElements"
1003     ## Name of algorithm type
1004     algoType   = "Import_1D2D"
1005     isDefault  = True
1006
1007     def __init__(self, mesh, geom=0):
1008         Mesh_Algorithm.__init__(self)
1009         self.Create(mesh, geom, self.algoType)
1010         return
1011
1012     ## Defines "Source faces" hypothesis, specifying groups of faces to import
1013     #  @param groups list of groups of faces
1014     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1015     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1016     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1017     #                     the same parameters, else (default) - creates a new one
1018     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1019         for group in groups:
1020             AssureGeomPublished( self.mesh, group )
1021         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1022                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1023         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1024                               UseExisting=UseExisting, CompareMethod=compFun)
1025         hyp.SetSourceFaces(groups)
1026         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1027         return hyp
1028
1029
1030 # Public class: Mesh_Cartesian_3D
1031 # --------------------------------------
1032 ## Defines a Body Fitting 3D algorithm
1033 #  It is created by calling Mesh.BodyFitted(geom=0)
1034 #
1035 #  @ingroup l3_algos_basic
1036 class StdMeshersDC_Cartesian_3D(Mesh_Algorithm):
1037
1038     ## Name of method of class Mesh creating an instance of this class
1039     meshMethod = "BodyFitted"
1040     ## Name of algorithm type
1041     algoType   = "Cartesian_3D"
1042     isDefault  = True
1043
1044     def __init__(self, mesh, geom=0):
1045         self.Create(mesh, geom, self.algoType)
1046         self.hyp = None
1047         return
1048
1049     ## Defines "Body Fitting parameters" hypothesis
1050     #  @param xGridDef is definition of the grid along the X asix.
1051     #  It can be in either of two following forms:
1052     #  - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1053     #  - Functions f(t) defining grid spacing at each point on grid axis. If there are
1054     #    several functions, they must be accompanied by relative coordinates of
1055     #    points dividing the whole shape into ranges where the functions apply; points
1056     #    coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1057     #    function f(t) varies from 0.0 to 1.0 witin a shape range. 
1058     #    Examples:
1059     #    - "10.5" - defines a grid with a constant spacing
1060     #    - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1061     #  @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does
1062     #  @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does
1063     #  @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1064     #         a polyhedron of size less than hexSize/sizeThreshold is not created
1065     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1066     #                     the same parameters, else (default) - creates a new one
1067     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, UseExisting=False):
1068         if not self.hyp:
1069             compFun = lambda hyp, args: False
1070             self.hyp = self.Hypothesis("CartesianParameters3D",
1071                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1072                                        UseExisting=UseExisting, CompareMethod=compFun)
1073         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1074             self.mesh.AddHypothesis( self.hyp, self.geom )
1075
1076         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef]):
1077             if not gridDef: raise ValueError, "Empty grid definition"
1078             if isinstance( gridDef, str ):
1079                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1080             elif isinstance( gridDef[0], str ):
1081                 self.hyp.SetGridSpacing( gridDef, [], axis )
1082             elif isinstance( gridDef[0], int ) or \
1083                  isinstance( gridDef[0], float ):
1084                 self.hyp.SetGrid(gridDef, axis )
1085             else:
1086                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1087         self.hyp.SetSizeThreshold( sizeThreshold )
1088         return self.hyp
1089
1090 # Public class: Mesh_UseExisting_1D
1091 # ---------------------------------
1092 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1093 #  segments usable by 2D algoritms
1094 #  It is created by calling Mesh.UseExistingSegments(geom=0)
1095 #
1096 #  @ingroup l3_algos_basic
1097
1098 class StdMeshersDC_UseExisting_1D(Mesh_Algorithm):
1099
1100     ## Name of method of class Mesh creating an instance of this class
1101     meshMethod = "UseExistingSegments"
1102     ## Name of algorithm type
1103     algoType   = "UseExisting_1D"
1104
1105     def __init__(self, mesh, geom=0):
1106         self.Create(mesh, geom, self.algoType)
1107
1108
1109 # Public class: Mesh_UseExisting
1110 # -------------------------------
1111 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1112 #  faces usable by 3D algoritms
1113 #  It is created by calling Mesh.UseExistingFaces(geom=0)
1114 #
1115 #  @ingroup l3_algos_basic
1116
1117 class StdMeshersDC_UseExisting_2D(Mesh_Algorithm):
1118
1119     ## Name of method of class Mesh creating an instance of this class
1120     meshMethod = "UseExistingFaces"
1121     ## Name of algorithm type
1122     algoType   = "UseExisting_2D"
1123
1124     def __init__(self, mesh, geom=0):
1125         self.Create(mesh, geom, self.algoType)