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