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