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