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