Salome HOME
Bug 0020072: GHS3DPRLPLUGIN update. Integrating the attached patch.
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  File   : smesh.py
23 #  Author : Francis KLOSS, OCC
24 #  Module : SMESH
25 #
26 """
27  \namespace smesh
28  \brief Module smesh
29 """
30
31 ## @defgroup l1_auxiliary Auxiliary methods and structures
32 ## @defgroup l1_creating  Creating meshes
33 ## @{
34 ##   @defgroup l2_impexp     Importing and exporting meshes
35 ##   @defgroup l2_construct  Constructing meshes
36 ##   @defgroup l2_algorithms Defining Algorithms
37 ##   @{
38 ##     @defgroup l3_algos_basic   Basic meshing algorithms
39 ##     @defgroup l3_algos_proj    Projection Algorithms
40 ##     @defgroup l3_algos_radialp Radial Prism
41 ##     @defgroup l3_algos_segmarv Segments around Vertex
42 ##     @defgroup l3_algos_3dextr  3D extrusion meshing algorithm
43
44 ##   @}
45 ##   @defgroup l2_hypotheses Defining hypotheses
46 ##   @{
47 ##     @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
48 ##     @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
49 ##     @defgroup l3_hypos_maxvol Max Element Volume hypothesis
50 ##     @defgroup l3_hypos_netgen Netgen 2D and 3D hypotheses
51 ##     @defgroup l3_hypos_ghs3dh GHS3D Parameters hypothesis
52 ##     @defgroup l3_hypos_blsurf BLSURF Parameters hypothesis
53 ##     @defgroup l3_hypos_hexotic Hexotic Parameters hypothesis
54 ##     @defgroup l3_hypos_additi Additional Hypotheses
55
56 ##   @}
57 ##   @defgroup l2_submeshes Constructing submeshes
58 ##   @defgroup l2_compounds Building Compounds
59 ##   @defgroup l2_editing   Editing Meshes
60
61 ## @}
62 ## @defgroup l1_meshinfo  Mesh Information
63 ## @defgroup l1_controls  Quality controls and Filtering
64 ## @defgroup l1_grouping  Grouping elements
65 ## @{
66 ##   @defgroup l2_grps_create Creating groups
67 ##   @defgroup l2_grps_edit   Editing groups
68 ##   @defgroup l2_grps_operon Using operations on groups
69 ##   @defgroup l2_grps_delete Deleting Groups
70
71 ## @}
72 ## @defgroup l1_modifying Modifying meshes
73 ## @{
74 ##   @defgroup l2_modif_add      Adding nodes and elements
75 ##   @defgroup l2_modif_del      Removing nodes and elements
76 ##   @defgroup l2_modif_edit     Modifying nodes and elements
77 ##   @defgroup l2_modif_renumber Renumbering nodes and elements
78 ##   @defgroup l2_modif_trsf     Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
79 ##   @defgroup l2_modif_movenode Moving nodes
80 ##   @defgroup l2_modif_throughp Mesh through point
81 ##   @defgroup l2_modif_invdiag  Diagonal inversion of elements
82 ##   @defgroup l2_modif_unitetri Uniting triangles
83 ##   @defgroup l2_modif_changori Changing orientation of elements
84 ##   @defgroup l2_modif_cutquadr Cutting quadrangles
85 ##   @defgroup l2_modif_smooth   Smoothing
86 ##   @defgroup l2_modif_extrurev Extrusion and Revolution
87 ##   @defgroup l2_modif_patterns Pattern mapping
88 ##   @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
89
90 ## @}
91
92 import salome
93 import geompyDC
94
95 import SMESH # This is necessary for back compatibility
96 from   SMESH import *
97
98 import StdMeshers
99
100 import SALOME
101
102 # import NETGENPlugin module if possible
103 noNETGENPlugin = 0
104 try:
105     import NETGENPlugin
106 except ImportError:
107     noNETGENPlugin = 1
108     pass
109
110 ## @addtogroup l1_auxiliary
111 ## @{
112
113 # Types of algorithms
114 REGULAR    = 1
115 PYTHON     = 2
116 COMPOSITE  = 3
117 SOLE       = 0
118 SIMPLE     = 1
119
120 MEFISTO       = 3
121 NETGEN        = 4
122 GHS3D         = 5
123 FULL_NETGEN   = 6
124 NETGEN_2D     = 7
125 NETGEN_1D2D   = NETGEN
126 NETGEN_1D2D3D = FULL_NETGEN
127 NETGEN_FULL   = FULL_NETGEN
128 Hexa    = 8
129 Hexotic = 9
130 BLSURF  = 10
131 GHS3DPRL = 11
132
133 # MirrorType enumeration
134 POINT = SMESH_MeshEditor.POINT
135 AXIS =  SMESH_MeshEditor.AXIS
136 PLANE = SMESH_MeshEditor.PLANE
137
138 # Smooth_Method enumeration
139 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
140 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
141
142 # Fineness enumeration (for NETGEN)
143 VeryCoarse = 0
144 Coarse     = 1
145 Moderate   = 2
146 Fine       = 3
147 VeryFine   = 4
148 Custom     = 5
149
150 # Optimization level of GHS3D
151 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
152
153 # Topology treatment way of BLSURF
154 FromCAD, PreProcess, PreProcessPlus = 0,1,2
155
156 # Element size flag of BLSURF
157 DefaultSize, DefaultGeom, Custom = 0,0,1
158
159 PrecisionConfusion = 1e-07
160
161 def IsEqual(val1, val2, tol=PrecisionConfusion):
162     if abs(val1 - val2) < tol:
163         return True
164     return False
165
166 NO_NAME = "NoName"
167
168 ## Gets object name
169 def GetName(obj):
170     ior  = salome.orb.object_to_string(obj)
171     sobj = salome.myStudy.FindObjectIOR(ior)
172     if sobj is None:
173         return NO_NAME
174     else:
175         attr = sobj.FindAttribute("AttributeName")[1]
176         return attr.Value()
177
178 ## Sets a name to the object
179 def SetName(obj, name):
180     if isinstance( obj, Mesh ):
181         obj = obj.GetMesh()
182     elif isinstance( obj, Mesh_Algorithm ):
183         obj = obj.GetAlgorithm()
184     ior  = salome.orb.object_to_string(obj)
185     sobj = salome.myStudy.FindObjectIOR(ior)
186     if not sobj is None:
187         attr = sobj.FindAttribute("AttributeName")[1]
188         attr.SetValue(name)
189
190 ## Prints error message if a hypothesis was not assigned.
191 def TreatHypoStatus(status, hypName, geomName, isAlgo):
192     if isAlgo:
193         hypType = "algorithm"
194     else:
195         hypType = "hypothesis"
196         pass
197     if status == HYP_UNKNOWN_FATAL :
198         reason = "for unknown reason"
199     elif status == HYP_INCOMPATIBLE :
200         reason = "this hypothesis mismatches the algorithm"
201     elif status == HYP_NOTCONFORM :
202         reason = "a non-conform mesh would be built"
203     elif status == HYP_ALREADY_EXIST :
204         reason = hypType + " of the same dimension is already assigned to this shape"
205     elif status == HYP_BAD_DIM :
206         reason = hypType + " mismatches the shape"
207     elif status == HYP_CONCURENT :
208         reason = "there are concurrent hypotheses on sub-shapes"
209     elif status == HYP_BAD_SUBSHAPE :
210         reason = "the shape is neither the main one, nor its subshape, nor a valid group"
211     elif status == HYP_BAD_GEOMETRY:
212         reason = "geometry mismatches the expectation of the algorithm"
213     elif status == HYP_HIDDEN_ALGO:
214         reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
215     elif status == HYP_HIDING_ALGO:
216         reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
217     elif status == HYP_NEED_SHAPE:
218         reason = "Algorithm can't work without shape"
219     else:
220         return
221     hypName = '"' + hypName + '"'
222     geomName= '"' + geomName+ '"'
223     if status < HYP_UNKNOWN_FATAL:
224         print hypName, "was assigned to",    geomName,"but", reason
225     else:
226         print hypName, "was not assigned to",geomName,":", reason
227         pass
228
229 ## Converts an angle from degrees to radians
230 def DegreesToRadians(AngleInDegrees):
231     from math import pi
232     return AngleInDegrees * pi / 180.0
233
234 # end of l1_auxiliary
235 ## @}
236
237 # All methods of this class are accessible directly from the smesh.py package.
238 class smeshDC(SMESH._objref_SMESH_Gen):
239
240     ## Sets the current study and Geometry component
241     #  @ingroup l1_auxiliary
242     def init_smesh(self,theStudy,geompyD):
243         self.SetCurrentStudy(theStudy,geompyD)
244
245     ## Creates an empty Mesh. This mesh can have an underlying geometry.
246     #  @param obj the Geometrical object on which the mesh is built. If not defined,
247     #             the mesh will have no underlying geometry.
248     #  @param name the name for the new mesh.
249     #  @return an instance of Mesh class.
250     #  @ingroup l2_construct
251     def Mesh(self, obj=0, name=0):
252       return Mesh(self,self.geompyD,obj,name)
253
254     ## Returns a long value from enumeration
255     #  Should be used for SMESH.FunctorType enumeration
256     #  @ingroup l1_controls
257     def EnumToLong(self,theItem):
258         return theItem._v
259
260     ## Gets PointStruct from vertex
261     #  @param theVertex a GEOM object(vertex)
262     #  @return SMESH.PointStruct
263     #  @ingroup l1_auxiliary
264     def GetPointStruct(self,theVertex):
265         [x, y, z] = self.geompyD.PointCoordinates(theVertex)
266         return PointStruct(x,y,z)
267
268     ## Gets DirStruct from vector
269     #  @param theVector a GEOM object(vector)
270     #  @return SMESH.DirStruct
271     #  @ingroup l1_auxiliary
272     def GetDirStruct(self,theVector):
273         vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
274         if(len(vertices) != 2):
275             print "Error: vector object is incorrect."
276             return None
277         p1 = self.geompyD.PointCoordinates(vertices[0])
278         p2 = self.geompyD.PointCoordinates(vertices[1])
279         pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
280         dirst = DirStruct(pnt)
281         return dirst
282
283     ## Makes DirStruct from a triplet
284     #  @param x,y,z vector components
285     #  @return SMESH.DirStruct
286     #  @ingroup l1_auxiliary
287     def MakeDirStruct(self,x,y,z):
288         pnt = PointStruct(x,y,z)
289         return DirStruct(pnt)
290
291     ## Get AxisStruct from object
292     #  @param theObj a GEOM object (line or plane)
293     #  @return SMESH.AxisStruct
294     #  @ingroup l1_auxiliary
295     def GetAxisStruct(self,theObj):
296         edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
297         if len(edges) > 1:
298             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
299             vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
300             vertex1 = self.geompyD.PointCoordinates(vertex1)
301             vertex2 = self.geompyD.PointCoordinates(vertex2)
302             vertex3 = self.geompyD.PointCoordinates(vertex3)
303             vertex4 = self.geompyD.PointCoordinates(vertex4)
304             v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
305             v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
306             normal = [ v1[1]*v2[2]-v2[1]*v1[2], v1[2]*v2[0]-v2[2]*v1[0], v1[0]*v2[1]-v2[0]*v1[1] ]
307             axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
308             return axis
309         elif len(edges) == 1:
310             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
311             p1 = self.geompyD.PointCoordinates( vertex1 )
312             p2 = self.geompyD.PointCoordinates( vertex2 )
313             axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
314             return axis
315         return None
316
317     # From SMESH_Gen interface:
318     # ------------------------
319
320     ## Sets the current mode
321     #  @ingroup l1_auxiliary
322     def SetEmbeddedMode( self,theMode ):
323         #self.SetEmbeddedMode(theMode)
324         SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
325
326     ## Gets the current mode
327     #  @ingroup l1_auxiliary
328     def IsEmbeddedMode(self):
329         #return self.IsEmbeddedMode()
330         return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
331
332     ## Sets the current study
333     #  @ingroup l1_auxiliary
334     def SetCurrentStudy( self, theStudy, geompyD = None ):
335         #self.SetCurrentStudy(theStudy)
336         if not geompyD:
337             import geompy
338             geompyD = geompy.geom
339             pass
340         self.geompyD=geompyD
341         self.SetGeomEngine(geompyD)
342         SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
343
344     ## Gets the current study
345     #  @ingroup l1_auxiliary
346     def GetCurrentStudy(self):
347         #return self.GetCurrentStudy()
348         return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
349
350     ## Creates a Mesh object importing data from the given UNV file
351     #  @return an instance of Mesh class
352     #  @ingroup l2_impexp
353     def CreateMeshesFromUNV( self,theFileName ):
354         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
355         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
356         return aMesh
357
358     ## Creates a Mesh object(s) importing data from the given MED file
359     #  @return a list of Mesh class instances
360     #  @ingroup l2_impexp
361     def CreateMeshesFromMED( self,theFileName ):
362         aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
363         aMeshes = []
364         for iMesh in range(len(aSmeshMeshes)) :
365             aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
366             aMeshes.append(aMesh)
367         return aMeshes, aStatus
368
369     ## Creates a Mesh object importing data from the given STL file
370     #  @return an instance of Mesh class
371     #  @ingroup l2_impexp
372     def CreateMeshesFromSTL( self, theFileName ):
373         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
374         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
375         return aMesh
376
377     ## Concatenate the given meshes into one mesh.
378     #  @return an instance of Mesh class
379     #  @param meshes the meshes to combine into one mesh
380     #  @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
381     #  @param mergeNodesAndElements if true, equal nodes and elements aremerged
382     #  @param mergeTolerance tolerance for merging nodes
383     #  @param allGroups forces creation of groups of all elements
384     def Concatenate( self, meshes, uniteIdenticalGroups,
385                      mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
386         if allGroups:
387             aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
388                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
389         else:
390             aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
391                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
392         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
393         return aMesh
394
395     ## From SMESH_Gen interface
396     #  @return the list of integer values
397     #  @ingroup l1_auxiliary
398     def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
399         return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
400
401     ## From SMESH_Gen interface. Creates a pattern
402     #  @return an instance of SMESH_Pattern
403     #
404     #  <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
405     #  @ingroup l2_modif_patterns
406     def GetPattern(self):
407         return SMESH._objref_SMESH_Gen.GetPattern(self)
408
409
410     # Filtering. Auxiliary functions:
411     # ------------------------------
412
413     ## Creates an empty criterion
414     #  @return SMESH.Filter.Criterion
415     #  @ingroup l1_controls
416     def GetEmptyCriterion(self):
417         Type = self.EnumToLong(FT_Undefined)
418         Compare = self.EnumToLong(FT_Undefined)
419         Threshold = 0
420         ThresholdStr = ""
421         ThresholdID = ""
422         UnaryOp = self.EnumToLong(FT_Undefined)
423         BinaryOp = self.EnumToLong(FT_Undefined)
424         Tolerance = 1e-07
425         TypeOfElement = ALL
426         Precision = -1 ##@1e-07
427         return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
428                                 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
429
430     ## Creates a criterion by the given parameters
431     #  @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
432     #  @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
433     #  @param Compare  belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
434     #  @param Treshold the threshold value (range of ids as string, shape, numeric)
435     #  @param UnaryOp  FT_LogicalNOT or FT_Undefined
436     #  @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
437     #                  FT_Undefined (must be for the last criterion of all criteria)
438     #  @return SMESH.Filter.Criterion
439     #  @ingroup l1_controls
440     def GetCriterion(self,elementType,
441                      CritType,
442                      Compare = FT_EqualTo,
443                      Treshold="",
444                      UnaryOp=FT_Undefined,
445                      BinaryOp=FT_Undefined):
446         aCriterion = self.GetEmptyCriterion()
447         aCriterion.TypeOfElement = elementType
448         aCriterion.Type = self.EnumToLong(CritType)
449
450         aTreshold = Treshold
451
452         if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
453             aCriterion.Compare = self.EnumToLong(Compare)
454         elif Compare == "=" or Compare == "==":
455             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
456         elif Compare == "<":
457             aCriterion.Compare = self.EnumToLong(FT_LessThan)
458         elif Compare == ">":
459             aCriterion.Compare = self.EnumToLong(FT_MoreThan)
460         else:
461             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
462             aTreshold = Compare
463
464         if CritType in [FT_BelongToGeom,     FT_BelongToPlane, FT_BelongToGenSurface,
465                         FT_BelongToCylinder, FT_LyingOnGeom]:
466             # Checks the treshold
467             if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
468                 aCriterion.ThresholdStr = GetName(aTreshold)
469                 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
470             else:
471                 print "Error: The treshold should be a shape."
472                 return None
473         elif CritType == FT_RangeOfIds:
474             # Checks the treshold
475             if isinstance(aTreshold, str):
476                 aCriterion.ThresholdStr = aTreshold
477             else:
478                 print "Error: The treshold should be a string."
479                 return None
480         elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
481             # At this point the treshold is unnecessary
482             if aTreshold ==  FT_LogicalNOT:
483                 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
484             elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
485                 aCriterion.BinaryOp = aTreshold
486         else:
487             # Check treshold
488             try:
489                 aTreshold = float(aTreshold)
490                 aCriterion.Threshold = aTreshold
491             except:
492                 print "Error: The treshold should be a number."
493                 return None
494
495         if Treshold ==  FT_LogicalNOT or UnaryOp ==  FT_LogicalNOT:
496             aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
497
498         if Treshold in [FT_LogicalAND, FT_LogicalOR]:
499             aCriterion.BinaryOp = self.EnumToLong(Treshold)
500
501         if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
502             aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
503
504         if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
505             aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
506
507         return aCriterion
508
509     ## Creates a filter with the given parameters
510     #  @param elementType the type of elements in the group
511     #  @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
512     #  @param Compare  belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
513     #  @param Treshold the threshold value (range of id ids as string, shape, numeric)
514     #  @param UnaryOp  FT_LogicalNOT or FT_Undefined
515     #  @return SMESH_Filter
516     #  @ingroup l1_controls
517     def GetFilter(self,elementType,
518                   CritType=FT_Undefined,
519                   Compare=FT_EqualTo,
520                   Treshold="",
521                   UnaryOp=FT_Undefined):
522         aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
523         aFilterMgr = self.CreateFilterManager()
524         aFilter = aFilterMgr.CreateFilter()
525         aCriteria = []
526         aCriteria.append(aCriterion)
527         aFilter.SetCriteria(aCriteria)
528         return aFilter
529
530     ## Creates a numerical functor by its type
531     #  @param theCriterion FT_...; functor type
532     #  @return SMESH_NumericalFunctor
533     #  @ingroup l1_controls
534     def GetFunctor(self,theCriterion):
535         aFilterMgr = self.CreateFilterManager()
536         if theCriterion == FT_AspectRatio:
537             return aFilterMgr.CreateAspectRatio()
538         elif theCriterion == FT_AspectRatio3D:
539             return aFilterMgr.CreateAspectRatio3D()
540         elif theCriterion == FT_Warping:
541             return aFilterMgr.CreateWarping()
542         elif theCriterion == FT_MinimumAngle:
543             return aFilterMgr.CreateMinimumAngle()
544         elif theCriterion == FT_Taper:
545             return aFilterMgr.CreateTaper()
546         elif theCriterion == FT_Skew:
547             return aFilterMgr.CreateSkew()
548         elif theCriterion == FT_Area:
549             return aFilterMgr.CreateArea()
550         elif theCriterion == FT_Volume3D:
551             return aFilterMgr.CreateVolume3D()
552         elif theCriterion == FT_MultiConnection:
553             return aFilterMgr.CreateMultiConnection()
554         elif theCriterion == FT_MultiConnection2D:
555             return aFilterMgr.CreateMultiConnection2D()
556         elif theCriterion == FT_Length:
557             return aFilterMgr.CreateLength()
558         elif theCriterion == FT_Length2D:
559             return aFilterMgr.CreateLength2D()
560         else:
561             print "Error: given parameter is not numerucal functor type."
562
563
564 import omniORB
565 #Registering the new proxy for SMESH_Gen
566 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
567
568
569 # Public class: Mesh
570 # ==================
571
572 ## This class allows defining and managing a mesh.
573 #  It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
574 #  It also has methods to define groups of mesh elements, to modify a mesh (by addition of
575 #  new nodes and elements and by changing the existing entities), to get information
576 #  about a mesh and to export a mesh into different formats.
577 class Mesh:
578
579     geom = 0
580     mesh = 0
581     editor = 0
582
583     ## Constructor
584     #
585     #  Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
586     #  sets the GUI name of this mesh to \a name.
587     #  @param smeshpyD an instance of smeshDC class
588     #  @param geompyD an instance of geompyDC class
589     #  @param obj Shape to be meshed or SMESH_Mesh object
590     #  @param name Study name of the mesh
591     #  @ingroup l2_construct
592     def __init__(self, smeshpyD, geompyD, obj=0, name=0):
593         self.smeshpyD=smeshpyD
594         self.geompyD=geompyD
595         if obj is None:
596             obj = 0
597         if obj != 0:
598             if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
599                 self.geom = obj
600                 self.mesh = self.smeshpyD.CreateMesh(self.geom)
601             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
602                 self.SetMesh(obj)
603         else:
604             self.mesh = self.smeshpyD.CreateEmptyMesh()
605         if name != 0:
606             SetName(self.mesh, name)
607         elif obj != 0:
608             SetName(self.mesh, GetName(obj))
609
610         if not self.geom:
611             self.geom = self.mesh.GetShapeToMesh()
612
613         self.editor = self.mesh.GetMeshEditor()
614
615     ## Initializes the Mesh object from an instance of SMESH_Mesh interface
616     #  @param theMesh a SMESH_Mesh object
617     #  @ingroup l2_construct
618     def SetMesh(self, theMesh):
619         self.mesh = theMesh
620         self.geom = self.mesh.GetShapeToMesh()
621
622     ## Returns the mesh, that is an instance of SMESH_Mesh interface
623     #  @return a SMESH_Mesh object
624     #  @ingroup l2_construct
625     def GetMesh(self):
626         return self.mesh
627
628     ## Gets the name of the mesh
629     #  @return the name of the mesh as a string
630     #  @ingroup l2_construct
631     def GetName(self):
632         name = GetName(self.GetMesh())
633         return name
634
635     ## Sets a name to the mesh
636     #  @param name a new name of the mesh
637     #  @ingroup l2_construct
638     def SetName(self, name):
639         SetName(self.GetMesh(), name)
640
641     ## Gets the subMesh object associated to a \a theSubObject geometrical object.
642     #  The subMesh object gives access to the IDs of nodes and elements.
643     #  @param theSubObject a geometrical object (shape)
644     #  @param theName a name for the submesh
645     #  @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
646     #  @ingroup l2_submeshes
647     def GetSubMesh(self, theSubObject, theName):
648         submesh = self.mesh.GetSubMesh(theSubObject, theName)
649         return submesh
650
651     ## Returns the shape associated to the mesh
652     #  @return a GEOM_Object
653     #  @ingroup l2_construct
654     def GetShape(self):
655         return self.geom
656
657     ## Associates the given shape to the mesh (entails the recreation of the mesh)
658     #  @param geom the shape to be meshed (GEOM_Object)
659     #  @ingroup l2_construct
660     def SetShape(self, geom):
661         self.mesh = self.smeshpyD.CreateMesh(geom)
662
663     ## Returns true if the hypotheses are defined well
664     #  @param theSubObject a subshape of a mesh shape
665     #  @return True or False
666     #  @ingroup l2_construct
667     def IsReadyToCompute(self, theSubObject):
668         return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
669
670     ## Returns errors of hypotheses definition.
671     #  The list of errors is empty if everything is OK.
672     #  @param theSubObject a subshape of a mesh shape
673     #  @return a list of errors
674     #  @ingroup l2_construct
675     def GetAlgoState(self, theSubObject):
676         return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
677
678     ## Returns a geometrical object on which the given element was built.
679     #  The returned geometrical object, if not nil, is either found in the
680     #  study or published by this method with the given name
681     #  @param theElementID the id of the mesh element
682     #  @param theGeomName the user-defined name of the geometrical object
683     #  @return GEOM::GEOM_Object instance
684     #  @ingroup l2_construct
685     def GetGeometryByMeshElement(self, theElementID, theGeomName):
686         return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
687
688     ## Returns the mesh dimension depending on the dimension of the underlying shape
689     #  @return mesh dimension as an integer value [0,3]
690     #  @ingroup l1_auxiliary
691     def MeshDimension(self):
692         shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
693         if len( shells ) > 0 :
694             return 3
695         elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
696             return 2
697         elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
698             return 1
699         else:
700             return 0;
701         pass
702
703     ## Creates a segment discretization 1D algorithm.
704     #  If the optional \a algo parameter is not set, this algorithm is REGULAR.
705     #  \n If the optional \a geom parameter is not set, this algorithm is global.
706     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
707     #  @param algo the type of the required algorithm. Possible values are:
708     #     - smesh.REGULAR,
709     #     - smesh.PYTHON for discretization via a python function,
710     #     - smesh.COMPOSITE for meshing a set of edges on one face side as a whole.
711     #  @param geom If defined is the subshape to be meshed
712     #  @return an instance of Mesh_Segment or Mesh_Segment_Python, or Mesh_CompositeSegment class
713     #  @ingroup l3_algos_basic
714     def Segment(self, algo=REGULAR, geom=0):
715         ## if Segment(geom) is called by mistake
716         if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
717             algo, geom = geom, algo
718             if not algo: algo = REGULAR
719             pass
720         if algo == REGULAR:
721             return Mesh_Segment(self,  geom)
722         elif algo == PYTHON:
723             return Mesh_Segment_Python(self, geom)
724         elif algo == COMPOSITE:
725             return Mesh_CompositeSegment(self, geom)
726         else:
727             return Mesh_Segment(self, geom)
728
729     ## Enables creation of nodes and segments usable by 2D algoritms.
730     #  The added nodes and segments must be bound to edges and vertices by
731     #  SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
732     #  If the optional \a geom parameter is not set, this algorithm is global.
733     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
734     #  @param geom the subshape to be manually meshed
735     #  @return StdMeshers_UseExisting_1D algorithm that generates nothing
736     #  @ingroup l3_algos_basic
737     def UseExistingSegments(self, geom=0):
738         algo = Mesh_UseExisting(1,self,geom)
739         return algo.GetAlgorithm()
740
741     ## Enables creation of nodes and faces usable by 3D algoritms.
742     #  The added nodes and faces must be bound to geom faces by SetNodeOnFace()
743     #  and SetMeshElementOnShape()
744     #  If the optional \a geom parameter is not set, this algorithm is global.
745     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
746     #  @param geom the subshape to be manually meshed
747     #  @return StdMeshers_UseExisting_2D algorithm that generates nothing
748     #  @ingroup l3_algos_basic
749     def UseExistingFaces(self, geom=0):
750         algo = Mesh_UseExisting(2,self,geom)
751         return algo.GetAlgorithm()
752
753     ## Creates a triangle 2D algorithm for faces.
754     #  If the optional \a geom parameter is not set, this algorithm is global.
755     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
756     #  @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D || smesh.BLSURF
757     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
758     #  @return an instance of Mesh_Triangle algorithm
759     #  @ingroup l3_algos_basic
760     def Triangle(self, algo=MEFISTO, geom=0):
761         ## if Triangle(geom) is called by mistake
762         if (isinstance(algo, geompyDC.GEOM._objref_GEOM_Object)):
763             geom = algo
764             algo = MEFISTO
765
766         return Mesh_Triangle(self, algo, geom)
767
768     ## Creates a quadrangle 2D algorithm for faces.
769     #  If the optional \a geom parameter is not set, this algorithm is global.
770     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
771     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
772     #  @return an instance of Mesh_Quadrangle algorithm
773     #  @ingroup l3_algos_basic
774     def Quadrangle(self, geom=0):
775         return Mesh_Quadrangle(self,  geom)
776
777     ## Creates a tetrahedron 3D algorithm for solids.
778     #  The parameter \a algo permits to choose the algorithm: NETGEN or GHS3D
779     #  If the optional \a geom parameter is not set, this algorithm is global.
780     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
781     #  @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.GHS3DPRL, smesh.FULL_NETGEN
782     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
783     #  @return an instance of Mesh_Tetrahedron algorithm
784     #  @ingroup l3_algos_basic
785     def Tetrahedron(self, algo=NETGEN, geom=0):
786         ## if Tetrahedron(geom) is called by mistake
787         if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
788             algo, geom = geom, algo
789             if not algo: algo = NETGEN
790             pass
791         return Mesh_Tetrahedron(self,  algo, geom)
792
793     ## Creates a hexahedron 3D algorithm for solids.
794     #  If the optional \a geom parameter is not set, this algorithm is global.
795     #  \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
796     #  @param algo possible values are: smesh.Hexa, smesh.Hexotic
797     #  @param geom If defined, the subshape to be meshed (GEOM_Object)
798     #  @return an instance of Mesh_Hexahedron algorithm
799     #  @ingroup l3_algos_basic
800     def Hexahedron(self, algo=Hexa, geom=0):
801         ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
802         if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
803             if   geom in [Hexa, Hexotic]: algo, geom = geom, algo
804             elif geom == 0:               algo, geom = Hexa, algo
805         return Mesh_Hexahedron(self, algo, geom)
806
807     ## Deprecated, used only for compatibility!
808     #  @return an instance of Mesh_Netgen algorithm
809     #  @ingroup l3_algos_basic
810     def Netgen(self, is3D, geom=0):
811         return Mesh_Netgen(self,  is3D, geom)
812
813     ## Creates a projection 1D algorithm for edges.
814     #  If the optional \a geom parameter is not set, this algorithm is global.
815     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
816     #  @param geom If defined, the subshape to be meshed
817     #  @return an instance of Mesh_Projection1D algorithm
818     #  @ingroup l3_algos_proj
819     def Projection1D(self, geom=0):
820         return Mesh_Projection1D(self,  geom)
821
822     ## Creates a projection 2D algorithm for faces.
823     #  If the optional \a geom parameter is not set, this algorithm is global.
824     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
825     #  @param geom If defined, the subshape to be meshed
826     #  @return an instance of Mesh_Projection2D algorithm
827     #  @ingroup l3_algos_proj
828     def Projection2D(self, geom=0):
829         return Mesh_Projection2D(self,  geom)
830
831     ## Creates a projection 3D algorithm for solids.
832     #  If the optional \a geom parameter is not set, this algorithm is global.
833     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
834     #  @param geom If defined, the subshape to be meshed
835     #  @return an instance of Mesh_Projection3D algorithm
836     #  @ingroup l3_algos_proj
837     def Projection3D(self, geom=0):
838         return Mesh_Projection3D(self,  geom)
839
840     ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
841     #  If the optional \a geom parameter is not set, this algorithm is global.
842     #  Otherwise, this algorithm defines a submesh based on \a geom subshape.
843     #  @param geom If defined, the subshape to be meshed
844     #  @return an instance of Mesh_Prism3D or Mesh_RadialPrism3D algorithm
845     #  @ingroup l3_algos_radialp l3_algos_3dextr
846     def Prism(self, geom=0):
847         shape = geom
848         if shape==0:
849             shape = self.geom
850         nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
851         nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
852         if nbSolids == 0 or nbSolids == nbShells:
853             return Mesh_Prism3D(self,  geom)
854         return Mesh_RadialPrism3D(self,  geom)
855
856     ## Computes the mesh and returns the status of the computation
857     #  @return True or False
858     #  @ingroup l2_construct
859     def Compute(self, geom=0):
860         if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
861             if self.geom == 0:
862                 geom = self.mesh.GetShapeToMesh()
863             else:
864                 geom = self.geom
865         ok = False
866         try:
867             ok = self.smeshpyD.Compute(self.mesh, geom)
868         except SALOME.SALOME_Exception, ex:
869             print "Mesh computation failed, exception caught:"
870             print "    ", ex.details.text
871         except:
872             import traceback
873             print "Mesh computation failed, exception caught:"
874             traceback.print_exc()
875         if True:#not ok:
876             errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
877             allReasons = ""
878             for err in errors:
879                 if err.isGlobalAlgo:
880                     glob = "global"
881                 else:
882                     glob = "local"
883                     pass
884                 dim = err.algoDim
885                 name = err.algoName
886                 if len(name) == 0:
887                     reason = '%s %sD algorithm is missing' % (glob, dim)
888                 elif err.state == HYP_MISSING:
889                     reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
890                               % (glob, dim, name, dim))
891                 elif err.state == HYP_NOTCONFORM:
892                     reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
893                 elif err.state == HYP_BAD_PARAMETER:
894                     reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
895                               % ( glob, dim, name ))
896                 elif err.state == HYP_BAD_GEOMETRY:
897                     reason = ('%s %sD algorithm "%s" is assigned to mismatching'
898                               'geometry' % ( glob, dim, name ))
899                 else:
900                     reason = "For unknown reason."+\
901                              " Revise Mesh.Compute() implementation in smeshDC.py!"
902                     pass
903                 if allReasons != "":
904                     allReasons += "\n"
905                     pass
906                 allReasons += reason
907                 pass
908             if allReasons != "":
909                 print '"' + GetName(self.mesh) + '"',"has not been computed:"
910                 print allReasons
911                 ok = False
912             elif not ok:
913                 print '"' + GetName(self.mesh) + '"',"has not been computed."
914                 pass
915             pass
916         if salome.sg.hasDesktop():
917             smeshgui = salome.ImportComponentGUI("SMESH")
918             smeshgui.Init(salome.myStudyId)
919             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
920             salome.sg.updateObjBrowser(1)
921             pass
922         return ok
923
924     ## Removes all nodes and elements
925     #  @ingroup l2_construct
926     def Clear(self):
927         self.mesh.Clear()
928         if salome.sg.hasDesktop():
929             smeshgui = salome.ImportComponentGUI("SMESH")
930             smeshgui.Init(salome.myStudyId)
931             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
932             salome.sg.updateObjBrowser(1)
933
934     ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
935     #  @param fineness [0,-1] defines mesh fineness
936     #  @return True or False
937     #  @ingroup l3_algos_basic
938     def AutomaticTetrahedralization(self, fineness=0):
939         dim = self.MeshDimension()
940         # assign hypotheses
941         self.RemoveGlobalHypotheses()
942         self.Segment().AutomaticLength(fineness)
943         if dim > 1 :
944             self.Triangle().LengthFromEdges()
945             pass
946         if dim > 2 :
947             self.Tetrahedron(NETGEN)
948             pass
949         return self.Compute()
950
951     ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
952     #  @param fineness [0,-1] defines mesh fineness
953     #  @return True or False
954     #  @ingroup l3_algos_basic
955     def AutomaticHexahedralization(self, fineness=0):
956         dim = self.MeshDimension()
957         # assign the hypotheses
958         self.RemoveGlobalHypotheses()
959         self.Segment().AutomaticLength(fineness)
960         if dim > 1 :
961             self.Quadrangle()
962             pass
963         if dim > 2 :
964             self.Hexahedron()
965             pass
966         return self.Compute()
967
968     ## Assigns a hypothesis
969     #  @param hyp a hypothesis to assign
970     #  @param geom a subhape of mesh geometry
971     #  @return SMESH.Hypothesis_Status
972     #  @ingroup l2_hypotheses
973     def AddHypothesis(self, hyp, geom=0):
974         if isinstance( hyp, Mesh_Algorithm ):
975             hyp = hyp.GetAlgorithm()
976             pass
977         if not geom:
978             geom = self.geom
979             if not geom:
980                 geom = self.mesh.GetShapeToMesh()
981             pass
982         status = self.mesh.AddHypothesis(geom, hyp)
983         isAlgo = hyp._narrow( SMESH_Algo )
984         TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
985         return status
986
987     ## Unassigns a hypothesis
988     #  @param hyp a hypothesis to unassign
989     #  @param geom a subshape of mesh geometry
990     #  @return SMESH.Hypothesis_Status
991     #  @ingroup l2_hypotheses
992     def RemoveHypothesis(self, hyp, geom=0):
993         if isinstance( hyp, Mesh_Algorithm ):
994             hyp = hyp.GetAlgorithm()
995             pass
996         if not geom:
997             geom = self.geom
998             pass
999         status = self.mesh.RemoveHypothesis(geom, hyp)
1000         return status
1001
1002     ## Gets the list of hypotheses added on a geometry
1003     #  @param geom a subshape of mesh geometry
1004     #  @return the sequence of SMESH_Hypothesis
1005     #  @ingroup l2_hypotheses
1006     def GetHypothesisList(self, geom):
1007         return self.mesh.GetHypothesisList( geom )
1008
1009     ## Removes all global hypotheses
1010     #  @ingroup l2_hypotheses
1011     def RemoveGlobalHypotheses(self):
1012         current_hyps = self.mesh.GetHypothesisList( self.geom )
1013         for hyp in current_hyps:
1014             self.mesh.RemoveHypothesis( self.geom, hyp )
1015             pass
1016         pass
1017
1018     ## Creates a mesh group based on the geometric object \a grp
1019     #  and gives a \a name, \n if this parameter is not defined
1020     #  the name is the same as the geometric group name \n
1021     #  Note: Works like GroupOnGeom().
1022     #  @param grp  a geometric group, a vertex, an edge, a face or a solid
1023     #  @param name the name of the mesh group
1024     #  @return SMESH_GroupOnGeom
1025     #  @ingroup l2_grps_create
1026     def Group(self, grp, name=""):
1027         return self.GroupOnGeom(grp, name)
1028
1029     ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
1030     #  Exports the mesh in a file in MED format and chooses the \a version of MED format
1031     #  @param f the file name
1032     #  @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1033     #  @ingroup l2_impexp
1034     def ExportToMED(self, f, version, opt=0):
1035         self.mesh.ExportToMED(f, opt, version)
1036
1037     ## Exports the mesh in a file in MED format
1038     #  @param f is the file name
1039     #  @param auto_groups boolean parameter for creating/not creating
1040     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1041     #  the typical use is auto_groups=false.
1042     #  @param version MED format version(MED_V2_1 or MED_V2_2)
1043     #  @ingroup l2_impexp
1044     def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1045         self.mesh.ExportToMED(f, auto_groups, version)
1046
1047     ## Exports the mesh in a file in DAT format
1048     #  @param f the file name
1049     #  @ingroup l2_impexp
1050     def ExportDAT(self, f):
1051         self.mesh.ExportDAT(f)
1052
1053     ## Exports the mesh in a file in UNV format
1054     #  @param f the file name
1055     #  @ingroup l2_impexp
1056     def ExportUNV(self, f):
1057         self.mesh.ExportUNV(f)
1058
1059     ## Export the mesh in a file in STL format
1060     #  @param f the file name
1061     #  @param ascii defines the file encoding
1062     #  @ingroup l2_impexp
1063     def ExportSTL(self, f, ascii=1):
1064         self.mesh.ExportSTL(f, ascii)
1065
1066
1067     # Operations with groups:
1068     # ----------------------
1069
1070     ## Creates an empty mesh group
1071     #  @param elementType the type of elements in the group
1072     #  @param name the name of the mesh group
1073     #  @return SMESH_Group
1074     #  @ingroup l2_grps_create
1075     def CreateEmptyGroup(self, elementType, name):
1076         return self.mesh.CreateGroup(elementType, name)
1077
1078     ## Creates a mesh group based on the geometrical object \a grp
1079     #  and gives a \a name, \n if this parameter is not defined
1080     #  the name is the same as the geometrical group name
1081     #  @param grp  a geometrical group, a vertex, an edge, a face or a solid
1082     #  @param name the name of the mesh group
1083     #  @param typ  the type of elements in the group. If not set, it is
1084     #              automatically detected by the type of the geometry
1085     #  @return SMESH_GroupOnGeom
1086     #  @ingroup l2_grps_create
1087     def GroupOnGeom(self, grp, name="", typ=None):
1088         if name == "":
1089             name = grp.GetName()
1090
1091         if typ == None:
1092             tgeo = str(grp.GetShapeType())
1093             if tgeo == "VERTEX":
1094                 typ = NODE
1095             elif tgeo == "EDGE":
1096                 typ = EDGE
1097             elif tgeo == "FACE":
1098                 typ = FACE
1099             elif tgeo == "SOLID":
1100                 typ = VOLUME
1101             elif tgeo == "SHELL":
1102                 typ = VOLUME
1103             elif tgeo == "COMPOUND":
1104                 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1105                     print "Mesh.Group: empty geometric group", GetName( grp )
1106                     return 0
1107                 tgeo = self.geompyD.GetType(grp)
1108                 if tgeo == geompyDC.ShapeType["VERTEX"]:
1109                     typ = NODE
1110                 elif tgeo == geompyDC.ShapeType["EDGE"]:
1111                     typ = EDGE
1112                 elif tgeo == geompyDC.ShapeType["FACE"]:
1113                     typ = FACE
1114                 elif tgeo == geompyDC.ShapeType["SOLID"]:
1115                     typ = VOLUME
1116
1117         if typ == None:
1118             print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1119             return 0
1120         else:
1121             return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1122
1123     ## Creates a mesh group by the given ids of elements
1124     #  @param groupName the name of the mesh group
1125     #  @param elementType the type of elements in the group
1126     #  @param elemIDs the list of ids
1127     #  @return SMESH_Group
1128     #  @ingroup l2_grps_create
1129     def MakeGroupByIds(self, groupName, elementType, elemIDs):
1130         group = self.mesh.CreateGroup(elementType, groupName)
1131         group.Add(elemIDs)
1132         return group
1133
1134     ## Creates a mesh group by the given conditions
1135     #  @param groupName the name of the mesh group
1136     #  @param elementType the type of elements in the group
1137     #  @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1138     #  @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1139     #  @param Treshold the threshold value (range of id ids as string, shape, numeric)
1140     #  @param UnaryOp FT_LogicalNOT or FT_Undefined
1141     #  @return SMESH_Group
1142     #  @ingroup l2_grps_create
1143     def MakeGroup(self,
1144                   groupName,
1145                   elementType,
1146                   CritType=FT_Undefined,
1147                   Compare=FT_EqualTo,
1148                   Treshold="",
1149                   UnaryOp=FT_Undefined):
1150         aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1151         group = self.MakeGroupByCriterion(groupName, aCriterion)
1152         return group
1153
1154     ## Creates a mesh group by the given criterion
1155     #  @param groupName the name of the mesh group
1156     #  @param Criterion the instance of Criterion class
1157     #  @return SMESH_Group
1158     #  @ingroup l2_grps_create
1159     def MakeGroupByCriterion(self, groupName, Criterion):
1160         aFilterMgr = self.smeshpyD.CreateFilterManager()
1161         aFilter = aFilterMgr.CreateFilter()
1162         aCriteria = []
1163         aCriteria.append(Criterion)
1164         aFilter.SetCriteria(aCriteria)
1165         group = self.MakeGroupByFilter(groupName, aFilter)
1166         return group
1167
1168     ## Creates a mesh group by the given criteria (list of criteria)
1169     #  @param groupName the name of the mesh group
1170     #  @param theCriteria the list of criteria
1171     #  @return SMESH_Group
1172     #  @ingroup l2_grps_create
1173     def MakeGroupByCriteria(self, groupName, theCriteria):
1174         aFilterMgr = self.smeshpyD.CreateFilterManager()
1175         aFilter = aFilterMgr.CreateFilter()
1176         aFilter.SetCriteria(theCriteria)
1177         group = self.MakeGroupByFilter(groupName, aFilter)
1178         return group
1179
1180     ## Creates a mesh group by the given filter
1181     #  @param groupName the name of the mesh group
1182     #  @param theFilter the instance of Filter class
1183     #  @return SMESH_Group
1184     #  @ingroup l2_grps_create
1185     def MakeGroupByFilter(self, groupName, theFilter):
1186         anIds = theFilter.GetElementsId(self.mesh)
1187         anElemType = theFilter.GetElementType()
1188         group = self.MakeGroupByIds(groupName, anElemType, anIds)
1189         return group
1190
1191     ## Passes mesh elements through the given filter and return IDs of fitting elements
1192     #  @param theFilter SMESH_Filter
1193     #  @return a list of ids
1194     #  @ingroup l1_controls
1195     def GetIdsFromFilter(self, theFilter):
1196         return theFilter.GetElementsId(self.mesh)
1197
1198     ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
1199     #  Returns a list of special structures (borders).
1200     #  @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
1201     #  @ingroup l1_controls
1202     def GetFreeBorders(self):
1203         aFilterMgr = self.smeshpyD.CreateFilterManager()
1204         aPredicate = aFilterMgr.CreateFreeEdges()
1205         aPredicate.SetMesh(self.mesh)
1206         aBorders = aPredicate.GetBorders()
1207         return aBorders
1208
1209     ## Removes a group
1210     #  @ingroup l2_grps_delete
1211     def RemoveGroup(self, group):
1212         self.mesh.RemoveGroup(group)
1213
1214     ## Removes a group with its contents
1215     #  @ingroup l2_grps_delete
1216     def RemoveGroupWithContents(self, group):
1217         self.mesh.RemoveGroupWithContents(group)
1218
1219     ## Gets the list of groups existing in the mesh
1220     #  @return a sequence of SMESH_GroupBase
1221     #  @ingroup l2_grps_create
1222     def GetGroups(self):
1223         return self.mesh.GetGroups()
1224
1225     ## Gets the number of groups existing in the mesh
1226     #  @return the quantity of groups as an integer value
1227     #  @ingroup l2_grps_create
1228     def NbGroups(self):
1229         return self.mesh.NbGroups()
1230
1231     ## Gets the list of names of groups existing in the mesh
1232     #  @return list of strings
1233     #  @ingroup l2_grps_create
1234     def GetGroupNames(self):
1235         groups = self.GetGroups()
1236         names = []
1237         for group in groups:
1238             names.append(group.GetName())
1239         return names
1240
1241     ## Produces a union of two groups
1242     #  A new group is created. All mesh elements that are
1243     #  present in the initial groups are added to the new one
1244     #  @return an instance of SMESH_Group
1245     #  @ingroup l2_grps_operon
1246     def UnionGroups(self, group1, group2, name):
1247         return self.mesh.UnionGroups(group1, group2, name)
1248
1249     ## Prodices an intersection of two groups
1250     #  A new group is created. All mesh elements that are common
1251     #  for the two initial groups are added to the new one.
1252     #  @return an instance of SMESH_Group
1253     #  @ingroup l2_grps_operon
1254     def IntersectGroups(self, group1, group2, name):
1255         return self.mesh.IntersectGroups(group1, group2, name)
1256
1257     ## Produces a cut of two groups
1258     #  A new group is created. All mesh elements that are present in
1259     #  the main group but are not present in the tool group are added to the new one
1260     #  @return an instance of SMESH_Group
1261     #  @ingroup l2_grps_operon
1262     def CutGroups(self, mainGroup, toolGroup, name):
1263         return self.mesh.CutGroups(mainGroup, toolGroup, name)
1264
1265
1266     # Get some info about mesh:
1267     # ------------------------
1268
1269     ## Returns the log of nodes and elements added or removed
1270     #  since the previous clear of the log.
1271     #  @param clearAfterGet log is emptied after Get (safe if concurrents access)
1272     #  @return list of log_block structures:
1273     #                                        commandType
1274     #                                        number
1275     #                                        coords
1276     #                                        indexes
1277     #  @ingroup l1_auxiliary
1278     def GetLog(self, clearAfterGet):
1279         return self.mesh.GetLog(clearAfterGet)
1280
1281     ## Clears the log of nodes and elements added or removed since the previous
1282     #  clear. Must be used immediately after GetLog if clearAfterGet is false.
1283     #  @ingroup l1_auxiliary
1284     def ClearLog(self):
1285         self.mesh.ClearLog()
1286
1287     ## Toggles auto color mode on the object.
1288     #  @param theAutoColor the flag which toggles auto color mode.
1289     #  @ingroup l1_auxiliary
1290     def SetAutoColor(self, theAutoColor):
1291         self.mesh.SetAutoColor(theAutoColor)
1292
1293     ## Gets flag of object auto color mode.
1294     #  @return True or False
1295     #  @ingroup l1_auxiliary
1296     def GetAutoColor(self):
1297         return self.mesh.GetAutoColor()
1298
1299     ## Gets the internal ID
1300     #  @return integer value, which is the internal Id of the mesh
1301     #  @ingroup l1_auxiliary
1302     def GetId(self):
1303         return self.mesh.GetId()
1304
1305     ## Get the study Id
1306     #  @return integer value, which is the study Id of the mesh
1307     #  @ingroup l1_auxiliary
1308     def GetStudyId(self):
1309         return self.mesh.GetStudyId()
1310
1311     ## Checks the group names for duplications.
1312     #  Consider the maximum group name length stored in MED file.
1313     #  @return True or False
1314     #  @ingroup l1_auxiliary
1315     def HasDuplicatedGroupNamesMED(self):
1316         return self.mesh.HasDuplicatedGroupNamesMED()
1317
1318     ## Obtains the mesh editor tool
1319     #  @return an instance of SMESH_MeshEditor
1320     #  @ingroup l1_modifying
1321     def GetMeshEditor(self):
1322         return self.mesh.GetMeshEditor()
1323
1324     ## Gets MED Mesh
1325     #  @return an instance of SALOME_MED::MESH
1326     #  @ingroup l1_auxiliary
1327     def GetMEDMesh(self):
1328         return self.mesh.GetMEDMesh()
1329
1330
1331     # Get informations about mesh contents:
1332     # ------------------------------------
1333
1334     ## Returns the number of nodes in the mesh
1335     #  @return an integer value
1336     #  @ingroup l1_meshinfo
1337     def NbNodes(self):
1338         return self.mesh.NbNodes()
1339
1340     ## Returns the number of elements in the mesh
1341     #  @return an integer value
1342     #  @ingroup l1_meshinfo
1343     def NbElements(self):
1344         return self.mesh.NbElements()
1345
1346     ## Returns the number of edges in the mesh
1347     #  @return an integer value
1348     #  @ingroup l1_meshinfo
1349     def NbEdges(self):
1350         return self.mesh.NbEdges()
1351
1352     ## Returns the number of edges with the given order in the mesh
1353     #  @param elementOrder the order of elements:
1354     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1355     #  @return an integer value
1356     #  @ingroup l1_meshinfo
1357     def NbEdgesOfOrder(self, elementOrder):
1358         return self.mesh.NbEdgesOfOrder(elementOrder)
1359
1360     ## Returns the number of faces in the mesh
1361     #  @return an integer value
1362     #  @ingroup l1_meshinfo
1363     def NbFaces(self):
1364         return self.mesh.NbFaces()
1365
1366     ## Returns the number of faces with the given order in the mesh
1367     #  @param elementOrder the order of elements:
1368     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1369     #  @return an integer value
1370     #  @ingroup l1_meshinfo
1371     def NbFacesOfOrder(self, elementOrder):
1372         return self.mesh.NbFacesOfOrder(elementOrder)
1373
1374     ## Returns the number of triangles in the mesh
1375     #  @return an integer value
1376     #  @ingroup l1_meshinfo
1377     def NbTriangles(self):
1378         return self.mesh.NbTriangles()
1379
1380     ## Returns the number of triangles with the given order in the mesh
1381     #  @param elementOrder is the order of elements:
1382     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1383     #  @return an integer value
1384     #  @ingroup l1_meshinfo
1385     def NbTrianglesOfOrder(self, elementOrder):
1386         return self.mesh.NbTrianglesOfOrder(elementOrder)
1387
1388     ## Returns the number of quadrangles in the mesh
1389     #  @return an integer value
1390     #  @ingroup l1_meshinfo
1391     def NbQuadrangles(self):
1392         return self.mesh.NbQuadrangles()
1393
1394     ## Returns the number of quadrangles with the given order in the mesh
1395     #  @param elementOrder the order of elements:
1396     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1397     #  @return an integer value
1398     #  @ingroup l1_meshinfo
1399     def NbQuadranglesOfOrder(self, elementOrder):
1400         return self.mesh.NbQuadranglesOfOrder(elementOrder)
1401
1402     ## Returns the number of polygons in the mesh
1403     #  @return an integer value
1404     #  @ingroup l1_meshinfo
1405     def NbPolygons(self):
1406         return self.mesh.NbPolygons()
1407
1408     ## Returns the number of volumes in the mesh
1409     #  @return an integer value
1410     #  @ingroup l1_meshinfo
1411     def NbVolumes(self):
1412         return self.mesh.NbVolumes()
1413
1414     ## Returns the number of volumes with the given order in the mesh
1415     #  @param elementOrder  the order of elements:
1416     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1417     #  @return an integer value
1418     #  @ingroup l1_meshinfo
1419     def NbVolumesOfOrder(self, elementOrder):
1420         return self.mesh.NbVolumesOfOrder(elementOrder)
1421
1422     ## Returns the number of tetrahedrons in the mesh
1423     #  @return an integer value
1424     #  @ingroup l1_meshinfo
1425     def NbTetras(self):
1426         return self.mesh.NbTetras()
1427
1428     ## Returns the number of tetrahedrons with the given order in the mesh
1429     #  @param elementOrder  the order of elements:
1430     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1431     #  @return an integer value
1432     #  @ingroup l1_meshinfo
1433     def NbTetrasOfOrder(self, elementOrder):
1434         return self.mesh.NbTetrasOfOrder(elementOrder)
1435
1436     ## Returns the number of hexahedrons in the mesh
1437     #  @return an integer value
1438     #  @ingroup l1_meshinfo
1439     def NbHexas(self):
1440         return self.mesh.NbHexas()
1441
1442     ## Returns the number of hexahedrons with the given order in the mesh
1443     #  @param elementOrder  the order of elements:
1444     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1445     #  @return an integer value
1446     #  @ingroup l1_meshinfo
1447     def NbHexasOfOrder(self, elementOrder):
1448         return self.mesh.NbHexasOfOrder(elementOrder)
1449
1450     ## Returns the number of pyramids in the mesh
1451     #  @return an integer value
1452     #  @ingroup l1_meshinfo
1453     def NbPyramids(self):
1454         return self.mesh.NbPyramids()
1455
1456     ## Returns the number of pyramids with the given order in the mesh
1457     #  @param elementOrder  the order of elements:
1458     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1459     #  @return an integer value
1460     #  @ingroup l1_meshinfo
1461     def NbPyramidsOfOrder(self, elementOrder):
1462         return self.mesh.NbPyramidsOfOrder(elementOrder)
1463
1464     ## Returns the number of prisms in the mesh
1465     #  @return an integer value
1466     #  @ingroup l1_meshinfo
1467     def NbPrisms(self):
1468         return self.mesh.NbPrisms()
1469
1470     ## Returns the number of prisms with the given order in the mesh
1471     #  @param elementOrder  the order of elements:
1472     #         ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1473     #  @return an integer value
1474     #  @ingroup l1_meshinfo
1475     def NbPrismsOfOrder(self, elementOrder):
1476         return self.mesh.NbPrismsOfOrder(elementOrder)
1477
1478     ## Returns the number of polyhedrons in the mesh
1479     #  @return an integer value
1480     #  @ingroup l1_meshinfo
1481     def NbPolyhedrons(self):
1482         return self.mesh.NbPolyhedrons()
1483
1484     ## Returns the number of submeshes in the mesh
1485     #  @return an integer value
1486     #  @ingroup l1_meshinfo
1487     def NbSubMesh(self):
1488         return self.mesh.NbSubMesh()
1489
1490     ## Returns the list of mesh elements IDs
1491     #  @return the list of integer values
1492     #  @ingroup l1_meshinfo
1493     def GetElementsId(self):
1494         return self.mesh.GetElementsId()
1495
1496     ## Returns the list of IDs of mesh elements with the given type
1497     #  @param elementType  the required type of elements
1498     #  @return list of integer values
1499     #  @ingroup l1_meshinfo
1500     def GetElementsByType(self, elementType):
1501         return self.mesh.GetElementsByType(elementType)
1502
1503     ## Returns the list of mesh nodes IDs
1504     #  @return the list of integer values
1505     #  @ingroup l1_meshinfo
1506     def GetNodesId(self):
1507         return self.mesh.GetNodesId()
1508
1509     # Get the information about mesh elements:
1510     # ------------------------------------
1511
1512     ## Returns the type of mesh element
1513     #  @return the value from SMESH::ElementType enumeration
1514     #  @ingroup l1_meshinfo
1515     def GetElementType(self, id, iselem):
1516         return self.mesh.GetElementType(id, iselem)
1517
1518     ## Returns the list of submesh elements IDs
1519     #  @param Shape a geom object(subshape) IOR
1520     #         Shape must be the subshape of a ShapeToMesh()
1521     #  @return the list of integer values
1522     #  @ingroup l1_meshinfo
1523     def GetSubMeshElementsId(self, Shape):
1524         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1525             ShapeID = Shape.GetSubShapeIndices()[0]
1526         else:
1527             ShapeID = Shape
1528         return self.mesh.GetSubMeshElementsId(ShapeID)
1529
1530     ## Returns the list of submesh nodes IDs
1531     #  @param Shape a geom object(subshape) IOR
1532     #         Shape must be the subshape of a ShapeToMesh()
1533     #  @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
1534     #  @return the list of integer values
1535     #  @ingroup l1_meshinfo
1536     def GetSubMeshNodesId(self, Shape, all):
1537         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1538             ShapeID = Shape.GetSubShapeIndices()[0]
1539         else:
1540             ShapeID = Shape
1541         return self.mesh.GetSubMeshNodesId(ShapeID, all)
1542
1543     ## Returns the list of IDs of submesh elements with the given type
1544     #  @param Shape a geom object(subshape) IOR
1545     #         Shape must be a subshape of a ShapeToMesh()
1546     #  @return the list of integer values
1547     #  @ingroup l1_meshinfo
1548     def GetSubMeshElementType(self, Shape):
1549         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1550             ShapeID = Shape.GetSubShapeIndices()[0]
1551         else:
1552             ShapeID = Shape
1553         return self.mesh.GetSubMeshElementType(ShapeID)
1554
1555     ## Gets the mesh description
1556     #  @return string value
1557     #  @ingroup l1_meshinfo
1558     def Dump(self):
1559         return self.mesh.Dump()
1560
1561
1562     # Get the information about nodes and elements of a mesh by its IDs:
1563     # -----------------------------------------------------------
1564
1565     ## Gets XYZ coordinates of a node
1566     #  \n If there is no nodes for the given ID - returns an empty list
1567     #  @return a list of double precision values
1568     #  @ingroup l1_meshinfo
1569     def GetNodeXYZ(self, id):
1570         return self.mesh.GetNodeXYZ(id)
1571
1572     ## Returns list of IDs of inverse elements for the given node
1573     #  \n If there is no node for the given ID - returns an empty list
1574     #  @return a list of integer values
1575     #  @ingroup l1_meshinfo
1576     def GetNodeInverseElements(self, id):
1577         return self.mesh.GetNodeInverseElements(id)
1578
1579     ## @brief Returns the position of a node on the shape
1580     #  @return SMESH::NodePosition
1581     #  @ingroup l1_meshinfo
1582     def GetNodePosition(self,NodeID):
1583         return self.mesh.GetNodePosition(NodeID)
1584
1585     ## If the given element is a node, returns the ID of shape
1586     #  \n If there is no node for the given ID - returns -1
1587     #  @return an integer value
1588     #  @ingroup l1_meshinfo
1589     def GetShapeID(self, id):
1590         return self.mesh.GetShapeID(id)
1591
1592     ## Returns the ID of the result shape after
1593     #  FindShape() from SMESH_MeshEditor for the given element
1594     #  \n If there is no element for the given ID - returns -1
1595     #  @return an integer value
1596     #  @ingroup l1_meshinfo
1597     def GetShapeIDForElem(self,id):
1598         return self.mesh.GetShapeIDForElem(id)
1599
1600     ## Returns the number of nodes for the given element
1601     #  \n If there is no element for the given ID - returns -1
1602     #  @return an integer value
1603     #  @ingroup l1_meshinfo
1604     def GetElemNbNodes(self, id):
1605         return self.mesh.GetElemNbNodes(id)
1606
1607     ## Returns the node ID the given index for the given element
1608     #  \n If there is no element for the given ID - returns -1
1609     #  \n If there is no node for the given index - returns -2
1610     #  @return an integer value
1611     #  @ingroup l1_meshinfo
1612     def GetElemNode(self, id, index):
1613         return self.mesh.GetElemNode(id, index)
1614
1615     ## Returns the IDs of nodes of the given element
1616     #  @return a list of integer values
1617     #  @ingroup l1_meshinfo
1618     def GetElemNodes(self, id):
1619         return self.mesh.GetElemNodes(id)
1620
1621     ## Returns true if the given node is the medium node in the given quadratic element
1622     #  @ingroup l1_meshinfo
1623     def IsMediumNode(self, elementID, nodeID):
1624         return self.mesh.IsMediumNode(elementID, nodeID)
1625
1626     ## Returns true if the given node is the medium node in one of quadratic elements
1627     #  @ingroup l1_meshinfo
1628     def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1629         return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1630
1631     ## Returns the number of edges for the given element
1632     #  @ingroup l1_meshinfo
1633     def ElemNbEdges(self, id):
1634         return self.mesh.ElemNbEdges(id)
1635
1636     ## Returns the number of faces for the given element
1637     #  @ingroup l1_meshinfo
1638     def ElemNbFaces(self, id):
1639         return self.mesh.ElemNbFaces(id)
1640
1641     ## Returns true if the given element is a polygon
1642     #  @ingroup l1_meshinfo
1643     def IsPoly(self, id):
1644         return self.mesh.IsPoly(id)
1645
1646     ## Returns true if the given element is quadratic
1647     #  @ingroup l1_meshinfo
1648     def IsQuadratic(self, id):
1649         return self.mesh.IsQuadratic(id)
1650
1651     ## Returns XYZ coordinates of the barycenter of the given element
1652     #  \n If there is no element for the given ID - returns an empty list
1653     #  @return a list of three double values
1654     #  @ingroup l1_meshinfo
1655     def BaryCenter(self, id):
1656         return self.mesh.BaryCenter(id)
1657
1658
1659     # Mesh edition (SMESH_MeshEditor functionality):
1660     # ---------------------------------------------
1661
1662     ## Removes the elements from the mesh by ids
1663     #  @param IDsOfElements is a list of ids of elements to remove
1664     #  @return True or False
1665     #  @ingroup l2_modif_del
1666     def RemoveElements(self, IDsOfElements):
1667         return self.editor.RemoveElements(IDsOfElements)
1668
1669     ## Removes nodes from mesh by ids
1670     #  @param IDsOfNodes is a list of ids of nodes to remove
1671     #  @return True or False
1672     #  @ingroup l2_modif_del
1673     def RemoveNodes(self, IDsOfNodes):
1674         return self.editor.RemoveNodes(IDsOfNodes)
1675
1676     ## Add a node to the mesh by coordinates
1677     #  @return Id of the new node
1678     #  @ingroup l2_modif_add
1679     def AddNode(self, x, y, z):
1680         return self.editor.AddNode( x, y, z)
1681
1682     ## Creates a linear or quadratic edge (this is determined
1683     #  by the number of given nodes).
1684     #  @param IDsOfNodes the list of node IDs for creation of the element.
1685     #  The order of nodes in this list should correspond to the description
1686     #  of MED. \n This description is located by the following link:
1687     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1688     #  @return the Id of the new edge
1689     #  @ingroup l2_modif_add
1690     def AddEdge(self, IDsOfNodes):
1691         return self.editor.AddEdge(IDsOfNodes)
1692
1693     ## Creates a linear or quadratic face (this is determined
1694     #  by the number of given nodes).
1695     #  @param IDsOfNodes the list of node IDs for creation of the element.
1696     #  The order of nodes in this list should correspond to the description
1697     #  of MED. \n This description is located by the following link:
1698     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1699     #  @return the Id of the new face
1700     #  @ingroup l2_modif_add
1701     def AddFace(self, IDsOfNodes):
1702         return self.editor.AddFace(IDsOfNodes)
1703
1704     ## Adds a polygonal face to the mesh by the list of node IDs
1705     #  @param IdsOfNodes the list of node IDs for creation of the element.
1706     #  @return the Id of the new face
1707     #  @ingroup l2_modif_add
1708     def AddPolygonalFace(self, IdsOfNodes):
1709         return self.editor.AddPolygonalFace(IdsOfNodes)
1710
1711     ## Creates both simple and quadratic volume (this is determined
1712     #  by the number of given nodes).
1713     #  @param IDsOfNodes the list of node IDs for creation of the element.
1714     #  The order of nodes in this list should correspond to the description
1715     #  of MED. \n This description is located by the following link:
1716     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1717     #  @return the Id of the new volumic element
1718     #  @ingroup l2_modif_add
1719     def AddVolume(self, IDsOfNodes):
1720         return self.editor.AddVolume(IDsOfNodes)
1721
1722     ## Creates a volume of many faces, giving nodes for each face.
1723     #  @param IdsOfNodes the list of node IDs for volume creation face by face.
1724     #  @param Quantities the list of integer values, Quantities[i]
1725     #         gives the quantity of nodes in face number i.
1726     #  @return the Id of the new volumic element
1727     #  @ingroup l2_modif_add
1728     def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1729         return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1730
1731     ## Creates a volume of many faces, giving the IDs of the existing faces.
1732     #  @param IdsOfFaces the list of face IDs for volume creation.
1733     #
1734     #  Note:  The created volume will refer only to the nodes
1735     #         of the given faces, not to the faces themselves.
1736     #  @return the Id of the new volumic element
1737     #  @ingroup l2_modif_add
1738     def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1739         return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1740
1741
1742     ## @brief Binds a node to a vertex
1743     #  @param NodeID a node ID
1744     #  @param Vertex a vertex or vertex ID
1745     #  @return True if succeed else raises an exception
1746     #  @ingroup l2_modif_add
1747     def SetNodeOnVertex(self, NodeID, Vertex):
1748         if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
1749             VertexID = Vertex.GetSubShapeIndices()[0]
1750         else:
1751             VertexID = Vertex
1752         try:
1753             self.editor.SetNodeOnVertex(NodeID, VertexID)
1754         except SALOME.SALOME_Exception, inst:
1755             raise ValueError, inst.details.text
1756         return True
1757
1758
1759     ## @brief Stores the node position on an edge
1760     #  @param NodeID a node ID
1761     #  @param Edge an edge or edge ID
1762     #  @param paramOnEdge a parameter on the edge where the node is located
1763     #  @return True if succeed else raises an exception
1764     #  @ingroup l2_modif_add
1765     def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
1766         if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
1767             EdgeID = Edge.GetSubShapeIndices()[0]
1768         else:
1769             EdgeID = Edge
1770         try:
1771             self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
1772         except SALOME.SALOME_Exception, inst:
1773             raise ValueError, inst.details.text
1774         return True
1775
1776     ## @brief Stores node position on a face
1777     #  @param NodeID a node ID
1778     #  @param Face a face or face ID
1779     #  @param u U parameter on the face where the node is located
1780     #  @param v V parameter on the face where the node is located
1781     #  @return True if succeed else raises an exception
1782     #  @ingroup l2_modif_add
1783     def SetNodeOnFace(self, NodeID, Face, u, v):
1784         if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
1785             FaceID = Face.GetSubShapeIndices()[0]
1786         else:
1787             FaceID = Face
1788         try:
1789             self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
1790         except SALOME.SALOME_Exception, inst:
1791             raise ValueError, inst.details.text
1792         return True
1793
1794     ## @brief Binds a node to a solid
1795     #  @param NodeID a node ID
1796     #  @param Solid  a solid or solid ID
1797     #  @return True if succeed else raises an exception
1798     #  @ingroup l2_modif_add
1799     def SetNodeInVolume(self, NodeID, Solid):
1800         if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
1801             SolidID = Solid.GetSubShapeIndices()[0]
1802         else:
1803             SolidID = Solid
1804         try:
1805             self.editor.SetNodeInVolume(NodeID, SolidID)
1806         except SALOME.SALOME_Exception, inst:
1807             raise ValueError, inst.details.text
1808         return True
1809
1810     ## @brief Bind an element to a shape
1811     #  @param ElementID an element ID
1812     #  @param Shape a shape or shape ID
1813     #  @return True if succeed else raises an exception
1814     #  @ingroup l2_modif_add
1815     def SetMeshElementOnShape(self, ElementID, Shape):
1816         if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1817             ShapeID = Shape.GetSubShapeIndices()[0]
1818         else:
1819             ShapeID = Shape
1820         try:
1821             self.editor.SetMeshElementOnShape(ElementID, ShapeID)
1822         except SALOME.SALOME_Exception, inst:
1823             raise ValueError, inst.details.text
1824         return True
1825
1826
1827     ## Moves the node with the given id
1828     #  @param NodeID the id of the node
1829     #  @param x  a new X coordinate
1830     #  @param y  a new Y coordinate
1831     #  @param z  a new Z coordinate
1832     #  @return True if succeed else False
1833     #  @ingroup l2_modif_movenode
1834     def MoveNode(self, NodeID, x, y, z):
1835         return self.editor.MoveNode(NodeID, x, y, z)
1836
1837     ## Finds the node closest to a point
1838     #  @param x  the X coordinate of a point
1839     #  @param y  the Y coordinate of a point
1840     #  @param z  the Z coordinate of a point
1841     #  @return the ID of a node
1842     #  @ingroup l2_modif_throughp
1843     def FindNodeClosestTo(self, x, y, z):
1844         preview = self.mesh.GetMeshEditPreviewer()
1845         return preview.MoveClosestNodeToPoint(x, y, z, -1)
1846
1847     ## Finds the node closest to a point and moves it to a point location
1848     #  @param x  the X coordinate of a point
1849     #  @param y  the Y coordinate of a point
1850     #  @param z  the Z coordinate of a point
1851     #  @return the ID of a moved node
1852     #  @ingroup l2_modif_throughp
1853     def MeshToPassThroughAPoint(self, x, y, z):
1854         return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1855
1856     ## Replaces two neighbour triangles sharing Node1-Node2 link
1857     #  with the triangles built on the same 4 nodes but having other common link.
1858     #  @param NodeID1  the ID of the first node
1859     #  @param NodeID2  the ID of the second node
1860     #  @return false if proper faces were not found
1861     #  @ingroup l2_modif_invdiag
1862     def InverseDiag(self, NodeID1, NodeID2):
1863         return self.editor.InverseDiag(NodeID1, NodeID2)
1864
1865     ## Replaces two neighbour triangles sharing Node1-Node2 link
1866     #  with a quadrangle built on the same 4 nodes.
1867     #  @param NodeID1  the ID of the first node
1868     #  @param NodeID2  the ID of the second node
1869     #  @return false if proper faces were not found
1870     #  @ingroup l2_modif_unitetri
1871     def DeleteDiag(self, NodeID1, NodeID2):
1872         return self.editor.DeleteDiag(NodeID1, NodeID2)
1873
1874     ## Reorients elements by ids
1875     #  @param IDsOfElements if undefined reorients all mesh elements
1876     #  @return True if succeed else False
1877     #  @ingroup l2_modif_changori
1878     def Reorient(self, IDsOfElements=None):
1879         if IDsOfElements == None:
1880             IDsOfElements = self.GetElementsId()
1881         return self.editor.Reorient(IDsOfElements)
1882
1883     ## Reorients all elements of the object
1884     #  @param theObject mesh, submesh or group
1885     #  @return True if succeed else False
1886     #  @ingroup l2_modif_changori
1887     def ReorientObject(self, theObject):
1888         if ( isinstance( theObject, Mesh )):
1889             theObject = theObject.GetMesh()
1890         return self.editor.ReorientObject(theObject)
1891
1892     ## Fuses the neighbouring triangles into quadrangles.
1893     #  @param IDsOfElements The triangles to be fused,
1894     #  @param theCriterion  is FT_...; used to choose a neighbour to fuse with.
1895     #  @param MaxAngle      is the maximum angle between element normals at which the fusion
1896     #                       is still performed; theMaxAngle is mesured in radians.
1897     #  @return TRUE in case of success, FALSE otherwise.
1898     #  @ingroup l2_modif_unitetri
1899     def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1900         if IDsOfElements == []:
1901             IDsOfElements = self.GetElementsId()
1902         return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1903
1904     ## Fuses the neighbouring triangles of the object into quadrangles
1905     #  @param theObject is mesh, submesh or group
1906     #  @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1907     #  @param MaxAngle   a max angle between element normals at which the fusion
1908     #                   is still performed; theMaxAngle is mesured in radians.
1909     #  @return TRUE in case of success, FALSE otherwise.
1910     #  @ingroup l2_modif_unitetri
1911     def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1912         if ( isinstance( theObject, Mesh )):
1913             theObject = theObject.GetMesh()
1914         return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1915
1916     ## Splits quadrangles into triangles.
1917     #  @param IDsOfElements the faces to be splitted.
1918     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
1919     #  @return TRUE in case of success, FALSE otherwise.
1920     #  @ingroup l2_modif_cutquadr
1921     def QuadToTri (self, IDsOfElements, theCriterion):
1922         if IDsOfElements == []:
1923             IDsOfElements = self.GetElementsId()
1924         return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
1925
1926     ## Splits quadrangles into triangles.
1927     #  @param theObject  the object from which the list of elements is taken, this is mesh, submesh or group
1928     #  @param theCriterion   FT_...; used to choose a diagonal for splitting.
1929     #  @return TRUE in case of success, FALSE otherwise.
1930     #  @ingroup l2_modif_cutquadr
1931     def QuadToTriObject (self, theObject, theCriterion):
1932         if ( isinstance( theObject, Mesh )):
1933             theObject = theObject.GetMesh()
1934         return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
1935
1936     ## Splits quadrangles into triangles.
1937     #  @param IDsOfElements the faces to be splitted
1938     #  @param Diag13        is used to choose a diagonal for splitting.
1939     #  @return TRUE in case of success, FALSE otherwise.
1940     #  @ingroup l2_modif_cutquadr
1941     def SplitQuad (self, IDsOfElements, Diag13):
1942         if IDsOfElements == []:
1943             IDsOfElements = self.GetElementsId()
1944         return self.editor.SplitQuad(IDsOfElements, Diag13)
1945
1946     ## Splits quadrangles into triangles.
1947     #  @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
1948     #  @param Diag13    is used to choose a diagonal for splitting.
1949     #  @return TRUE in case of success, FALSE otherwise.
1950     #  @ingroup l2_modif_cutquadr
1951     def SplitQuadObject (self, theObject, Diag13):
1952         if ( isinstance( theObject, Mesh )):
1953             theObject = theObject.GetMesh()
1954         return self.editor.SplitQuadObject(theObject, Diag13)
1955
1956     ## Finds a better splitting of the given quadrangle.
1957     #  @param IDOfQuad   the ID of the quadrangle to be splitted.
1958     #  @param theCriterion  FT_...; a criterion to choose a diagonal for splitting.
1959     #  @return 1 if 1-3 diagonal is better, 2 if 2-4
1960     #          diagonal is better, 0 if error occurs.
1961     #  @ingroup l2_modif_cutquadr
1962     def BestSplit (self, IDOfQuad, theCriterion):
1963         return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
1964
1965     ## Splits quadrangle faces near triangular facets of volumes
1966     #
1967     #  @ingroup l1_auxiliary
1968     def SplitQuadsNearTriangularFacets(self):
1969         faces_array = self.GetElementsByType(SMESH.FACE)
1970         for face_id in faces_array:
1971             if self.GetElemNbNodes(face_id) == 4: # quadrangle
1972                 quad_nodes = self.mesh.GetElemNodes(face_id)
1973                 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1974                 isVolumeFound = False
1975                 for node1_elem in node1_elems:
1976                     if not isVolumeFound:
1977                         if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1978                             nb_nodes = self.GetElemNbNodes(node1_elem)
1979                             if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1980                                 volume_elem = node1_elem
1981                                 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1982                                 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1983                                     if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1984                                         isVolumeFound = True
1985                                         if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1986                                             self.SplitQuad([face_id], False) # diagonal 2-4
1987                                     elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1988                                         isVolumeFound = True
1989                                         self.SplitQuad([face_id], True) # diagonal 1-3
1990                                 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1991                                     if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1992                                         isVolumeFound = True
1993                                         self.SplitQuad([face_id], True) # diagonal 1-3
1994
1995     ## @brief Splits hexahedrons into tetrahedrons.
1996     #
1997     #  This operation uses pattern mapping functionality for splitting.
1998     #  @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
1999     #  @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2000     #         pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2001     #         will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2002     #         key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2003     #         The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2004     #  @return TRUE in case of success, FALSE otherwise.
2005     #  @ingroup l1_auxiliary
2006     def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2007         # Pattern:     5.---------.6
2008         #              /|#*      /|
2009         #             / | #*    / |
2010         #            /  |  # * /  |
2011         #           /   |   # /*  |
2012         # (0,0,1) 4.---------.7 * |
2013         #          |#*  |1   | # *|
2014         #          | # *.----|---#.2
2015         #          |  #/ *   |   /
2016         #          |  /#  *  |  /
2017         #          | /   # * | /
2018         #          |/      #*|/
2019         # (0,0,0) 0.---------.3
2020         pattern_tetra = "!!! Nb of points: \n 8 \n\
2021         !!! Points: \n\
2022         0 0 0  !- 0 \n\
2023         0 1 0  !- 1 \n\
2024         1 1 0  !- 2 \n\
2025         1 0 0  !- 3 \n\
2026         0 0 1  !- 4 \n\
2027         0 1 1  !- 5 \n\
2028         1 1 1  !- 6 \n\
2029         1 0 1  !- 7 \n\
2030         !!! Indices of points of 6 tetras: \n\
2031         0 3 4 1 \n\
2032         7 4 3 1 \n\
2033         4 7 5 1 \n\
2034         6 2 5 7 \n\
2035         1 5 2 7 \n\
2036         2 3 1 7 \n"
2037
2038         pattern = self.smeshpyD.GetPattern()
2039         isDone  = pattern.LoadFromFile(pattern_tetra)
2040         if not isDone:
2041             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2042             return isDone
2043
2044         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2045         isDone = pattern.MakeMesh(self.mesh, False, False)
2046         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2047
2048         # split quafrangle faces near triangular facets of volumes
2049         self.SplitQuadsNearTriangularFacets()
2050
2051         return isDone
2052
2053     ## @brief Split hexahedrons into prisms.
2054     #
2055     #  Uses the pattern mapping functionality for splitting.
2056     #  @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2057     #  @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2058     #         pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2059     #         will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2060     #         will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2061     #         Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2062     #  @return TRUE in case of success, FALSE otherwise.
2063     #  @ingroup l1_auxiliary
2064     def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2065         # Pattern:     5.---------.6
2066         #              /|#       /|
2067         #             / | #     / |
2068         #            /  |  #   /  |
2069         #           /   |   # /   |
2070         # (0,0,1) 4.---------.7   |
2071         #          |    |    |    |
2072         #          |   1.----|----.2
2073         #          |   / *   |   /
2074         #          |  /   *  |  /
2075         #          | /     * | /
2076         #          |/       *|/
2077         # (0,0,0) 0.---------.3
2078         pattern_prism = "!!! Nb of points: \n 8 \n\
2079         !!! Points: \n\
2080         0 0 0  !- 0 \n\
2081         0 1 0  !- 1 \n\
2082         1 1 0  !- 2 \n\
2083         1 0 0  !- 3 \n\
2084         0 0 1  !- 4 \n\
2085         0 1 1  !- 5 \n\
2086         1 1 1  !- 6 \n\
2087         1 0 1  !- 7 \n\
2088         !!! Indices of points of 2 prisms: \n\
2089         0 1 3 4 5 7 \n\
2090         2 3 1 6 7 5 \n"
2091
2092         pattern = self.smeshpyD.GetPattern()
2093         isDone  = pattern.LoadFromFile(pattern_prism)
2094         if not isDone:
2095             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2096             return isDone
2097
2098         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2099         isDone = pattern.MakeMesh(self.mesh, False, False)
2100         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2101
2102         # Splits quafrangle faces near triangular facets of volumes
2103         self.SplitQuadsNearTriangularFacets()
2104
2105         return isDone
2106
2107     ## Smoothes elements
2108     #  @param IDsOfElements the list if ids of elements to smooth
2109     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2110     #  Note that nodes built on edges and boundary nodes are always fixed.
2111     #  @param MaxNbOfIterations the maximum number of iterations
2112     #  @param MaxAspectRatio varies in range [1.0, inf]
2113     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2114     #  @return TRUE in case of success, FALSE otherwise.
2115     #  @ingroup l2_modif_smooth
2116     def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2117                MaxNbOfIterations, MaxAspectRatio, Method):
2118         if IDsOfElements == []:
2119             IDsOfElements = self.GetElementsId()
2120         return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2121                                   MaxNbOfIterations, MaxAspectRatio, Method)
2122
2123     ## Smoothes elements which belong to the given object
2124     #  @param theObject the object to smooth
2125     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2126     #  Note that nodes built on edges and boundary nodes are always fixed.
2127     #  @param MaxNbOfIterations the maximum number of iterations
2128     #  @param MaxAspectRatio varies in range [1.0, inf]
2129     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2130     #  @return TRUE in case of success, FALSE otherwise.
2131     #  @ingroup l2_modif_smooth
2132     def SmoothObject(self, theObject, IDsOfFixedNodes,
2133                      MaxNbOfIterations, MaxAspectRatio, Method):
2134         if ( isinstance( theObject, Mesh )):
2135             theObject = theObject.GetMesh()
2136         return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2137                                         MaxNbOfIterations, MaxAspectRatio, Method)
2138
2139     ## Parametrically smoothes the given elements
2140     #  @param IDsOfElements the list if ids of elements to smooth
2141     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2142     #  Note that nodes built on edges and boundary nodes are always fixed.
2143     #  @param MaxNbOfIterations the maximum number of iterations
2144     #  @param MaxAspectRatio varies in range [1.0, inf]
2145     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2146     #  @return TRUE in case of success, FALSE otherwise.
2147     #  @ingroup l2_modif_smooth
2148     def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2149                          MaxNbOfIterations, MaxAspectRatio, Method):
2150         if IDsOfElements == []:
2151             IDsOfElements = self.GetElementsId()
2152         return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2153                                             MaxNbOfIterations, MaxAspectRatio, Method)
2154
2155     ## Parametrically smoothes the elements which belong to the given object
2156     #  @param theObject the object to smooth
2157     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
2158     #  Note that nodes built on edges and boundary nodes are always fixed.
2159     #  @param MaxNbOfIterations the maximum number of iterations
2160     #  @param MaxAspectRatio varies in range [1.0, inf]
2161     #  @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2162     #  @return TRUE in case of success, FALSE otherwise.
2163     #  @ingroup l2_modif_smooth
2164     def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2165                                MaxNbOfIterations, MaxAspectRatio, Method):
2166         if ( isinstance( theObject, Mesh )):
2167             theObject = theObject.GetMesh()
2168         return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2169                                                   MaxNbOfIterations, MaxAspectRatio, Method)
2170
2171     ## Converts the mesh to quadratic, deletes old elements, replacing
2172     #  them with quadratic with the same id.
2173     #  @ingroup l2_modif_tofromqu
2174     def ConvertToQuadratic(self, theForce3d):
2175         self.editor.ConvertToQuadratic(theForce3d)
2176
2177     ## Converts the mesh from quadratic to ordinary,
2178     #  deletes old quadratic elements, \n replacing
2179     #  them with ordinary mesh elements with the same id.
2180     #  @return TRUE in case of success, FALSE otherwise.
2181     #  @ingroup l2_modif_tofromqu
2182     def ConvertFromQuadratic(self):
2183         return self.editor.ConvertFromQuadratic()
2184
2185     ## Renumber mesh nodes
2186     #  @ingroup l2_modif_renumber
2187     def RenumberNodes(self):
2188         self.editor.RenumberNodes()
2189
2190     ## Renumber mesh elements
2191     #  @ingroup l2_modif_renumber
2192     def RenumberElements(self):
2193         self.editor.RenumberElements()
2194
2195     ## Generates new elements by rotation of the elements around the axis
2196     #  @param IDsOfElements the list of ids of elements to sweep
2197     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
2198     #  @param AngleInRadians the angle of Rotation
2199     #  @param NbOfSteps the number of steps
2200     #  @param Tolerance tolerance
2201     #  @param MakeGroups forces the generation of new groups from existing ones
2202     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
2203     #                    of all steps, else - size of each step
2204     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2205     #  @ingroup l2_modif_extrurev
2206     def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
2207                       MakeGroups=False, TotalAngle=False):
2208         if IDsOfElements == []:
2209             IDsOfElements = self.GetElementsId()
2210         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2211             Axis = self.smeshpyD.GetAxisStruct(Axis)
2212         if TotalAngle and NbOfSteps:
2213             AngleInRadians /= NbOfSteps
2214         if MakeGroups:
2215             return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
2216                                                        AngleInRadians, NbOfSteps, Tolerance)
2217         self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
2218         return []
2219
2220     ## Generates new elements by rotation of the elements of object around the axis
2221     #  @param theObject object which elements should be sweeped
2222     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
2223     #  @param AngleInRadians the angle of Rotation
2224     #  @param NbOfSteps number of steps
2225     #  @param Tolerance tolerance
2226     #  @param MakeGroups forces the generation of new groups from existing ones
2227     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
2228     #                    of all steps, else - size of each step
2229     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2230     #  @ingroup l2_modif_extrurev
2231     def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
2232                             MakeGroups=False, TotalAngle=False):
2233         if ( isinstance( theObject, Mesh )):
2234             theObject = theObject.GetMesh()
2235         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2236             Axis = self.smeshpyD.GetAxisStruct(Axis)
2237         if TotalAngle and NbOfSteps:
2238             AngleInRadians /= NbOfSteps
2239         if MakeGroups:
2240             return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
2241                                                              NbOfSteps, Tolerance)
2242         self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
2243         return []
2244
2245     ## Generates new elements by extrusion of the elements with given ids
2246     #  @param IDsOfElements the list of elements ids for extrusion
2247     #  @param StepVector vector, defining the direction and value of extrusion
2248     #  @param NbOfSteps the number of steps
2249     #  @param MakeGroups forces the generation of new groups from existing ones
2250     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2251     #  @ingroup l2_modif_extrurev
2252     def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2253         if IDsOfElements == []:
2254             IDsOfElements = self.GetElementsId()
2255         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2256             StepVector = self.smeshpyD.GetDirStruct(StepVector)
2257         if MakeGroups:
2258             return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2259         self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2260         return []
2261
2262     ## Generates new elements by extrusion of the elements with given ids
2263     #  @param IDsOfElements is ids of elements
2264     #  @param StepVector vector, defining the direction and value of extrusion
2265     #  @param NbOfSteps the number of steps
2266     #  @param ExtrFlags sets flags for extrusion
2267     #  @param SewTolerance uses for comparing locations of nodes if flag
2268     #         EXTRUSION_FLAG_SEW is set
2269     #  @param MakeGroups forces the generation of new groups from existing ones
2270     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2271     #  @ingroup l2_modif_extrurev
2272     def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
2273                           ExtrFlags, SewTolerance, MakeGroups=False):
2274         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2275             StepVector = self.smeshpyD.GetDirStruct(StepVector)
2276         if MakeGroups:
2277             return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2278                                                            ExtrFlags, SewTolerance)
2279         self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2280                                       ExtrFlags, SewTolerance)
2281         return []
2282
2283     ## Generates new elements by extrusion of the elements which belong to the object
2284     #  @param theObject the object which elements should be processed
2285     #  @param StepVector vector, defining the direction and value of extrusion
2286     #  @param NbOfSteps the number of steps
2287     #  @param MakeGroups forces the generation of new groups from existing ones
2288     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2289     #  @ingroup l2_modif_extrurev
2290     def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2291         if ( isinstance( theObject, Mesh )):
2292             theObject = theObject.GetMesh()
2293         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2294             StepVector = self.smeshpyD.GetDirStruct(StepVector)
2295         if MakeGroups:
2296             return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2297         self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2298         return []
2299
2300     ## Generates new elements by extrusion of the elements which belong to the object
2301     #  @param theObject object which elements should be processed
2302     #  @param StepVector vector, defining the direction and value of extrusion
2303     #  @param NbOfSteps the number of steps
2304     #  @param MakeGroups to generate new groups from existing ones
2305     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2306     #  @ingroup l2_modif_extrurev
2307     def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2308         if ( isinstance( theObject, Mesh )):
2309             theObject = theObject.GetMesh()
2310         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2311             StepVector = self.smeshpyD.GetDirStruct(StepVector)
2312         if MakeGroups:
2313             return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2314         self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2315         return []
2316
2317     ## Generates new elements by extrusion of the elements which belong to the object
2318     #  @param theObject object which elements should be processed
2319     #  @param StepVector vector, defining the direction and value of extrusion
2320     #  @param NbOfSteps the number of steps
2321     #  @param MakeGroups forces the generation of new groups from existing ones
2322     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2323     #  @ingroup l2_modif_extrurev
2324     def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2325         if ( isinstance( theObject, Mesh )):
2326             theObject = theObject.GetMesh()
2327         if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2328             StepVector = self.smeshpyD.GetDirStruct(StepVector)
2329         if MakeGroups:
2330             return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2331         self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2332         return []
2333
2334     ## Generates new elements by extrusion of the given elements
2335     #  The path of extrusion must be a meshed edge.
2336     #  @param IDsOfElements ids of elements
2337     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2338     #  @param PathShape shape(edge) defines the sub-mesh for the path
2339     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2340     #  @param HasAngles allows the shape to be rotated around the path
2341     #                   to get the resulting mesh in a helical fashion
2342     #  @param Angles list of angles
2343     #  @param HasRefPoint allows using the reference point
2344     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2345     #         The User can specify any point as the Reference Point.
2346     #  @param MakeGroups forces the generation of new groups from existing ones
2347     #  @param LinearVariation forces the computation of rotation angles as linear
2348     #                         variation of the given Angles along path steps
2349     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2350     #          only SMESH::Extrusion_Error otherwise
2351     #  @ingroup l2_modif_extrurev
2352     def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2353                            HasAngles, Angles, HasRefPoint, RefPoint,
2354                            MakeGroups=False, LinearVariation=False):
2355         if IDsOfElements == []:
2356             IDsOfElements = self.GetElementsId()
2357         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2358             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2359             pass
2360         if ( isinstance( PathMesh, Mesh )):
2361             PathMesh = PathMesh.GetMesh()
2362         if HasAngles and Angles and LinearVariation:
2363             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2364             pass
2365         if MakeGroups:
2366             return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
2367                                                             PathShape, NodeStart, HasAngles,
2368                                                             Angles, HasRefPoint, RefPoint)
2369         return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
2370                                               NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2371
2372     ## Generates new elements by extrusion of the elements which belong to the object
2373     #  The path of extrusion must be a meshed edge.
2374     #  @param theObject the object which elements should be processed
2375     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
2376     #  @param PathShape shape(edge) defines the sub-mesh for the path
2377     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2378     #  @param HasAngles allows the shape to be rotated around the path
2379     #                   to get the resulting mesh in a helical fashion
2380     #  @param Angles list of angles
2381     #  @param HasRefPoint allows using the reference point
2382     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2383     #         The User can specify any point as the Reference Point.
2384     #  @param MakeGroups forces the generation of new groups from existing ones
2385     #  @param LinearVariation forces the computation of rotation angles as linear
2386     #                         variation of the given Angles along path steps
2387     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2388     #          only SMESH::Extrusion_Error otherwise
2389     #  @ingroup l2_modif_extrurev
2390     def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2391                                  HasAngles, Angles, HasRefPoint, RefPoint,
2392                                  MakeGroups=False, LinearVariation=False):
2393         if ( isinstance( theObject, Mesh )):
2394             theObject = theObject.GetMesh()
2395         if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2396             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2397         if ( isinstance( PathMesh, Mesh )):
2398             PathMesh = PathMesh.GetMesh()
2399         if HasAngles and Angles and LinearVariation:
2400             Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2401             pass
2402         if MakeGroups:
2403             return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
2404                                                                   PathShape, NodeStart, HasAngles,
2405                                                                   Angles, HasRefPoint, RefPoint)
2406         return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
2407                                                     NodeStart, HasAngles, Angles, HasRefPoint,
2408                                                     RefPoint)
2409
2410     ## Creates a symmetrical copy of mesh elements
2411     #  @param IDsOfElements list of elements ids
2412     #  @param Mirror is AxisStruct or geom object(point, line, plane)
2413     #  @param theMirrorType is  POINT, AXIS or PLANE
2414     #  If the Mirror is a geom object this parameter is unnecessary
2415     #  @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
2416     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2417     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2418     #  @ingroup l2_modif_trsf
2419     def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2420         if IDsOfElements == []:
2421             IDsOfElements = self.GetElementsId()
2422         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2423             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2424         if Copy and MakeGroups:
2425             return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2426         self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2427         return []
2428
2429     ## Creates a new mesh by a symmetrical copy of mesh elements
2430     #  @param IDsOfElements the list of elements ids
2431     #  @param Mirror is AxisStruct or geom object (point, line, plane)
2432     #  @param theMirrorType is  POINT, AXIS or PLANE
2433     #  If the Mirror is a geom object this parameter is unnecessary
2434     #  @param MakeGroups to generate new groups from existing ones
2435     #  @param NewMeshName a name of the new mesh to create
2436     #  @return instance of Mesh class
2437     #  @ingroup l2_modif_trsf
2438     def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
2439         if IDsOfElements == []:
2440             IDsOfElements = self.GetElementsId()
2441         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2442             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2443         mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
2444                                           MakeGroups, NewMeshName)
2445         return Mesh(self.smeshpyD,self.geompyD,mesh)
2446
2447     ## Creates a symmetrical copy of the object
2448     #  @param theObject mesh, submesh or group
2449     #  @param Mirror AxisStruct or geom object (point, line, plane)
2450     #  @param theMirrorType is  POINT, AXIS or PLANE
2451     #  If the Mirror is a geom object this parameter is unnecessary
2452     #  @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
2453     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2454     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2455     #  @ingroup l2_modif_trsf
2456     def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2457         if ( isinstance( theObject, Mesh )):
2458             theObject = theObject.GetMesh()
2459         if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2460             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2461         if Copy and MakeGroups:
2462             return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2463         self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2464         return []
2465
2466     ## Creates a new mesh by a symmetrical copy of the object
2467     #  @param theObject mesh, submesh or group
2468     #  @param Mirror AxisStruct or geom object (point, line, plane)
2469     #  @param theMirrorType POINT, AXIS or PLANE
2470     #  If the Mirror is a geom object this parameter is unnecessary
2471     #  @param MakeGroups forces the generation of new groups from existing ones
2472     #  @param NewMeshName the name of the new mesh to create
2473     #  @return instance of Mesh class
2474     #  @ingroup l2_modif_trsf
2475     def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
2476         if ( isinstance( theObject, Mesh )):
2477             theObject = theObject.GetMesh()
2478         if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2479             Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2480         mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
2481                                                 MakeGroups, NewMeshName)
2482         return Mesh( self.smeshpyD,self.geompyD,mesh )
2483
2484     ## Translates the elements
2485     #  @param IDsOfElements list of elements ids
2486     #  @param Vector the direction of translation (DirStruct or vector)
2487     #  @param Copy allows copying the translated elements
2488     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2489     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2490     #  @ingroup l2_modif_trsf
2491     def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2492         if IDsOfElements == []:
2493             IDsOfElements = self.GetElementsId()
2494         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2495             Vector = self.smeshpyD.GetDirStruct(Vector)
2496         if Copy and MakeGroups:
2497             return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2498         self.editor.Translate(IDsOfElements, Vector, Copy)
2499         return []
2500
2501     ## Creates a new mesh of translated elements
2502     #  @param IDsOfElements list of elements ids
2503     #  @param Vector the direction of translation (DirStruct or vector)
2504     #  @param MakeGroups forces the generation of new groups from existing ones
2505     #  @param NewMeshName the name of the newly created mesh
2506     #  @return instance of Mesh class
2507     #  @ingroup l2_modif_trsf
2508     def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
2509         if IDsOfElements == []:
2510             IDsOfElements = self.GetElementsId()
2511         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2512             Vector = self.smeshpyD.GetDirStruct(Vector)
2513         mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
2514         return Mesh ( self.smeshpyD, self.geompyD, mesh )
2515
2516     ## Translates the object
2517     #  @param theObject the object to translate (mesh, submesh, or group)
2518     #  @param Vector direction of translation (DirStruct or geom vector)
2519     #  @param Copy allows copying the translated elements
2520     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2521     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2522     #  @ingroup l2_modif_trsf
2523     def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2524         if ( isinstance( theObject, Mesh )):
2525             theObject = theObject.GetMesh()
2526         if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2527             Vector = self.smeshpyD.GetDirStruct(Vector)
2528         if Copy and MakeGroups:
2529             return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2530         self.editor.TranslateObject(theObject, Vector, Copy)
2531         return []
2532
2533     ## Creates a new mesh from the translated object
2534     #  @param theObject the object to translate (mesh, submesh, or group)
2535     #  @param Vector the direction of translation (DirStruct or geom vector)
2536     #  @param MakeGroups forces the generation of new groups from existing ones
2537     #  @param NewMeshName the name of the newly created mesh
2538     #  @return instance of Mesh class
2539     #  @ingroup l2_modif_trsf
2540     def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
2541         if (isinstance(theObject, Mesh)):
2542             theObject = theObject.GetMesh()
2543         if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
2544             Vector = self.smeshpyD.GetDirStruct(Vector)
2545         mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
2546         return Mesh( self.smeshpyD, self.geompyD, mesh )
2547
2548     ## Rotates the elements
2549     #  @param IDsOfElements list of elements ids
2550     #  @param Axis the axis of rotation (AxisStruct or geom line)
2551     #  @param AngleInRadians the angle of rotation (in radians)
2552     #  @param Copy allows copying the rotated elements
2553     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2554     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2555     #  @ingroup l2_modif_trsf
2556     def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2557         if IDsOfElements == []:
2558             IDsOfElements = self.GetElementsId()
2559         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2560             Axis = self.smeshpyD.GetAxisStruct(Axis)
2561         if Copy and MakeGroups:
2562             return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2563         self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2564         return []
2565
2566     ## Creates a new mesh of rotated elements
2567     #  @param IDsOfElements list of element ids
2568     #  @param Axis the axis of rotation (AxisStruct or geom line)
2569     #  @param AngleInRadians the angle of rotation (in radians)
2570     #  @param MakeGroups forces the generation of new groups from existing ones
2571     #  @param NewMeshName the name of the newly created mesh
2572     #  @return instance of Mesh class
2573     #  @ingroup l2_modif_trsf
2574     def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
2575         if IDsOfElements == []:
2576             IDsOfElements = self.GetElementsId()
2577         if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2578             Axis = self.smeshpyD.GetAxisStruct(Axis)
2579         mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
2580                                           MakeGroups, NewMeshName)
2581         return Mesh( self.smeshpyD, self.geompyD, mesh )
2582
2583     ## Rotates the object
2584     #  @param theObject the object to rotate( mesh, submesh, or group)
2585     #  @param Axis the axis of rotation (AxisStruct or geom line)
2586     #  @param AngleInRadians the angle of rotation (in radians)
2587     #  @param Copy allows copying the rotated elements
2588     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2589     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2590     #  @ingroup l2_modif_trsf
2591     def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2592         if (isinstance(theObject, Mesh)):
2593             theObject = theObject.GetMesh()
2594         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2595             Axis = self.smeshpyD.GetAxisStruct(Axis)
2596         if Copy and MakeGroups:
2597             return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2598         self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2599         return []
2600
2601     ## Creates a new mesh from the rotated object
2602     #  @param theObject the object to rotate (mesh, submesh, or group)
2603     #  @param Axis the axis of rotation (AxisStruct or geom line)
2604     #  @param AngleInRadians the angle of rotation (in radians)
2605     #  @param MakeGroups forces the generation of new groups from existing ones
2606     #  @param NewMeshName the name of the newly created mesh
2607     #  @return instance of Mesh class
2608     #  @ingroup l2_modif_trsf
2609     def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
2610         if (isinstance( theObject, Mesh )):
2611             theObject = theObject.GetMesh()
2612         if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2613             Axis = self.smeshpyD.GetAxisStruct(Axis)
2614         mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
2615                                                        MakeGroups, NewMeshName)
2616         return Mesh( self.smeshpyD, self.geompyD, mesh )
2617
2618     ## Finds groups of ajacent nodes within Tolerance.
2619     #  @param Tolerance the value of tolerance
2620     #  @return the list of groups of nodes
2621     #  @ingroup l2_modif_trsf
2622     def FindCoincidentNodes (self, Tolerance):
2623         return self.editor.FindCoincidentNodes(Tolerance)
2624
2625     ## Finds groups of ajacent nodes within Tolerance.
2626     #  @param Tolerance the value of tolerance
2627     #  @param SubMeshOrGroup SubMesh or Group
2628     #  @return the list of groups of nodes
2629     #  @ingroup l2_modif_trsf
2630     def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2631         return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2632
2633     ## Merges nodes
2634     #  @param GroupsOfNodes the list of groups of nodes
2635     #  @ingroup l2_modif_trsf
2636     def MergeNodes (self, GroupsOfNodes):
2637         self.editor.MergeNodes(GroupsOfNodes)
2638
2639     ## Finds the elements built on the same nodes.
2640     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2641     #  @return a list of groups of equal elements
2642     #  @ingroup l2_modif_trsf
2643     def FindEqualElements (self, MeshOrSubMeshOrGroup):
2644         return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2645
2646     ## Merges elements in each given group.
2647     #  @param GroupsOfElementsID groups of elements for merging
2648     #  @ingroup l2_modif_trsf
2649     def MergeElements(self, GroupsOfElementsID):
2650         self.editor.MergeElements(GroupsOfElementsID)
2651
2652     ## Leaves one element and removes all other elements built on the same nodes.
2653     #  @ingroup l2_modif_trsf
2654     def MergeEqualElements(self):
2655         self.editor.MergeEqualElements()
2656
2657     ## Sews free borders
2658     #  @return SMESH::Sew_Error
2659     #  @ingroup l2_modif_trsf
2660     def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2661                         FirstNodeID2, SecondNodeID2, LastNodeID2,
2662                         CreatePolygons, CreatePolyedrs):
2663         return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2664                                           FirstNodeID2, SecondNodeID2, LastNodeID2,
2665                                           CreatePolygons, CreatePolyedrs)
2666
2667     ## Sews conform free borders
2668     #  @return SMESH::Sew_Error
2669     #  @ingroup l2_modif_trsf
2670     def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2671                                FirstNodeID2, SecondNodeID2):
2672         return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2673                                                  FirstNodeID2, SecondNodeID2)
2674
2675     ## Sews border to side
2676     #  @return SMESH::Sew_Error
2677     #  @ingroup l2_modif_trsf
2678     def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2679                          FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2680         return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2681                                            FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2682
2683     ## Sews two sides of a mesh. The nodes belonging to Side1 are
2684     #  merged with the nodes of elements of Side2.
2685     #  The number of elements in theSide1 and in theSide2 must be
2686     #  equal and they should have similar nodal connectivity.
2687     #  The nodes to merge should belong to side borders and
2688     #  the first node should be linked to the second.
2689     #  @return SMESH::Sew_Error
2690     #  @ingroup l2_modif_trsf
2691     def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2692                          NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2693                          NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2694         return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2695                                            NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2696                                            NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2697
2698     ## Sets new nodes for the given element.
2699     #  @param ide the element id
2700     #  @param newIDs nodes ids
2701     #  @return If the number of nodes does not correspond to the type of element - returns false
2702     #  @ingroup l2_modif_edit
2703     def ChangeElemNodes(self, ide, newIDs):
2704         return self.editor.ChangeElemNodes(ide, newIDs)
2705
2706     ## If during the last operation of MeshEditor some nodes were
2707     #  created, this method returns the list of their IDs, \n
2708     #  if new nodes were not created - returns empty list
2709     #  @return the list of integer values (can be empty)
2710     #  @ingroup l1_auxiliary
2711     def GetLastCreatedNodes(self):
2712         return self.editor.GetLastCreatedNodes()
2713
2714     ## If during the last operation of MeshEditor some elements were
2715     #  created this method returns the list of their IDs, \n
2716     #  if new elements were not created - returns empty list
2717     #  @return the list of integer values (can be empty)
2718     #  @ingroup l1_auxiliary
2719     def GetLastCreatedElems(self):
2720         return self.editor.GetLastCreatedElems()
2721
2722 ## The mother class to define algorithm, it is not recommended to use it directly.
2723 #
2724 #  More details.
2725 #  @ingroup l2_algorithms
2726 class Mesh_Algorithm:
2727     #  @class Mesh_Algorithm
2728     #  @brief Class Mesh_Algorithm
2729
2730     #def __init__(self,smesh):
2731     #    self.smesh=smesh
2732     def __init__(self):
2733         self.mesh = None
2734         self.geom = None
2735         self.subm = None
2736         self.algo = None
2737
2738     ## Finds a hypothesis in the study by its type name and parameters.
2739     #  Finds only the hypotheses created in smeshpyD engine.
2740     #  @return SMESH.SMESH_Hypothesis
2741     def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
2742         study = smeshpyD.GetCurrentStudy()
2743         #to do: find component by smeshpyD object, not by its data type
2744         scomp = study.FindComponent(smeshpyD.ComponentDataType())
2745         if scomp is not None:
2746             res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
2747             # Check if the root label of the hypotheses exists
2748             if res and hypRoot is not None:
2749                 iter = study.NewChildIterator(hypRoot)
2750                 # Check all published hypotheses
2751                 while iter.More():
2752                     hypo_so_i = iter.Value()
2753                     attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
2754                     if attr is not None:
2755                         anIOR = attr.Value()
2756                         hypo_o_i = salome.orb.string_to_object(anIOR)
2757                         if hypo_o_i is not None:
2758                             # Check if this is a hypothesis
2759                             hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
2760                             if hypo_i is not None:
2761                                 # Check if the hypothesis belongs to current engine
2762                                 if smeshpyD.GetObjectId(hypo_i) > 0:
2763                                     # Check if this is the required hypothesis
2764                                     if hypo_i.GetName() == hypname:
2765                                         # Check arguments
2766                                         if CompareMethod(hypo_i, args):
2767                                             # found!!!
2768                                             return hypo_i
2769                                         pass
2770                                     pass
2771                                 pass
2772                             pass
2773                         pass
2774                     iter.Next()
2775                     pass
2776                 pass
2777             pass
2778         return None
2779
2780     ## Finds the algorithm in the study by its type name.
2781     #  Finds only the algorithms, which have been created in smeshpyD engine.
2782     #  @return SMESH.SMESH_Algo
2783     def FindAlgorithm (self, algoname, smeshpyD):
2784         study = smeshpyD.GetCurrentStudy()
2785         #to do: find component by smeshpyD object, not by its data type
2786         scomp = study.FindComponent(smeshpyD.ComponentDataType())
2787         if scomp is not None:
2788             res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
2789             # Check if the root label of the algorithms exists
2790             if res and hypRoot is not None:
2791                 iter = study.NewChildIterator(hypRoot)
2792                 # Check all published algorithms
2793                 while iter.More():
2794                     algo_so_i = iter.Value()
2795                     attr = algo_so_i.FindAttribute("AttributeIOR")[1]
2796                     if attr is not None:
2797                         anIOR = attr.Value()
2798                         algo_o_i = salome.orb.string_to_object(anIOR)
2799                         if algo_o_i is not None:
2800                             # Check if this is an algorithm
2801                             algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
2802                             if algo_i is not None:
2803                                 # Checks if the algorithm belongs to the current engine
2804                                 if smeshpyD.GetObjectId(algo_i) > 0:
2805                                     # Check if this is the required algorithm
2806                                     if algo_i.GetName() == algoname:
2807                                         # found!!!
2808                                         return algo_i
2809                                     pass
2810                                 pass
2811                             pass
2812                         pass
2813                     iter.Next()
2814                     pass
2815                 pass
2816             pass
2817         return None
2818
2819     ## If the algorithm is global, returns 0; \n
2820     #  else returns the submesh associated to this algorithm.
2821     def GetSubMesh(self):
2822         return self.subm
2823
2824     ## Returns the wrapped mesher.
2825     def GetAlgorithm(self):
2826         return self.algo
2827
2828     ## Gets the list of hypothesis that can be used with this algorithm
2829     def GetCompatibleHypothesis(self):
2830         mylist = []
2831         if self.algo:
2832             mylist = self.algo.GetCompatibleHypothesis()
2833         return mylist
2834
2835     ## Gets the name of the algorithm
2836     def GetName(self):
2837         GetName(self.algo)
2838
2839     ## Sets the name to the algorithm
2840     def SetName(self, name):
2841         SetName(self.algo, name)
2842
2843     ## Gets the id of the algorithm
2844     def GetId(self):
2845         return self.algo.GetId()
2846
2847     ## Private method.
2848     def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
2849         if geom is None:
2850             raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
2851         algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
2852         if algo is None:
2853             algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
2854             pass
2855         self.Assign(algo, mesh, geom)
2856         return self.algo
2857
2858     ## Private method
2859     def Assign(self, algo, mesh, geom):
2860         if geom is None:
2861             raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
2862         self.mesh = mesh
2863         piece = mesh.geom
2864         if not geom:
2865             self.geom = piece
2866         else:
2867             self.geom = geom
2868             name = GetName(geom)
2869             if name==NO_NAME:
2870                 name = mesh.geompyD.SubShapeName(geom, piece)
2871                 mesh.geompyD.addToStudyInFather(piece, geom, name)
2872             self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
2873
2874         self.algo = algo
2875         status = mesh.mesh.AddHypothesis(self.geom, self.algo)
2876         TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
2877
2878     def CompareHyp (self, hyp, args):
2879         print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
2880         return False
2881
2882     def CompareEqualHyp (self, hyp, args):
2883         return True
2884
2885     ## Private method
2886     def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
2887                     UseExisting=0, CompareMethod=""):
2888         hypo = None
2889         if UseExisting:
2890             if CompareMethod == "": CompareMethod = self.CompareHyp
2891             hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
2892             pass
2893         if hypo is None:
2894             hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
2895             a = ""
2896             s = "="
2897             i = 0
2898             n = len(args)
2899             while i<n:
2900                 a = a + s + str(args[i])
2901                 s = ","
2902                 i = i + 1
2903                 pass
2904             SetName(hypo, hyp + a)
2905             pass
2906         status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
2907         TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
2908         return hypo
2909
2910
2911 # Public class: Mesh_Segment
2912 # --------------------------
2913
2914 ## Class to define a segment 1D algorithm for discretization
2915 #
2916 #  More details.
2917 #  @ingroup l3_algos_basic
2918 class Mesh_Segment(Mesh_Algorithm):
2919
2920     ## Private constructor.
2921     def __init__(self, mesh, geom=0):
2922         Mesh_Algorithm.__init__(self)
2923         self.Create(mesh, geom, "Regular_1D")
2924
2925     ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
2926     #  @param l for the length of segments that cut an edge
2927     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
2928     #                    the same parameters, else (default) - creates a new one
2929     #  @param p precision, used for calculation of the number of segments.
2930     #           The precision should be a positive, meaningful value within the range [0,1].
2931     #           In general, the number of segments is calculated with the formula:
2932     #           nb = ceil((edge_length / l) - p)
2933     #           Function ceil rounds its argument to the higher integer.
2934     #           So, p=0 means rounding of (edge_length / l) to the higher integer,
2935     #               p=0.5 means rounding of (edge_length / l) to the nearest integer,
2936     #               p=1 means rounding of (edge_length / l) to the lower integer.
2937     #           Default value is 1e-07.
2938     #  @return an instance of StdMeshers_LocalLength hypothesis
2939     #  @ingroup l3_hypos_1dhyps
2940     def LocalLength(self, l, UseExisting=0, p=1e-07):
2941         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
2942                               CompareMethod=self.CompareLocalLength)
2943         hyp.SetLength(l)
2944         hyp.SetPrecision(p)
2945         return hyp
2946
2947     ## Private method
2948     ## Checks if the given "LocalLength" hypothesis has the same parameters as the given arguments
2949     def CompareLocalLength(self, hyp, args):
2950         if IsEqual(hyp.GetLength(), args[0]):
2951             return IsEqual(hyp.GetPrecision(), args[1])
2952         return False
2953
2954     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
2955     #  @param n for the number of segments that cut an edge
2956     #  @param s for the scale factor (optional)
2957     #  @param UseExisting if ==true - searches for an existing hypothesis created with
2958     #                     the same parameters, else (default) - create a new one
2959     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
2960     #  @ingroup l3_hypos_1dhyps
2961     def NumberOfSegments(self, n, s=[], UseExisting=0):
2962         if s == []:
2963             hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
2964                                   CompareMethod=self.CompareNumberOfSegments)
2965         else:
2966             hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
2967                                   CompareMethod=self.CompareNumberOfSegments)
2968             hyp.SetDistrType( 1 )
2969             hyp.SetScaleFactor(s)
2970         hyp.SetNumberOfSegments(n)
2971         return hyp
2972
2973     ## Private method
2974     ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
2975     def CompareNumberOfSegments(self, hyp, args):
2976         if hyp.GetNumberOfSegments() == args[0]:
2977             if len(args) == 1:
2978                 return True
2979             else:
2980                 if hyp.GetDistrType() == 1:
2981                     if IsEqual(hyp.GetScaleFactor(), args[1]):
2982                         return True
2983         return False
2984
2985     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
2986     #  @param start defines the length of the first segment
2987     #  @param end   defines the length of the last  segment
2988     #  @param UseExisting if ==true - searches for an existing hypothesis created with
2989     #                     the same parameters, else (default) - creates a new one
2990     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
2991     #  @ingroup l3_hypos_1dhyps
2992     def Arithmetic1D(self, start, end, UseExisting=0):
2993         hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
2994                               CompareMethod=self.CompareArithmetic1D)
2995         hyp.SetLength(start, 1)
2996         hyp.SetLength(end  , 0)
2997         return hyp
2998
2999     ## Private method
3000     ## Check if the given "Arithmetic1D" hypothesis has the same parameters as the given arguments
3001     def CompareArithmetic1D(self, hyp, args):
3002         if IsEqual(hyp.GetLength(1), args[0]):
3003             if IsEqual(hyp.GetLength(0), args[1]):
3004                 return True
3005         return False
3006
3007     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
3008     #  @param start defines the length of the first segment
3009     #  @param end   defines the length of the last  segment
3010     #  @param UseExisting if ==true - searches for an existing hypothesis created with
3011     #                     the same parameters, else (default) - creates a new one
3012     #  @return an instance of StdMeshers_StartEndLength hypothesis
3013     #  @ingroup l3_hypos_1dhyps
3014     def StartEndLength(self, start, end, UseExisting=0):
3015         hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
3016                               CompareMethod=self.CompareStartEndLength)
3017         hyp.SetLength(start, 1)
3018         hyp.SetLength(end  , 0)
3019         return hyp
3020
3021     ## Check if the given "StartEndLength" hypothesis has the same parameters as the given arguments
3022     def CompareStartEndLength(self, hyp, args):
3023         if IsEqual(hyp.GetLength(1), args[0]):
3024             if IsEqual(hyp.GetLength(0), args[1]):
3025                 return True
3026         return False
3027
3028     ## Defines "Deflection1D" hypothesis
3029     #  @param d for the deflection
3030     #  @param UseExisting if ==true - searches for an existing hypothesis created with
3031     #                     the same parameters, else (default) - create a new one
3032     #  @ingroup l3_hypos_1dhyps
3033     def Deflection1D(self, d, UseExisting=0):
3034         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
3035                               CompareMethod=self.CompareDeflection1D)
3036         hyp.SetDeflection(d)
3037         return hyp
3038
3039     ## Check if the given "Deflection1D" hypothesis has the same parameters as the given arguments
3040     def CompareDeflection1D(self, hyp, args):
3041         return IsEqual(hyp.GetDeflection(), args[0])
3042
3043     ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
3044     #  the opposite side in case of quadrangular faces
3045     #  @ingroup l3_hypos_additi
3046     def Propagation(self):
3047         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3048
3049     ## Defines "AutomaticLength" hypothesis
3050     #  @param fineness for the fineness [0-1]
3051     #  @param UseExisting if ==true - searches for an existing hypothesis created with the
3052     #                     same parameters, else (default) - create a new one
3053     #  @ingroup l3_hypos_1dhyps
3054     def AutomaticLength(self, fineness=0, UseExisting=0):
3055         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
3056                               CompareMethod=self.CompareAutomaticLength)
3057         hyp.SetFineness( fineness )
3058         return hyp
3059
3060     ## Checks if the given "AutomaticLength" hypothesis has the same parameters as the given arguments
3061     def CompareAutomaticLength(self, hyp, args):
3062         return IsEqual(hyp.GetFineness(), args[0])
3063
3064     ## Defines "SegmentLengthAroundVertex" hypothesis
3065     #  @param length for the segment length
3066     #  @param vertex for the length localization: the vertex index [0,1] | vertex object.
3067     #         Any other integer value means that the hypothesis will be set on the
3068     #         whole 1D shape, where Mesh_Segment algorithm is assigned.
3069     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
3070     #                   the same parameters, else (default) - creates a new one
3071     #  @ingroup l3_algos_segmarv
3072     def LengthNearVertex(self, length, vertex=0, UseExisting=0):
3073         import types
3074         store_geom = self.geom
3075         if type(vertex) is types.IntType:
3076             if vertex == 0 or vertex == 1:
3077                 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
3078                 self.geom = vertex
3079                 pass
3080             pass
3081         else:
3082             self.geom = vertex
3083             pass
3084         ### 0D algorithm
3085         if self.geom is None:
3086             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
3087         name = GetName(self.geom)
3088         if name == NO_NAME:
3089             piece = self.mesh.geom
3090             name = self.mesh.geompyD.SubShapeName(self.geom, piece)
3091             self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
3092         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
3093         if algo is None:
3094             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
3095             pass
3096         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
3097         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
3098         ###
3099         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
3100                               CompareMethod=self.CompareLengthNearVertex)
3101         self.geom = store_geom
3102         hyp.SetLength( length )
3103         return hyp
3104
3105     ## Checks if the given "LengthNearVertex" hypothesis has the same parameters as the given arguments
3106     #  @ingroup l3_algos_segmarv
3107     def CompareLengthNearVertex(self, hyp, args):
3108         return IsEqual(hyp.GetLength(), args[0])
3109
3110     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
3111     #  If the 2D mesher sees that all boundary edges are quadratic,
3112     #  it generates quadratic faces, else it generates linear faces using
3113     #  medium nodes as if they are vertices.
3114     #  The 3D mesher generates quadratic volumes only if all boundary faces
3115     #  are quadratic, else it fails.
3116     #
3117     #  @ingroup l3_hypos_additi
3118     def QuadraticMesh(self):
3119         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3120         return hyp
3121
3122 # Public class: Mesh_CompositeSegment
3123 # --------------------------
3124
3125 ## Defines a segment 1D algorithm for discretization
3126 #
3127 #  @ingroup l3_algos_basic
3128 class Mesh_CompositeSegment(Mesh_Segment):
3129
3130     ## Private constructor.
3131     def __init__(self, mesh, geom=0):
3132         self.Create(mesh, geom, "CompositeSegment_1D")
3133
3134
3135 # Public class: Mesh_Segment_Python
3136 # ---------------------------------
3137
3138 ## Defines a segment 1D algorithm for discretization with python function
3139 #
3140 #  @ingroup l3_algos_basic
3141 class Mesh_Segment_Python(Mesh_Segment):
3142
3143     ## Private constructor.
3144     def __init__(self, mesh, geom=0):
3145         import Python1dPlugin
3146         self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
3147
3148     ## Defines "PythonSplit1D" hypothesis
3149     #  @param n for the number of segments that cut an edge
3150     #  @param func for the python function that calculates the length of all segments
3151     #  @param UseExisting if ==true - searches for the existing hypothesis created with
3152     #                     the same parameters, else (default) - creates a new one
3153     #  @ingroup l3_hypos_1dhyps
3154     def PythonSplit1D(self, n, func, UseExisting=0):
3155         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
3156                               UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
3157         hyp.SetNumberOfSegments(n)
3158         hyp.SetPythonLog10RatioFunction(func)
3159         return hyp
3160
3161     ## Checks if the given "PythonSplit1D" hypothesis has the same parameters as the given arguments
3162     def ComparePythonSplit1D(self, hyp, args):
3163         #if hyp.GetNumberOfSegments() == args[0]:
3164         #    if hyp.GetPythonLog10RatioFunction() == args[1]:
3165         #        return True
3166         return False
3167
3168 # Public class: Mesh_Triangle
3169 # ---------------------------
3170
3171 ## Defines a triangle 2D algorithm
3172 #
3173 #  @ingroup l3_algos_basic
3174 class Mesh_Triangle(Mesh_Algorithm):
3175
3176     # default values
3177     algoType = 0
3178     params = 0
3179
3180     _angleMeshS = 8
3181     _gradation  = 1.1
3182
3183     ## Private constructor.
3184     def __init__(self, mesh, algoType, geom=0):
3185         Mesh_Algorithm.__init__(self)
3186
3187         self.algoType = algoType
3188         if algoType == MEFISTO:
3189             self.Create(mesh, geom, "MEFISTO_2D")
3190             pass
3191         elif algoType == BLSURF:
3192             import BLSURFPlugin
3193             self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
3194             #self.SetPhysicalMesh() - PAL19680
3195         elif algoType == NETGEN:
3196             if noNETGENPlugin:
3197                 print "Warning: NETGENPlugin module unavailable"
3198                 pass
3199             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3200             pass
3201         elif algoType == NETGEN_2D:
3202             if noNETGENPlugin:
3203                 print "Warning: NETGENPlugin module unavailable"
3204                 pass
3205             self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
3206             pass
3207
3208     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
3209     #  @param area for the maximum area of each triangle
3210     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
3211     #                     same parameters, else (default) - creates a new one
3212     #
3213     #  Only for algoType == MEFISTO || NETGEN_2D
3214     #  @ingroup l3_hypos_2dhyps
3215     def MaxElementArea(self, area, UseExisting=0):
3216         if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
3217             hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
3218                                   CompareMethod=self.CompareMaxElementArea)
3219         elif self.algoType == NETGEN:
3220             hyp = self.Parameters(SIMPLE)
3221         hyp.SetMaxElementArea(area)
3222         return hyp
3223
3224     ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
3225     def CompareMaxElementArea(self, hyp, args):
3226         return IsEqual(hyp.GetMaxElementArea(), args[0])
3227
3228     ## Defines "LengthFromEdges" hypothesis to build triangles
3229     #  based on the length of the edges taken from the wire
3230     #
3231     #  Only for algoType == MEFISTO || NETGEN_2D
3232     #  @ingroup l3_hypos_2dhyps
3233     def LengthFromEdges(self):
3234         if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
3235             hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3236             return hyp
3237         elif self.algoType == NETGEN:
3238             hyp = self.Parameters(SIMPLE)
3239             hyp.LengthFromEdges()
3240             return hyp
3241
3242     ## Sets a way to define size of mesh elements to generate.
3243     #  @param thePhysicalMesh is: DefaultSize or Custom.
3244     #  @ingroup l3_hypos_blsurf
3245     def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
3246         # Parameter of BLSURF algo
3247         self.Parameters().SetPhysicalMesh(thePhysicalMesh)
3248
3249     ## Sets size of mesh elements to generate.
3250     #  @ingroup l3_hypos_blsurf
3251     def SetPhySize(self, theVal):
3252         # Parameter of BLSURF algo
3253         self.Parameters().SetPhySize(theVal)
3254
3255     ## Sets lower boundary of mesh element size (PhySize).
3256     #  @ingroup l3_hypos_blsurf
3257     def SetPhyMin(self, theVal=-1):
3258         #  Parameter of BLSURF algo
3259         self.Parameters().SetPhyMin(theVal)
3260
3261     ## Sets upper boundary of mesh element size (PhySize).
3262     #  @ingroup l3_hypos_blsurf
3263     def SetPhyMax(self, theVal=-1):
3264         #  Parameter of BLSURF algo
3265         self.Parameters().SetPhyMax(theVal)
3266
3267     ## Sets a way to define maximum angular deflection of mesh from CAD model.
3268     #  @param theGeometricMesh is: DefaultGeom or Custom
3269     #  @ingroup l3_hypos_blsurf
3270     def SetGeometricMesh(self, theGeometricMesh=0):
3271         #  Parameter of BLSURF algo
3272         if self.Parameters().GetPhysicalMesh() == 0: theGeometricMesh = 1
3273         self.params.SetGeometricMesh(theGeometricMesh)
3274
3275     ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
3276     #  @ingroup l3_hypos_blsurf
3277     def SetAngleMeshS(self, theVal=_angleMeshS):
3278         #  Parameter of BLSURF algo
3279         if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
3280         self.params.SetAngleMeshS(theVal)
3281
3282     ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
3283     #  @ingroup l3_hypos_blsurf
3284     def SetAngleMeshC(self, theVal=_angleMeshS):
3285         #  Parameter of BLSURF algo
3286         if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
3287         self.params.SetAngleMeshC(theVal)
3288
3289     ## Sets lower boundary of mesh element size computed to respect angular deflection.
3290     #  @ingroup l3_hypos_blsurf
3291     def SetGeoMin(self, theVal=-1):
3292         #  Parameter of BLSURF algo
3293         self.Parameters().SetGeoMin(theVal)
3294
3295     ## Sets upper boundary of mesh element size computed to respect angular deflection.
3296     #  @ingroup l3_hypos_blsurf
3297     def SetGeoMax(self, theVal=-1):
3298         #  Parameter of BLSURF algo
3299         self.Parameters().SetGeoMax(theVal)
3300
3301     ## Sets maximal allowed ratio between the lengths of two adjacent edges.
3302     #  @ingroup l3_hypos_blsurf
3303     def SetGradation(self, theVal=_gradation):
3304         #  Parameter of BLSURF algo
3305         if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
3306         self.params.SetGradation(theVal)
3307
3308     ## Sets topology usage way.
3309     # @param way defines how mesh conformity is assured <ul>
3310     # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
3311     # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model</li></ul>
3312     #  @ingroup l3_hypos_blsurf
3313     def SetTopology(self, way):
3314         #  Parameter of BLSURF algo
3315         self.Parameters().SetTopology(way)
3316
3317     ## To respect geometrical edges or not.
3318     #  @ingroup l3_hypos_blsurf
3319     def SetDecimesh(self, toIgnoreEdges=False):
3320         #  Parameter of BLSURF algo
3321         self.Parameters().SetDecimesh(toIgnoreEdges)
3322
3323     ## Sets verbosity level in the range 0 to 100.
3324     #  @ingroup l3_hypos_blsurf
3325     def SetVerbosity(self, level):
3326         #  Parameter of BLSURF algo
3327         self.Parameters().SetVerbosity(level)
3328
3329     ## Sets advanced option value.
3330     #  @ingroup l3_hypos_blsurf
3331     def SetOptionValue(self, optionName, level):
3332         #  Parameter of BLSURF algo
3333         self.Parameters().SetOptionValue(optionName,level)
3334
3335     ## Sets QuadAllowed flag.
3336     #  Only for algoType == NETGEN || NETGEN_2D || BLSURF
3337     #  @ingroup l3_hypos_netgen l3_hypos_blsurf
3338     def SetQuadAllowed(self, toAllow=True):
3339         if self.algoType == NETGEN_2D:
3340             if toAllow: # add QuadranglePreference
3341                 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3342             else:       # remove QuadranglePreference
3343                 for hyp in self.mesh.GetHypothesisList( self.geom ):
3344                     if hyp.GetName() == "QuadranglePreference":
3345                         self.mesh.RemoveHypothesis( self.geom, hyp )
3346                         pass
3347                     pass
3348                 pass
3349             return
3350         if self.Parameters():
3351             self.params.SetQuadAllowed(toAllow)
3352             return
3353
3354     ## Defines hypothesis having several parameters
3355     #
3356     #  @ingroup l3_hypos_netgen
3357     def Parameters(self, which=SOLE):
3358         if self.params:
3359             return self.params
3360         if self.algoType == NETGEN:
3361             if which == SIMPLE:
3362                 self.params = self.Hypothesis("NETGEN_SimpleParameters_2D", [],
3363                                               "libNETGENEngine.so", UseExisting=0)
3364             else:
3365                 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
3366                                               "libNETGENEngine.so", UseExisting=0)
3367             return self.params
3368         elif self.algoType == MEFISTO:
3369             print "Mefisto algo support no multi-parameter hypothesis"
3370             return None
3371         elif self.algoType == NETGEN_2D:
3372             print "NETGEN_2D_ONLY algo support no multi-parameter hypothesis"
3373             print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
3374             return None
3375         elif self.algoType == BLSURF:
3376             self.params = self.Hypothesis("BLSURF_Parameters", [],
3377                                           "libBLSURFEngine.so", UseExisting=0)
3378             return self.params
3379         else:
3380             print "Mesh_Triangle with algo type %s does not have such a parameter, check algo type"%self.algoType
3381         return None
3382
3383     ## Sets MaxSize
3384     #
3385     #  Only for algoType == NETGEN
3386     #  @ingroup l3_hypos_netgen
3387     def SetMaxSize(self, theSize):
3388         if self.Parameters():
3389             self.params.SetMaxSize(theSize)
3390
3391     ## Sets SecondOrder flag
3392     #
3393     #  Only for algoType == NETGEN
3394     #  @ingroup l3_hypos_netgen
3395     def SetSecondOrder(self, theVal):
3396         if self.Parameters():
3397             self.params.SetSecondOrder(theVal)
3398
3399     ## Sets Optimize flag
3400     #
3401     #  Only for algoType == NETGEN
3402     #  @ingroup l3_hypos_netgen
3403     def SetOptimize(self, theVal):
3404         if self.Parameters():
3405             self.params.SetOptimize(theVal)
3406
3407     ## Sets Fineness
3408     #  @param theFineness is:
3409     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3410     #
3411     #  Only for algoType == NETGEN
3412     #  @ingroup l3_hypos_netgen
3413     def SetFineness(self, theFineness):
3414         if self.Parameters():
3415             self.params.SetFineness(theFineness)
3416
3417     ## Sets GrowthRate
3418     #
3419     #  Only for algoType == NETGEN
3420     #  @ingroup l3_hypos_netgen
3421     def SetGrowthRate(self, theRate):
3422         if self.Parameters():
3423             self.params.SetGrowthRate(theRate)
3424
3425     ## Sets NbSegPerEdge
3426     #
3427     #  Only for algoType == NETGEN
3428     #  @ingroup l3_hypos_netgen
3429     def SetNbSegPerEdge(self, theVal):
3430         if self.Parameters():
3431             self.params.SetNbSegPerEdge(theVal)
3432
3433     ## Sets NbSegPerRadius
3434     #
3435     #  Only for algoType == NETGEN
3436     #  @ingroup l3_hypos_netgen
3437     def SetNbSegPerRadius(self, theVal):
3438         if self.Parameters():
3439             self.params.SetNbSegPerRadius(theVal)
3440
3441     ## Sets number of segments overriding value set by SetLocalLength()
3442     #
3443     #  Only for algoType == NETGEN
3444     #  @ingroup l3_hypos_netgen
3445     def SetNumberOfSegments(self, theVal):
3446         self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
3447
3448     ## Sets number of segments overriding value set by SetNumberOfSegments()
3449     #
3450     #  Only for algoType == NETGEN
3451     #  @ingroup l3_hypos_netgen
3452     def SetLocalLength(self, theVal):
3453         self.Parameters(SIMPLE).SetLocalLength(theVal)
3454
3455     pass
3456
3457
3458 # Public class: Mesh_Quadrangle
3459 # -----------------------------
3460
3461 ## Defines a quadrangle 2D algorithm
3462 #
3463 #  @ingroup l3_algos_basic
3464 class Mesh_Quadrangle(Mesh_Algorithm):
3465
3466     ## Private constructor.
3467     def __init__(self, mesh, geom=0):
3468         Mesh_Algorithm.__init__(self)
3469         self.Create(mesh, geom, "Quadrangle_2D")
3470
3471     ## Defines "QuadranglePreference" hypothesis, forcing construction
3472     #  of quadrangles if the number of nodes on the opposite edges is not the same
3473     #  while the total number of nodes on edges is even
3474     #
3475     #  @ingroup l3_hypos_additi
3476     def QuadranglePreference(self):
3477         hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
3478                               CompareMethod=self.CompareEqualHyp)
3479         return hyp
3480
3481     ## Defines "TrianglePreference" hypothesis, forcing construction
3482     #  of triangles in the refinement area if the number of nodes
3483     #  on the opposite edges is not the same
3484     #
3485     #  @ingroup l3_hypos_additi
3486     def TrianglePreference(self):
3487         hyp = self.Hypothesis("TrianglePreference", UseExisting=1,
3488                               CompareMethod=self.CompareEqualHyp)
3489         return hyp
3490
3491 # Public class: Mesh_Tetrahedron
3492 # ------------------------------
3493
3494 ## Defines a tetrahedron 3D algorithm
3495 #
3496 #  @ingroup l3_algos_basic
3497 class Mesh_Tetrahedron(Mesh_Algorithm):
3498
3499     params = 0
3500     algoType = 0
3501
3502     ## Private constructor.
3503     def __init__(self, mesh, algoType, geom=0):
3504         Mesh_Algorithm.__init__(self)
3505
3506         if algoType == NETGEN:
3507             self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
3508             pass
3509
3510         elif algoType == FULL_NETGEN:
3511             if noNETGENPlugin:
3512                 print "Warning: NETGENPlugin module has not been imported."
3513             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3514             pass
3515
3516         elif algoType == GHS3D:
3517             import GHS3DPlugin
3518             self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
3519             pass
3520
3521         elif algoType == GHS3DPRL:
3522             import GHS3DPRLPlugin
3523             self.Create(mesh, geom, "GHS3DPRL_3D" , "libGHS3DPRLEngine.so")
3524             pass
3525
3526         self.algoType = algoType
3527
3528     ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
3529     #  @param vol for the maximum volume of each tetrahedron
3530     #  @param UseExisting if ==true - searches for the existing hypothesis created with
3531     #                   the same parameters, else (default) - creates a new one
3532     #  @ingroup l3_hypos_maxvol
3533     def MaxElementVolume(self, vol, UseExisting=0):
3534         if self.algoType == NETGEN:
3535             hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
3536                                   CompareMethod=self.CompareMaxElementVolume)
3537             hyp.SetMaxElementVolume(vol)
3538             return hyp
3539         elif self.algoType == FULL_NETGEN:
3540             self.Parameters(SIMPLE).SetMaxElementVolume(vol)
3541         return None
3542
3543     ## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
3544     def CompareMaxElementVolume(self, hyp, args):
3545         return IsEqual(hyp.GetMaxElementVolume(), args[0])
3546
3547     ## Defines hypothesis having several parameters
3548     #
3549     #  @ingroup l3_hypos_netgen
3550     def Parameters(self, which=SOLE):
3551         if self.params:
3552             return self.params
3553
3554         if self.algoType == FULL_NETGEN:
3555             if which == SIMPLE:
3556                 self.params = self.Hypothesis("NETGEN_SimpleParameters_3D", [],
3557                                               "libNETGENEngine.so", UseExisting=0)
3558             else:
3559                 self.params = self.Hypothesis("NETGEN_Parameters", [],
3560                                               "libNETGENEngine.so", UseExisting=0)
3561             return self.params
3562
3563         if self.algoType == GHS3D:
3564             self.params = self.Hypothesis("GHS3D_Parameters", [],
3565                                           "libGHS3DEngine.so", UseExisting=0)
3566             return self.params
3567
3568         if self.algoType == GHS3DPRL:
3569             self.params = self.Hypothesis("GHS3DPRL_Parameters", [],
3570                                           "libGHS3DPRLEngine.so", UseExisting=0)
3571             return self.params
3572
3573         print "Algo supports no multi-parameter hypothesis"
3574         return None
3575
3576     ## Sets MaxSize
3577     #  Parameter of FULL_NETGEN
3578     #  @ingroup l3_hypos_netgen
3579     def SetMaxSize(self, theSize):
3580         self.Parameters().SetMaxSize(theSize)
3581
3582     ## Sets SecondOrder flag
3583     #  Parameter of FULL_NETGEN
3584     #  @ingroup l3_hypos_netgen
3585     def SetSecondOrder(self, theVal):
3586         self.Parameters().SetSecondOrder(theVal)
3587
3588     ## Sets Optimize flag
3589     #  Parameter of FULL_NETGEN
3590     #  @ingroup l3_hypos_netgen
3591     def SetOptimize(self, theVal):
3592         self.Parameters().SetOptimize(theVal)
3593
3594     ## Sets Fineness
3595     #  @param theFineness is:
3596     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3597     #  Parameter of FULL_NETGEN
3598     #  @ingroup l3_hypos_netgen
3599     def SetFineness(self, theFineness):
3600         self.Parameters().SetFineness(theFineness)
3601
3602     ## Sets GrowthRate
3603     #  Parameter of FULL_NETGEN
3604     #  @ingroup l3_hypos_netgen
3605     def SetGrowthRate(self, theRate):
3606         self.Parameters().SetGrowthRate(theRate)
3607
3608     ## Sets NbSegPerEdge
3609     #  Parameter of FULL_NETGEN
3610     #  @ingroup l3_hypos_netgen
3611     def SetNbSegPerEdge(self, theVal):
3612         self.Parameters().SetNbSegPerEdge(theVal)
3613
3614     ## Sets NbSegPerRadius
3615     #  Parameter of FULL_NETGEN
3616     #  @ingroup l3_hypos_netgen
3617     def SetNbSegPerRadius(self, theVal):
3618         self.Parameters().SetNbSegPerRadius(theVal)
3619
3620     ## Sets number of segments overriding value set by SetLocalLength()
3621     #  Only for algoType == NETGEN_FULL
3622     #  @ingroup l3_hypos_netgen
3623     def SetNumberOfSegments(self, theVal):
3624         self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
3625
3626     ## Sets number of segments overriding value set by SetNumberOfSegments()
3627     #  Only for algoType == NETGEN_FULL
3628     #  @ingroup l3_hypos_netgen
3629     def SetLocalLength(self, theVal):
3630         self.Parameters(SIMPLE).SetLocalLength(theVal)
3631
3632     ## Defines "MaxElementArea" parameter of NETGEN_SimpleParameters_3D hypothesis.
3633     #  Overrides value set by LengthFromEdges()
3634     #  Only for algoType == NETGEN_FULL
3635     #  @ingroup l3_hypos_netgen
3636     def MaxElementArea(self, area):
3637         self.Parameters(SIMPLE).SetMaxElementArea(area)
3638
3639     ## Defines "LengthFromEdges" parameter of NETGEN_SimpleParameters_3D hypothesis
3640     #  Overrides value set by MaxElementArea()
3641     #  Only for algoType == NETGEN_FULL
3642     #  @ingroup l3_hypos_netgen
3643     def LengthFromEdges(self):
3644         self.Parameters(SIMPLE).LengthFromEdges()
3645
3646     ## Defines "LengthFromFaces" parameter of NETGEN_SimpleParameters_3D hypothesis
3647     #  Overrides value set by MaxElementVolume()
3648     #  Only for algoType == NETGEN_FULL
3649     #  @ingroup l3_hypos_netgen
3650     def LengthFromFaces(self):
3651         self.Parameters(SIMPLE).LengthFromFaces()
3652
3653     ## To mesh "holes" in a solid or not. Default is to mesh.
3654     #  @ingroup l3_hypos_ghs3dh
3655     def SetToMeshHoles(self, toMesh):
3656         #  Parameter of GHS3D
3657         self.Parameters().SetToMeshHoles(toMesh)
3658
3659     ## Set Optimization level:
3660     #   None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization.
3661     #  Default is Medium_Optimization
3662     #  @ingroup l3_hypos_ghs3dh
3663     def SetOptimizationLevel(self, level):
3664         #  Parameter of GHS3D
3665         self.Parameters().SetOptimizationLevel(level)
3666
3667     ## Maximal size of memory to be used by the algorithm (in Megabytes).
3668     #  @ingroup l3_hypos_ghs3dh
3669     def SetMaximumMemory(self, MB):
3670         #  Advanced parameter of GHS3D
3671         self.Parameters().SetMaximumMemory(MB)
3672
3673     ## Initial size of memory to be used by the algorithm (in Megabytes) in
3674     #  automatic memory adjustment mode.
3675     #  @ingroup l3_hypos_ghs3dh
3676     def SetInitialMemory(self, MB):
3677         #  Advanced parameter of GHS3D
3678         self.Parameters().SetInitialMemory(MB)
3679
3680     ## Path to working directory.
3681     #  @ingroup l3_hypos_ghs3dh
3682     def SetWorkingDirectory(self, path):
3683         #  Advanced parameter of GHS3D
3684         self.Parameters().SetWorkingDirectory(path)
3685
3686     ## To keep working files or remove them. Log file remains in case of errors anyway.
3687     #  @ingroup l3_hypos_ghs3dh
3688     def SetKeepFiles(self, toKeep):
3689         #  Advanced parameter of GHS3D and GHS3DPRL
3690         self.Parameters().SetKeepFiles(toKeep)
3691
3692     ## To set verbose level [0-10]. <ul>
3693     #<li> 0 - no standard output,
3694     #<li> 2 - prints the data, quality statistics of the skin and final meshes and
3695     #     indicates when the final mesh is being saved. In addition the software
3696     #     gives indication regarding the CPU time.
3697     #<li>10 - same as 2 plus the main steps in the computation, quality statistics
3698     #     histogram of the skin mesh, quality statistics histogram together with
3699     #     the characteristics of the final mesh.</ul>
3700     #  @ingroup l3_hypos_ghs3dh
3701     def SetVerboseLevel(self, level):
3702         #  Advanced parameter of GHS3D
3703         self.Parameters().SetVerboseLevel(level)
3704
3705     ## To create new nodes.
3706     #  @ingroup l3_hypos_ghs3dh
3707     def SetToCreateNewNodes(self, toCreate):
3708         #  Advanced parameter of GHS3D
3709         self.Parameters().SetToCreateNewNodes(toCreate)
3710
3711     ## To use boundary recovery version which tries to create mesh on a very poor
3712     #  quality surface mesh.
3713     #  @ingroup l3_hypos_ghs3dh
3714     def SetToUseBoundaryRecoveryVersion(self, toUse):
3715         #  Advanced parameter of GHS3D
3716         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
3717
3718     ## Sets command line option as text.
3719     #  @ingroup l3_hypos_ghs3dh
3720     def SetTextOption(self, option):
3721         #  Advanced parameter of GHS3D
3722         self.Parameters().SetTextOption(option)
3723
3724     ## Sets MED files name and path.
3725     def SetMEDName(self, value):
3726         self.Parameters().SetMEDName(value)
3727
3728     ## Sets the number of partition of the initial mesh
3729     def SetNbPart(self, value):
3730         self.Parameters().SetNbPart(value)
3731
3732     ## When big mesh, start tepal in background
3733     def SetBackground(self, value):
3734         self.Parameters().SetBackground(value)
3735
3736 # Public class: Mesh_Hexahedron
3737 # ------------------------------
3738
3739 ## Defines a hexahedron 3D algorithm
3740 #
3741 #  @ingroup l3_algos_basic
3742 class Mesh_Hexahedron(Mesh_Algorithm):
3743
3744     params = 0
3745     algoType = 0
3746
3747     ## Private constructor.
3748     def __init__(self, mesh, algoType=Hexa, geom=0):
3749         Mesh_Algorithm.__init__(self)
3750
3751         self.algoType = algoType
3752
3753         if algoType == Hexa:
3754             self.Create(mesh, geom, "Hexa_3D")
3755             pass
3756
3757         elif algoType == Hexotic:
3758             import HexoticPlugin
3759             self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
3760             pass
3761
3762     ## Defines "MinMaxQuad" hypothesis to give three hexotic parameters
3763     #  @ingroup l3_hypos_hexotic
3764     def MinMaxQuad(self, min=3, max=8, quad=True):
3765         self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
3766                                       UseExisting=0)
3767         self.params.SetHexesMinLevel(min)
3768         self.params.SetHexesMaxLevel(max)
3769         self.params.SetHexoticQuadrangles(quad)
3770         return self.params
3771
3772 # Deprecated, only for compatibility!
3773 # Public class: Mesh_Netgen
3774 # ------------------------------
3775
3776 ## Defines a NETGEN-based 2D or 3D algorithm
3777 #  that needs no discrete boundary (i.e. independent)
3778 #
3779 #  This class is deprecated, only for compatibility!
3780 #
3781 #  More details.
3782 #  @ingroup l3_algos_basic
3783 class Mesh_Netgen(Mesh_Algorithm):
3784
3785     is3D = 0
3786
3787     ## Private constructor.
3788     def __init__(self, mesh, is3D, geom=0):
3789         Mesh_Algorithm.__init__(self)
3790
3791         if noNETGENPlugin:
3792             print "Warning: NETGENPlugin module has not been imported."
3793
3794         self.is3D = is3D
3795         if is3D:
3796             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3797             pass
3798
3799         else:
3800             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3801             pass
3802
3803     ## Defines the hypothesis containing parameters of the algorithm
3804     def Parameters(self):
3805         if self.is3D:
3806             hyp = self.Hypothesis("NETGEN_Parameters", [],
3807                                   "libNETGENEngine.so", UseExisting=0)
3808         else:
3809             hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
3810                                   "libNETGENEngine.so", UseExisting=0)
3811         return hyp
3812
3813 # Public class: Mesh_Projection1D
3814 # ------------------------------
3815
3816 ## Defines a projection 1D algorithm
3817 #  @ingroup l3_algos_proj
3818 #
3819 class Mesh_Projection1D(Mesh_Algorithm):
3820
3821     ## Private constructor.
3822     def __init__(self, mesh, geom=0):
3823         Mesh_Algorithm.__init__(self)
3824         self.Create(mesh, geom, "Projection_1D")
3825
3826     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
3827     #  a mesh pattern is taken, and, optionally, the association of vertices
3828     #  between the source edge and a target edge (to which a hypothesis is assigned)
3829     #  @param edge from which nodes distribution is taken
3830     #  @param mesh from which nodes distribution is taken (optional)
3831     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
3832     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
3833     #  to associate with \a srcV (optional)
3834     #  @param UseExisting if ==true - searches for the existing hypothesis created with
3835     #                     the same parameters, else (default) - creates a new one
3836     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
3837         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
3838                               UseExisting=0)
3839                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
3840         hyp.SetSourceEdge( edge )
3841         if not mesh is None and isinstance(mesh, Mesh):
3842             mesh = mesh.GetMesh()
3843         hyp.SetSourceMesh( mesh )
3844         hyp.SetVertexAssociation( srcV, tgtV )
3845         return hyp
3846
3847     ## Checks if the given "SourceEdge" hypothesis has the same parameters as the given arguments
3848     #def CompareSourceEdge(self, hyp, args):
3849     #    # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
3850     #    return False
3851
3852
3853 # Public class: Mesh_Projection2D
3854 # ------------------------------
3855
3856 ## Defines a projection 2D algorithm
3857 #  @ingroup l3_algos_proj
3858 #
3859 class Mesh_Projection2D(Mesh_Algorithm):
3860
3861     ## Private constructor.
3862     def __init__(self, mesh, geom=0):
3863         Mesh_Algorithm.__init__(self)
3864         self.Create(mesh, geom, "Projection_2D")
3865
3866     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
3867     #  a mesh pattern is taken, and, optionally, the association of vertices
3868     #  between the source face and the target face (to which a hypothesis is assigned)
3869     #  @param face from which the mesh pattern is taken
3870     #  @param mesh from which the mesh pattern is taken (optional)
3871     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
3872     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
3873     #               to associate with \a srcV1 (optional)
3874     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
3875     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
3876     #               to associate with \a srcV2 (optional)
3877     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
3878     #                     the same parameters, else (default) - forces the creation a new one
3879     #
3880     #  Note: all association vertices must belong to one edge of a face
3881     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
3882                    srcV2=None, tgtV2=None, UseExisting=0):
3883         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
3884                               UseExisting=0)
3885                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
3886         hyp.SetSourceFace( face )
3887         if not mesh is None and isinstance(mesh, Mesh):
3888             mesh = mesh.GetMesh()
3889         hyp.SetSourceMesh( mesh )
3890         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3891         return hyp
3892
3893     ## Checks if the given "SourceFace" hypothesis has the same parameters as the given arguments
3894     #def CompareSourceFace(self, hyp, args):
3895     #    # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
3896     #    return False
3897
3898 # Public class: Mesh_Projection3D
3899 # ------------------------------
3900
3901 ## Defines a projection 3D algorithm
3902 #  @ingroup l3_algos_proj
3903 #
3904 class Mesh_Projection3D(Mesh_Algorithm):
3905
3906     ## Private constructor.
3907     def __init__(self, mesh, geom=0):
3908         Mesh_Algorithm.__init__(self)
3909         self.Create(mesh, geom, "Projection_3D")
3910
3911     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
3912     #  the mesh pattern is taken, and, optionally, the  association of vertices
3913     #  between the source and the target solid  (to which a hipothesis is assigned)
3914     #  @param solid from where the mesh pattern is taken
3915     #  @param mesh from where the mesh pattern is taken (optional)
3916     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
3917     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
3918     #  to associate with \a srcV1 (optional)
3919     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
3920     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
3921     #  to associate with \a srcV2 (optional)
3922     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
3923     #                     the same parameters, else (default) - creates a new one
3924     #
3925     #  Note: association vertices must belong to one edge of a solid
3926     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
3927                       srcV2=0, tgtV2=0, UseExisting=0):
3928         hyp = self.Hypothesis("ProjectionSource3D",
3929                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
3930                               UseExisting=0)
3931                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
3932         hyp.SetSource3DShape( solid )
3933         if not mesh is None and isinstance(mesh, Mesh):
3934             mesh = mesh.GetMesh()
3935         hyp.SetSourceMesh( mesh )
3936         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3937         return hyp
3938
3939     ## Checks if the given "SourceShape3D" hypothesis has the same parameters as given arguments
3940     #def CompareSourceShape3D(self, hyp, args):
3941     #    # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
3942     #    return False
3943
3944
3945 # Public class: Mesh_Prism
3946 # ------------------------
3947
3948 ## Defines a 3D extrusion algorithm
3949 #  @ingroup l3_algos_3dextr
3950 #
3951 class Mesh_Prism3D(Mesh_Algorithm):
3952
3953     ## Private constructor.
3954     def __init__(self, mesh, geom=0):
3955         Mesh_Algorithm.__init__(self)
3956         self.Create(mesh, geom, "Prism_3D")
3957
3958 # Public class: Mesh_RadialPrism
3959 # -------------------------------
3960
3961 ## Defines a Radial Prism 3D algorithm
3962 #  @ingroup l3_algos_radialp
3963 #
3964 class Mesh_RadialPrism3D(Mesh_Algorithm):
3965
3966     ## Private constructor.
3967     def __init__(self, mesh, geom=0):
3968         Mesh_Algorithm.__init__(self)
3969         self.Create(mesh, geom, "RadialPrism_3D")
3970
3971         self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
3972         self.nbLayers = None
3973
3974     ## Return 3D hypothesis holding the 1D one
3975     def Get3DHypothesis(self):
3976         return self.distribHyp
3977
3978     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
3979     #  hypothesis. Returns the created hypothesis
3980     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
3981         #print "OwnHypothesis",hypType
3982         if not self.nbLayers is None:
3983             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
3984             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
3985         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
3986         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
3987         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
3988         self.distribHyp.SetLayerDistribution( hyp )
3989         return hyp
3990
3991     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
3992     #  prisms to build between the inner and outer shells
3993     #  @param n number of layers
3994     #  @param UseExisting if ==true - searches for the existing hypothesis created with
3995     #                     the same parameters, else (default) - creates a new one
3996     def NumberOfLayers(self, n, UseExisting=0):
3997         self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
3998         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
3999                                         CompareMethod=self.CompareNumberOfLayers)
4000         self.nbLayers.SetNumberOfLayers( n )
4001         return self.nbLayers
4002
4003     ## Checks if the given "NumberOfLayers" hypothesis has the same parameters as the given arguments
4004     def CompareNumberOfLayers(self, hyp, args):
4005         return IsEqual(hyp.GetNumberOfLayers(), args[0])
4006
4007     ## Defines "LocalLength" hypothesis, specifying the segment length
4008     #  to build between the inner and the outer shells
4009     #  @param l the length of segments
4010     #  @param p the precision of rounding
4011     def LocalLength(self, l, p=1e-07):
4012         hyp = self.OwnHypothesis("LocalLength", [l,p])
4013         hyp.SetLength(l)
4014         hyp.SetPrecision(p)
4015         return hyp
4016
4017     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
4018     #  prisms to build between the inner and the outer shells.
4019     #  @param n the number of layers
4020     #  @param s the scale factor (optional)
4021     def NumberOfSegments(self, n, s=[]):
4022         if s == []:
4023             hyp = self.OwnHypothesis("NumberOfSegments", [n])
4024         else:
4025             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
4026             hyp.SetDistrType( 1 )
4027             hyp.SetScaleFactor(s)
4028         hyp.SetNumberOfSegments(n)
4029         return hyp
4030
4031     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
4032     #  to build between the inner and the outer shells with a length that changes in arithmetic progression
4033     #  @param start  the length of the first segment
4034     #  @param end    the length of the last  segment
4035     def Arithmetic1D(self, start, end ):
4036         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
4037         hyp.SetLength(start, 1)
4038         hyp.SetLength(end  , 0)
4039         return hyp
4040
4041     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
4042     #  to build between the inner and the outer shells as geometric length increasing
4043     #  @param start for the length of the first segment
4044     #  @param end   for the length of the last  segment
4045     def StartEndLength(self, start, end):
4046         hyp = self.OwnHypothesis("StartEndLength", [start, end])
4047         hyp.SetLength(start, 1)
4048         hyp.SetLength(end  , 0)
4049         return hyp
4050
4051     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
4052     #  to build between the inner and outer shells
4053     #  @param fineness defines the quality of the mesh within the range [0-1]
4054     def AutomaticLength(self, fineness=0):
4055         hyp = self.OwnHypothesis("AutomaticLength")
4056         hyp.SetFineness( fineness )
4057         return hyp
4058
4059 # Private class: Mesh_UseExisting
4060 # -------------------------------
4061 class Mesh_UseExisting(Mesh_Algorithm):
4062
4063     def __init__(self, dim, mesh, geom=0):
4064         if dim == 1:
4065             self.Create(mesh, geom, "UseExisting_1D")
4066         else:
4067             self.Create(mesh, geom, "UseExisting_2D")