Salome HOME
PAL13330( When mesh generation does not success, trace where )
[modules/smesh.git] / src / SMESH_SWIG / smesh.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 import salome
30 import geompy
31
32 import SMESH
33 from   SMESH import *
34
35 import StdMeshers
36
37 import SALOME
38
39 # import NETGENPlugin module if possible
40 noNETGENPlugin = 0
41 try:
42     import NETGENPlugin
43 except ImportError:
44     noNETGENPlugin = 1
45     pass
46     
47 # Types of algo
48 REGULAR    = 1
49 PYTHON     = 2
50 COMPOSITE  = 3
51
52 MEFISTO = 3
53 NETGEN  = 4
54 GHS3D   = 5
55 FULL_NETGEN = 6
56
57 # MirrorType enumeration
58 POINT = SMESH_MeshEditor.POINT
59 AXIS =  SMESH_MeshEditor.AXIS 
60 PLANE = SMESH_MeshEditor.PLANE
61
62 # Smooth_Method enumeration
63 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
64 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
65
66 # Fineness enumeration(for NETGEN)
67 VeryCoarse = 0
68 Coarse = 1
69 Moderate = 2
70 Fine = 3
71 VeryFine = 4
72 Custom = 5
73
74
75 NO_NAME = "NoName"
76
77
78 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
79 smesh.SetCurrentStudy(salome.myStudy)
80
81 # Global functions
82
83 ## Gets object name
84 def GetName(obj):
85     ior  = salome.orb.object_to_string(obj)
86     sobj = salome.myStudy.FindObjectIOR(ior)
87     if sobj is None:
88         return NO_NAME
89     else:
90         attr = sobj.FindAttribute("AttributeName")[1]
91         return attr.Value()
92
93 ## Sets name to object
94 def SetName(obj, name):
95     ior  = salome.orb.object_to_string(obj)
96     sobj = salome.myStudy.FindObjectIOR(ior)
97     if not sobj is None:
98         attr = sobj.FindAttribute("AttributeName")[1]
99         attr.SetValue(name)
100         
101 ## Returns long value from enumeration
102 #  Uses for SMESH.FunctorType enumeration
103 def EnumToLong(theItem):
104     return theItem._v
105
106 ## Get PointStruct from vertex
107 #  @param theVertex is GEOM object(vertex)
108 #  @return SMESH.PointStruct
109 def GetPointStruct(theVertex):
110     [x, y, z] = geompy.PointCoordinates(theVertex)
111     return PointStruct(x,y,z)
112
113 ## Get DirStruct from vector
114 #  @param theVector is GEOM object(vector)
115 #  @return SMESH.DirStruct
116 def GetDirStruct(theVector):
117     vertices = geompy.SubShapeAll( theVector, geompy.ShapeType["VERTEX"] )
118     if(len(vertices) != 2):
119         print "Error: vector object is incorrect."
120         return None
121     p1 = geompy.PointCoordinates(vertices[0])
122     p2 = geompy.PointCoordinates(vertices[1])
123     pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
124     dir = DirStruct(pnt)
125     return dir
126
127 ## Get AxisStruct from object
128 #  @param theObj is GEOM object(line or plane)
129 #  @return SMESH.AxisStruct
130 def GetAxisStruct(theObj):
131     edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
132     if len(edges) > 1:
133         vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
134         vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
135         vertex1 = geompy.PointCoordinates(vertex1)
136         vertex2 = geompy.PointCoordinates(vertex2)
137         vertex3 = geompy.PointCoordinates(vertex3)
138         vertex4 = geompy.PointCoordinates(vertex4)
139         v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
140         v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
141         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] ]
142         axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
143         return axis
144     elif len(edges) == 1:
145         vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
146         p1 = geompy.PointCoordinates( vertex1 )
147         p2 = geompy.PointCoordinates( vertex2 )
148         axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
149         return axis
150     return None
151
152 # From SMESH_Gen interface:
153 # ------------------------
154
155 ## Set the current mode
156 def SetEmbeddedMode( theMode ):
157     smesh.SetEmbeddedMode(theMode)
158
159 ## Get the current mode
160 def IsEmbeddedMode():
161     return smesh.IsEmbeddedMode()
162
163 ## Set the current study
164 def SetCurrentStudy( theStudy ):
165     smesh.SetCurrentStudy(theStudy)
166
167 ## Get the current study
168 def GetCurrentStudy():
169     return smesh.GetCurrentStudy()
170
171 ## Create Mesh object importing data from given UNV file
172 #  @return an instance of Mesh class
173 def CreateMeshesFromUNV( theFileName ):
174     aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
175     aMesh = Mesh(aSmeshMesh)
176     return aMesh
177
178 ## Create Mesh object(s) importing data from given MED file
179 #  @return a list of Mesh class instances
180 def CreateMeshesFromMED( theFileName ):
181     aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
182     aMeshes = []
183     for iMesh in range(len(aSmeshMeshes)) :
184         aMesh = Mesh(aSmeshMeshes[iMesh])
185         aMeshes.append(aMesh)
186     return aMeshes, aStatus
187
188 ## Create Mesh object importing data from given STL file
189 #  @return an instance of Mesh class
190 def CreateMeshesFromSTL( theFileName ):
191     aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
192     aMesh = Mesh(aSmeshMesh)
193     return aMesh
194
195 ## From SMESH_Gen interface
196 def GetSubShapesId( theMainObject, theListOfSubObjects ):
197     return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
198
199 ## From SMESH_Gen interface. Creates pattern
200 def GetPattern():
201     return smesh.GetPattern()
202
203
204
205 # Filtering. Auxiliary functions:
206 # ------------------------------
207
208 ## Creates an empty criterion
209 #  @return SMESH.Filter.Criterion
210 def GetEmptyCriterion():
211     Type = EnumToLong(FT_Undefined)
212     Compare = EnumToLong(FT_Undefined)
213     Threshold = 0
214     ThresholdStr = ""
215     ThresholdID = ""
216     UnaryOp = EnumToLong(FT_Undefined)
217     BinaryOp = EnumToLong(FT_Undefined)
218     Tolerance = 1e-07
219     TypeOfElement = ALL
220     Precision = -1 ##@1e-07
221     return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
222                             UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
223       
224 ## Creates a criterion by given parameters
225 #  @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
226 #  @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
227 #  @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
228 #  @param Treshold is threshold value (range of ids as string, shape, numeric)
229 #  @param UnaryOp is FT_LogicalNOT or FT_Undefined
230 #  @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
231 #                  FT_Undefined(must be for the last criterion in criteria)
232 #  @return SMESH.Filter.Criterion
233 def GetCriterion(elementType,
234                  CritType,
235                  Compare = FT_EqualTo,
236                  Treshold="",
237                  UnaryOp=FT_Undefined,
238                  BinaryOp=FT_Undefined):
239     aCriterion = GetEmptyCriterion()
240     aCriterion.TypeOfElement = elementType
241     aCriterion.Type = EnumToLong(CritType)
242         
243     aTreshold = Treshold
244         
245     if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
246         aCriterion.Compare = EnumToLong(Compare)
247     elif Compare == "=" or Compare == "==":
248         aCriterion.Compare = EnumToLong(FT_EqualTo)
249     elif Compare == "<":
250         aCriterion.Compare = EnumToLong(FT_LessThan)
251     elif Compare == ">":
252         aCriterion.Compare = EnumToLong(FT_MoreThan)
253     else:
254         aCriterion.Compare = EnumToLong(FT_EqualTo)
255         aTreshold = Compare
256
257     if CritType in [FT_BelongToGeom,     FT_BelongToPlane, FT_BelongToGenSurface, 
258                     FT_BelongToCylinder, FT_LyingOnGeom]:
259         # Check treshold
260         if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
261             aCriterion.ThresholdStr = GetName(aTreshold)
262             aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
263         else:
264             print "Error: Treshold should be a shape."
265             return None
266     elif CritType == FT_RangeOfIds:
267         # Check treshold
268         if isinstance(aTreshold, str):
269             aCriterion.ThresholdStr = aTreshold
270         else:
271             print "Error: Treshold should be a string."
272             return None
273     elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
274         # Here we don't need treshold
275         if aTreshold ==  FT_LogicalNOT:
276             aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
277         elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
278             aCriterion.BinaryOp = aTreshold
279     else:
280         # Check treshold
281         try:
282             aTreshold = float(aTreshold)
283             aCriterion.Threshold = aTreshold
284         except:
285             print "Error: Treshold should be a number."
286             return None
287
288     if Treshold ==  FT_LogicalNOT or UnaryOp ==  FT_LogicalNOT:
289         aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
290
291     if Treshold in [FT_LogicalAND, FT_LogicalOR]:
292         aCriterion.BinaryOp = EnumToLong(Treshold)
293
294     if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
295         aCriterion.BinaryOp = EnumToLong(UnaryOp)
296
297     if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
298         aCriterion.BinaryOp = EnumToLong(BinaryOp)
299
300     return aCriterion
301
302 ## Creates filter by given parameters of criterion
303 #  @param elementType is the type of elements in the group
304 #  @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
305 #  @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
306 #  @param Treshold is threshold value (range of id ids as string, shape, numeric)
307 #  @param UnaryOp is FT_LogicalNOT or FT_Undefined
308 #  @return SMESH_Filter
309 def GetFilter(elementType,
310               CritType=FT_Undefined,
311               Compare=FT_EqualTo,
312               Treshold="",
313               UnaryOp=FT_Undefined):
314     aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
315     aFilterMgr = smesh.CreateFilterManager()
316     aFilter = aFilterMgr.CreateFilter()
317     aCriteria = []
318     aCriteria.append(aCriterion)
319     aFilter.SetCriteria(aCriteria)
320     return aFilter
321
322 ## Creates numerical functor by its type
323 #  @param theCrierion is FT_...; functor type
324 #  @return SMESH_NumericalFunctor
325 def GetFunctor(theCriterion):
326     aFilterMgr = smesh.CreateFilterManager()
327     if theCriterion == FT_AspectRatio:
328         return aFilterMgr.CreateAspectRatio()
329     elif theCriterion == FT_AspectRatio3D:
330         return aFilterMgr.CreateAspectRatio3D()
331     elif theCriterion == FT_Warping:
332         return aFilterMgr.CreateWarping()
333     elif theCriterion == FT_MinimumAngle:
334         return aFilterMgr.CreateMinimumAngle()
335     elif theCriterion == FT_Taper:
336         return aFilterMgr.CreateTaper()
337     elif theCriterion == FT_Skew:
338         return aFilterMgr.CreateSkew()
339     elif theCriterion == FT_Area:
340         return aFilterMgr.CreateArea()
341     elif theCriterion == FT_Volume3D:
342         return aFilterMgr.CreateVolume3D()
343     elif theCriterion == FT_MultiConnection:
344         return aFilterMgr.CreateMultiConnection()
345     elif theCriterion == FT_MultiConnection2D:
346         return aFilterMgr.CreateMultiConnection2D()
347     elif theCriterion == FT_Length:
348         return aFilterMgr.CreateLength()
349     elif theCriterion == FT_Length2D:
350         return aFilterMgr.CreateLength2D()
351     else:
352         print "Error: given parameter is not numerucal functor type."
353
354
355 ## Print error message if a hypothesis was not assigned.
356 def TreatHypoStatus(status, hypName, geomName, isAlgo):
357     if isAlgo:
358         hypType = "algorithm"
359     else:
360         hypType = "hypothesis"
361         pass
362     if status == HYP_UNKNOWN_FATAL :
363         reason = "for unknown reason"
364     elif status == HYP_INCOMPATIBLE :
365         reason = "this hypothesis mismatches algorithm"
366     elif status == HYP_NOTCONFORM :
367         reason = "not conform mesh would be built"
368     elif status == HYP_ALREADY_EXIST :
369         reason = hypType + " of the same dimension already assigned to this shape"
370     elif status == HYP_BAD_DIM :
371         reason = hypType + " mismatches shape"
372     elif status == HYP_CONCURENT :
373         reason = "there are concurrent hypotheses on sub-shapes"
374     elif status == HYP_BAD_SUBSHAPE :
375         reason = "shape is neither the main one, nor its subshape, nor a valid group"
376     elif status == HYP_BAD_GEOMETRY:
377         reason = "geometry mismatches algorithm's expectation"
378     elif status == HYP_HIDDEN_ALGO:
379         reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
380     elif status == HYP_HIDING_ALGO:
381         reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
382     else:
383         return
384     hypName = '"' + hypName + '"'
385     geomName= '"' + geomName+ '"'
386     if status < HYP_UNKNOWN_FATAL:
387         print hypName, "was assigned to",    geomName,"but", reason
388     else:
389         print hypName, "was not assigned to",geomName,":", reason
390         pass
391
392     
393     
394 ## Mother class to define algorithm, recommended to don't use directly.
395 #
396 #  More details.
397 class Mesh_Algorithm:
398     #  @class Mesh_Algorithm
399     #  @brief Class Mesh_Algorithm
400
401     mesh = 0
402     geom = 0
403     subm = 0
404     algo = 0
405
406     ## If the algorithm is global, return 0; \n
407     #  else return the submesh associated to this algorithm.
408     def GetSubMesh(self):
409         return self.subm
410
411     ## Return the wrapped mesher.
412     def GetAlgorithm(self):
413         return self.algo
414
415     ## Get list of hypothesis that can be used with this algorithm
416     def GetCompatibleHypothesis(self):
417         list = []
418         if self.algo:
419             list = self.algo.GetCompatibleHypothesis()
420         return list
421
422     ## Get name of algo
423     def GetName(self):
424         GetName(self.algo)
425
426     ## Set name to algo
427     def SetName(self, name):
428         SetName(self.algo, name)
429
430     ## Get id of algo
431     def GetId(self):
432         return self.algo.GetId()
433     
434     ## Private method.
435     def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
436         if geom is None:
437             raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
438         self.mesh = mesh
439         piece = mesh.geom
440         if geom==0:
441             self.geom = piece
442             name = GetName(piece)
443         else:
444             self.geom = geom
445             name = GetName(geom)
446             if name==NO_NAME:
447                 name = geompy.SubShapeName(geom, piece)
448                 geompy.addToStudyInFather(piece, geom, name)
449             self.subm = mesh.mesh.GetSubMesh(geom, hypo)
450
451         self.algo = smesh.CreateHypothesis(hypo, so)
452         SetName(self.algo, name + "/" + hypo)
453         status = mesh.mesh.AddHypothesis(self.geom, self.algo)
454         TreatHypoStatus( status, hypo, name, 1 )
455         
456     ## Private method
457     def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
458         hypo = smesh.CreateHypothesis(hyp, so)
459         a = ""
460         s = "="
461         i = 0
462         n = len(args)
463         while i<n:
464             a = a + s + str(args[i])
465             s = ","
466             i = i + 1
467         name = GetName(self.geom)
468         SetName(hypo, name + "/" + hyp + a)
469         status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
470         TreatHypoStatus( status, hyp, name, 0 )
471         return hypo
472
473
474 # Public class: Mesh_Segment
475 # --------------------------
476
477 ## Class to define a segment 1D algorithm for discretization
478 #
479 #  More details.
480 class Mesh_Segment(Mesh_Algorithm):
481
482     ## Private constructor.
483     def __init__(self, mesh, geom=0):
484         self.Create(mesh, geom, "Regular_1D")
485         
486     ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
487     #  @param l for the length of segments that cut an edge
488     def LocalLength(self, l):
489         hyp = self.Hypothesis("LocalLength", [l])
490         hyp.SetLength(l)
491         return hyp
492         
493     ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
494     #  @param n for the number of segments that cut an edge
495     #  @param s for the scale factor (optional)
496     def NumberOfSegments(self, n, s=[]):
497         if s == []:
498             hyp = self.Hypothesis("NumberOfSegments", [n])
499         else:
500             hyp = self.Hypothesis("NumberOfSegments", [n,s])
501             hyp.SetDistrType( 1 )
502             hyp.SetScaleFactor(s)
503         hyp.SetNumberOfSegments(n)
504         return hyp
505         
506     ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
507     #  @param start for the length of the first segment
508     #  @param end   for the length of the last  segment
509     def Arithmetic1D(self, start, end):
510         hyp = self.Hypothesis("Arithmetic1D", [start, end])
511         hyp.SetLength(start, 1)
512         hyp.SetLength(end  , 0)
513         return hyp
514         
515     ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
516     #  @param start for the length of the first segment
517     #  @param end   for the length of the last  segment
518     def StartEndLength(self, start, end):
519         hyp = self.Hypothesis("StartEndLength", [start, end])
520         hyp.SetLength(start, 1)
521         hyp.SetLength(end  , 0)
522         return hyp
523         
524     ## Define "Deflection1D" hypothesis
525     #  @param d for the deflection
526     def Deflection1D(self, d):
527         hyp = self.Hypothesis("Deflection1D", [d])
528         hyp.SetDeflection(d)
529         return hyp
530         
531     ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
532     #  the opposite side in the case of quadrangular faces
533     def Propagation(self):
534         return self.Hypothesis("Propagation")
535
536     ## Define "AutomaticLength" hypothesis
537     #  @param fineness for the fineness [0-1]
538     def AutomaticLength(self, fineness=0):
539         hyp = self.Hypothesis("AutomaticLength")
540         hyp.SetFineness( fineness )
541         return hyp
542
543     ## Define "SegmentLengthAroundVertex" hypothesis
544     #  @param length for the segment length
545     #  @param vertex for the length localization: vertex index [0,1] | verext object
546     def LengthNearVertex(self, length, vertex=0):
547         import types
548         store_geom = self.geom
549         if vertex:
550             if type(vertex) is types.IntType:
551                 vertex = geompy.SubShapeAllSorted(self.geom,geompy.ShapeType["VERTEX"])[vertex]
552                 pass
553             self.geom = vertex
554             pass
555         hyp = self.Hypothesis("SegmentAroundVertex_0D")
556         hyp = self.Hypothesis("SegmentLengthAroundVertex")
557         self.geom = store_geom
558         hyp.SetLength( length )
559         return hyp
560
561     ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
562     #  If the 2D mesher sees that all boundary edges are quadratic ones,
563     #  it generates quadratic faces, else it generates linear faces using
564     #  medium nodes as if they were vertex ones.
565     #  The 3D mesher generates quadratic volumes only if all boundary faces
566     #  are quadratic ones, else it fails.
567     def QuadraticMesh(self):
568         hyp = self.Hypothesis("QuadraticMesh")
569         return hyp
570
571 # Public class: Mesh_CompositeSegment
572 # --------------------------
573
574 ## Class to define a segment 1D algorithm for discretization
575 #
576 #  More details.
577 class Mesh_CompositeSegment(Mesh_Segment):
578
579     ## Private constructor.
580     def __init__(self, mesh, geom=0):
581         self.Create(mesh, geom, "CompositeSegment_1D")
582         
583
584 # Public class: Mesh_Segment_Python
585 # ---------------------------------
586
587 ## Class to define a segment 1D algorithm for discretization with python function
588 #
589 #  More details.
590 class Mesh_Segment_Python(Mesh_Segment):
591
592     ## Private constructor.
593     def __init__(self, mesh, geom=0):
594         import Python1dPlugin
595         self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
596     
597     ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
598     #  @param n for the number of segments that cut an edge
599     #  @param func for the python function that calculate the length of all segments
600     def PythonSplit1D(self, n, func):
601         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
602         hyp.SetNumberOfSegments(n)
603         hyp.SetPythonLog10RatioFunction(func)
604         return hyp
605         
606 # Public class: Mesh_Triangle
607 # ---------------------------
608
609 ## Class to define a triangle 2D algorithm
610 #
611 #  More details.
612 class Mesh_Triangle(Mesh_Algorithm):
613
614     algoType = 0
615     params = 0
616    
617     ## Private constructor.
618     def __init__(self, mesh, algoType, geom=0):
619         if algoType == MEFISTO:
620             self.Create(mesh, geom, "MEFISTO_2D")
621         elif algoType == NETGEN:
622             if noNETGENPlugin:
623                 print "Warning: NETGENPlugin module has not been imported."
624             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
625         self.algoType = algoType
626
627     ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
628     #  @param area for the maximum area of each triangles
629     def MaxElementArea(self, area):
630         if self.algoType == MEFISTO:
631             hyp = self.Hypothesis("MaxElementArea", [area])
632             hyp.SetMaxElementArea(area)
633             return hyp
634         elif self.algoType == NETGEN:
635             print "Netgen 1D-2D algo doesn't support this hypothesis"
636             return None
637             
638     ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
639     def LengthFromEdges(self):
640         if self.algoType == MEFISTO:
641             hyp = self.Hypothesis("LengthFromEdges")
642             return hyp
643         elif self.algoType == NETGEN:
644             print "Netgen 1D-2D algo doesn't support this hypothesis"
645             return None
646         
647     ## Define "Netgen 2D Parameters" hypothesis
648     def Parameters(self):
649         if self.algoType == NETGEN:
650             self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
651             return self.params
652         elif self.algoType == MEFISTO:
653             print "Mefisto algo doesn't support this hypothesis"
654             return None
655
656     ## Set MaxSize
657     def SetMaxSize(self, theSize):
658         if self.params == 0:
659             self.Parameters()
660         self.params.SetMaxSize(theSize)
661         
662     ## Set SecondOrder flag
663     def SetSecondOrder(seld, theVal):
664         if self.params == 0:
665             self.Parameters()
666         self.params.SetSecondOrder(theVal)
667
668     ## Set Optimize flag
669     def SetOptimize(self, theVal):
670         if self.params == 0:
671             self.Parameters()
672         self.params.SetOptimize(theVal)
673
674     ## Set Fineness
675     #  @param theFineness is:
676     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
677     def SetFineness(self, theFineness):
678         if self.params == 0:
679             self.Parameters()
680         self.params.SetFineness(theFineness)
681         
682     ## Set GrowthRate  
683     def SetGrowthRate(self, theRate):
684         if self.params == 0:
685             self.Parameters()
686         self.params.SetGrowthRate(theRate)
687
688     ## Set NbSegPerEdge
689     def SetNbSegPerEdge(self, theVal):
690         if self.params == 0:
691             self.Parameters()
692         self.params.SetNbSegPerEdge(theVal)
693
694     ## Set NbSegPerRadius
695     def SetNbSegPerRadius(self, theVal):
696         if self.params == 0:
697             self.Parameters()
698         self.params.SetNbSegPerRadius(theVal)
699
700     ## Set QuadAllowed flag
701     def SetQuadAllowed(self, toAllow):
702         if self.params == 0:
703             self.Parameters()
704         self.params.SetQuadAllowed(toAllow)
705         
706     
707 # Public class: Mesh_Quadrangle
708 # -----------------------------
709
710 ## Class to define a quadrangle 2D algorithm
711 #
712 #  More details.
713 class Mesh_Quadrangle(Mesh_Algorithm):
714
715     ## Private constructor.
716     def __init__(self, mesh, geom=0):
717         self.Create(mesh, geom, "Quadrangle_2D")
718     
719     ## Define "QuadranglePreference" hypothesis, forcing construction
720     #  of quadrangles if the number of nodes on opposite edges is not the same
721     #  in the case where the global number of nodes on edges is even
722     def QuadranglePreference(self):
723         hyp = self.Hypothesis("QuadranglePreference")
724         return hyp
725     
726 # Public class: Mesh_Tetrahedron
727 # ------------------------------
728
729 ## Class to define a tetrahedron 3D algorithm
730 #
731 #  More details.
732 class Mesh_Tetrahedron(Mesh_Algorithm):
733
734     params = 0
735     algoType = 0
736
737     ## Private constructor.
738     def __init__(self, mesh, algoType, geom=0):
739         if algoType == NETGEN:
740             self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
741         elif algoType == GHS3D:
742             import GHS3DPlugin
743             self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
744         elif algoType == FULL_NETGEN:
745             if noNETGENPlugin:
746                 print "Warning: NETGENPlugin module has not been imported."
747             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
748         self.algoType = algoType
749
750     ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
751     #  @param vol for the maximum volume of each tetrahedral
752     def MaxElementVolume(self, vol):
753         hyp = self.Hypothesis("MaxElementVolume", [vol])
754         hyp.SetMaxElementVolume(vol)
755         return hyp
756
757     ## Define "Netgen 3D Parameters" hypothesis
758     def Parameters(self):
759         if (self.algoType == FULL_NETGEN):
760             self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
761             return self.params
762         else:
763             print "Algo doesn't support this hypothesis"
764             return None 
765             
766     ## Set MaxSize
767     def SetMaxSize(self, theSize):
768         if self.params == 0:
769             self.Parameters()
770         self.params.SetMaxSize(theSize)
771         
772     ## Set SecondOrder flag
773     def SetSecondOrder(self, theVal):
774         if self.params == 0:
775             self.Parameters()
776         self.params.SetSecondOrder(theVal)
777
778     ## Set Optimize flag
779     def SetOptimize(self, theVal):
780         if self.params == 0:
781             self.Parameters()
782         self.params.SetOptimize(theVal)
783
784     ## Set Fineness
785     #  @param theFineness is:
786     #  VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
787     def SetFineness(self, theFineness):
788         if self.params == 0:
789             self.Parameters()
790         self.params.SetFineness(theFineness)
791         
792     ## Set GrowthRate  
793     def SetGrowthRate(self, theRate):
794         if self.params == 0:
795             self.Parameters()
796         self.params.SetGrowthRate(theRate)
797
798     ## Set NbSegPerEdge
799     def SetNbSegPerEdge(self, theVal):
800         if self.params == 0:
801             self.Parameters()
802         self.params.SetNbSegPerEdge(theVal)
803
804     ## Set NbSegPerRadius
805     def SetNbSegPerRadius(self, theVal):
806         if self.params == 0:
807             self.Parameters()
808         self.params.SetNbSegPerRadius(theVal)
809
810 # Public class: Mesh_Hexahedron
811 # ------------------------------
812
813 ## Class to define a hexahedron 3D algorithm
814 #
815 #  More details.
816 class Mesh_Hexahedron(Mesh_Algorithm):
817
818     ## Private constructor.
819     def __init__(self, mesh, geom=0):
820         self.Create(mesh, geom, "Hexa_3D")
821
822 # Deprecated, only for compatibility!
823 # Public class: Mesh_Netgen
824 # ------------------------------
825
826 ## Class to define a NETGEN-based 2D or 3D algorithm
827 #  that need no discrete boundary (i.e. independent)
828 #
829 #  This class is deprecated, only for compatibility!
830 #
831 #  More details.
832 class Mesh_Netgen(Mesh_Algorithm):
833
834     is3D = 0
835
836     ## Private constructor.
837     def __init__(self, mesh, is3D, geom=0):
838         if noNETGENPlugin:
839             print "Warning: NETGENPlugin module has not been imported."
840             
841         self.is3D = is3D
842         if is3D:
843             self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
844         else:
845             self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
846
847     ## Define hypothesis containing parameters of the algorithm
848     def Parameters(self):
849         if self.is3D:
850             hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
851         else:
852             hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
853         return hyp
854
855 # Public class: Mesh_Projection1D
856 # ------------------------------
857
858 ## Class to define a projection 1D algorithm
859 #
860 #  More details.
861 class Mesh_Projection1D(Mesh_Algorithm):
862
863     ## Private constructor.
864     def __init__(self, mesh, geom=0):
865         self.Create(mesh, geom, "Projection_1D")
866
867     ## Define "Source Edge" hypothesis, specifying a meshed edge to
868     #  take a mesh pattern from, and optionally association of vertices
869     #  between the source edge and a target one (where a hipothesis is assigned to)
870     #  @param edge to take nodes distribution from
871     #  @param mesh to take nodes distribution from (optional)
872     #  @param srcV is vertex of \a edge to associate with \a tgtV (optional)
873     #  @param tgtV is vertex of \a the edge where the algorithm is assigned,
874     #  to associate with \a srcV (optional)
875     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
876         hyp = self.Hypothesis("ProjectionSource1D")
877         hyp.SetSourceEdge( edge )
878         if not mesh is None and isinstance(mesh, Mesh):
879             mesh = mesh.GetMesh()
880         hyp.SetSourceMesh( mesh )
881         hyp.SetVertexAssociation( srcV, tgtV )
882         return hyp
883
884
885 # Public class: Mesh_Projection2D
886 # ------------------------------
887
888 ## Class to define a projection 2D algorithm
889 #
890 #  More details.
891 class Mesh_Projection2D(Mesh_Algorithm):
892
893     ## Private constructor.
894     def __init__(self, mesh, geom=0):
895         self.Create(mesh, geom, "Projection_2D")
896
897     ## Define "Source Face" hypothesis, specifying a meshed face to
898     #  take a mesh pattern from, and optionally association of vertices
899     #  between the source face and a target one (where a hipothesis is assigned to)
900     #  @param face to take mesh pattern from
901     #  @param mesh to take mesh pattern from (optional)
902     #  @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
903     #  @param tgtV1 is vertex of \a the face where the algorithm is assigned,
904     #  to associate with \a srcV1 (optional)
905     #  @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
906     #  @param tgtV2 is vertex of \a the face where the algorithm is assigned,
907     #  to associate with \a srcV2 (optional)
908     #
909     #  Note: association vertices must belong to one edge of a face
910     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
911         hyp = self.Hypothesis("ProjectionSource2D")
912         hyp.SetSourceFace( face )
913         if not mesh is None and isinstance(mesh, Mesh):
914             mesh = mesh.GetMesh()
915         hyp.SetSourceMesh( mesh )
916         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
917         return hyp
918
919 # Public class: Mesh_Projection3D
920 # ------------------------------
921
922 ## Class to define a projection 3D algorithm
923 #
924 #  More details.
925 class Mesh_Projection3D(Mesh_Algorithm):
926
927     ## Private constructor.
928     def __init__(self, mesh, geom=0):
929         self.Create(mesh, geom, "Projection_3D")
930
931     ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
932     #  take a mesh pattern from, and optionally association of vertices
933     #  between the source solid and a target one (where a hipothesis is assigned to)
934     #  @param solid to take mesh pattern from
935     #  @param mesh to take mesh pattern from (optional)
936     #  @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
937     #  @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
938     #  to associate with \a srcV1 (optional)
939     #  @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
940     #  @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
941     #  to associate with \a srcV2 (optional)
942     #
943     #  Note: association vertices must belong to one edge of a solid
944     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
945         hyp = self.Hypothesis("ProjectionSource3D")
946         hyp.SetSource3DShape( solid )
947         if not mesh is None and isinstance(mesh, Mesh):
948             mesh = mesh.GetMesh()
949         hyp.SetSourceMesh( mesh )
950         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
951         return hyp
952
953
954 # Public class: Mesh_Prism
955 # ------------------------
956
957 ## Class to define a 3D extrusion algorithm
958 #
959 #  More details.
960 class Mesh_Prism3D(Mesh_Algorithm):
961
962     ## Private constructor.
963     def __init__(self, mesh, geom=0):
964         self.Create(mesh, geom, "Prism_3D")
965
966 # Public class: Mesh_RadialPrism
967 # -------------------------------
968
969 ## Class to define a Radial Prism 3D algorithm
970 #
971 #  More details.
972 class Mesh_RadialPrism3D(Mesh_Algorithm):
973
974     ## Private constructor.
975     def __init__(self, mesh, geom=0):
976         self.Create(mesh, geom, "RadialPrism_3D")
977         self.distribHyp = self.Hypothesis( "LayerDistribution" )
978         self.nbLayers = None
979
980     ## Return 3D hypothesis holding the 1D one
981     def Get3DHypothesis(self):
982         return self.distribHyp
983
984     ## Private method creating 1D hypothes and storing it in the LayerDistribution
985     #  hypothes. Returns the created hypothes
986     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
987         if not self.nbLayers is None:
988             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
989             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
990         study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
991         hyp = smesh.CreateHypothesis(hypType, so)
992         SetCurrentStudy( study ) # anable publishing
993         self.distribHyp.SetLayerDistribution( hyp )
994         return hyp
995
996     ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
997     #  prisms to build between the inner and outer shells
998     def NumberOfLayers(self, n ):
999         self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1000         self.nbLayers = self.Hypothesis("NumberOfLayers")
1001         self.nbLayers.SetNumberOfLayers( n )
1002         return self.nbLayers
1003
1004     ## Define "LocalLength" hypothesis, specifying segment length
1005     #  to build between the inner and outer shells
1006     #  @param l for the length of segments
1007     def LocalLength(self, l):
1008         hyp = self.OwnHypothesis("LocalLength", [l])
1009         hyp.SetLength(l)
1010         return hyp
1011         
1012     ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1013     #  prisms to build between the inner and outer shells
1014     #  @param n for the number of segments
1015     #  @param s for the scale factor (optional)
1016     def NumberOfSegments(self, n, s=[]):
1017         if s == []:
1018             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1019         else:
1020             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1021             hyp.SetDistrType( 1 )
1022             hyp.SetScaleFactor(s)
1023         hyp.SetNumberOfSegments(n)
1024         return hyp
1025         
1026     ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1027     #  to build between the inner and outer shells as arithmetic length increasing
1028     #  @param start for the length of the first segment
1029     #  @param end   for the length of the last  segment
1030     def Arithmetic1D(self, start, end):
1031         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1032         hyp.SetLength(start, 1)
1033         hyp.SetLength(end  , 0)
1034         return hyp
1035         
1036     ## Define "StartEndLength" hypothesis, specifying distribution of segments
1037     #  to build between the inner and outer shells as geometric length increasing
1038     #  @param start for the length of the first segment
1039     #  @param end   for the length of the last  segment
1040     def StartEndLength(self, start, end):
1041         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1042         hyp.SetLength(start, 1)
1043         hyp.SetLength(end  , 0)
1044         return hyp
1045         
1046     ## Define "AutomaticLength" hypothesis, specifying number of segments
1047     #  to build between the inner and outer shells
1048     #  @param fineness for the fineness [0-1]
1049     def AutomaticLength(self, fineness=0):
1050         hyp = self.OwnHypothesis("AutomaticLength")
1051         hyp.SetFineness( fineness )
1052         return hyp
1053
1054
1055 # Public class: Mesh
1056 # ==================
1057
1058 ## Class to define a mesh
1059 #
1060 #  The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1061 #  More details.
1062 class Mesh:
1063
1064     geom = 0
1065     mesh = 0
1066     editor = 0
1067
1068     ## Constructor
1069     #
1070     #  Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1071     #  sets GUI name of this mesh to \a name.
1072     #  @param obj Shape to be meshed or SMESH_Mesh object
1073     #  @param name Study name of the mesh
1074     def __init__(self, obj=0, name=0):
1075         if obj is None:
1076             obj = 0
1077         if obj != 0:
1078             if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1079                 self.geom = obj
1080                 self.mesh = smesh.CreateMesh(self.geom)
1081             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1082                 self.SetMesh(obj)
1083         else:
1084             self.mesh = smesh.CreateEmptyMesh()
1085         if name != 0:
1086             SetName(self.mesh, name)
1087         elif obj != 0:
1088             SetName(self.mesh, GetName(obj))
1089
1090         self.editor = self.mesh.GetMeshEditor()
1091
1092     ## Method that inits the Mesh object from SMESH_Mesh interface
1093     #  @param theMesh is SMESH_Mesh object
1094     def SetMesh(self, theMesh):
1095         self.mesh = theMesh
1096         self.geom = self.mesh.GetShapeToMesh()
1097             
1098     ## Method that returns the mesh
1099     #  @return SMESH_Mesh object
1100     def GetMesh(self):
1101         return self.mesh
1102
1103     ## Get mesh name
1104     def GetName(self):
1105         name = GetName(self.GetMesh())
1106         return name
1107
1108     ## Set name to mesh
1109     def SetName(self, name):
1110         SetName(self.GetMesh(), name)
1111     
1112     ## Get the subMesh object associated to a subShape. The subMesh object
1113     #  gives access to nodes and elements IDs.
1114     #  \n SubMesh will be used instead of SubShape in a next idl version to
1115     #  adress a specific subMesh...
1116     def GetSubMesh(self, theSubObject, name):
1117         submesh = self.mesh.GetSubMesh(theSubObject, name)
1118         return submesh
1119         
1120     ## Method that returns the shape associated to the mesh
1121     #  @return GEOM_Object
1122     def GetShape(self):
1123         return self.geom
1124
1125     ## Method that associates given shape to the mesh(entails the mesh recreation)
1126     #  @param geom shape to be meshed(GEOM_Object)
1127     def SetShape(self, geom):
1128         self.mesh = smesh.CreateMesh(geom)  
1129                 
1130     ## Return true if hypotheses are defined well
1131     #  @param theMesh is an instance of Mesh class
1132     #  @param theSubObject subshape of a mesh shape
1133     def IsReadyToCompute(self, theSubObject):
1134         return smesh.IsReadyToCompute(self.mesh, theSubObject)
1135
1136     ## Return errors of hypotheses definintion
1137     #  error list is empty if everything is OK
1138     #  @param theMesh is an instance of Mesh class
1139     #  @param theSubObject subshape of a mesh shape
1140     #  @return a list of errors
1141     def GetAlgoState(self, theSubObject):
1142         return smesh.GetAlgoState(self.mesh, theSubObject)
1143     
1144     ## Return geometrical object the given element is built on.
1145     #  The returned geometrical object, if not nil, is either found in the 
1146     #  study or is published by this method with the given name
1147     #  @param theMesh is an instance of Mesh class
1148     #  @param theElementID an id of the mesh element
1149     #  @param theGeomName user defined name of geometrical object
1150     #  @return GEOM::GEOM_Object instance
1151     def GetGeometryByMeshElement(self, theElementID, theGeomName):
1152         return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1153         
1154     ## Returns mesh dimension depending on shape one
1155     def MeshDimension(self):
1156         shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1157         if len( shells ) > 0 :
1158             return 3
1159         elif geompy.NumberOfFaces( self.geom ) > 0 :
1160             return 2
1161         elif geompy.NumberOfEdges( self.geom ) > 0 :
1162             return 1
1163         else:
1164             return 0;
1165         pass
1166         
1167     ## Creates a segment discretization 1D algorithm.
1168     #  If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1169     #  If the optional \a geom parameter is not sets, this algorithm is global.
1170     #  \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1171     #  @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1172     #  @param geom If defined, subshape to be meshed
1173     def Segment(self, algo=REGULAR, geom=0):
1174         ## if Segment(geom) is called by mistake
1175         if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1176             algo, geom = geom, algo
1177             pass
1178         if algo == REGULAR:
1179             return Mesh_Segment(self, geom)
1180         elif algo == PYTHON:
1181             return Mesh_Segment_Python(self, geom)
1182         elif algo == COMPOSITE:
1183             return Mesh_CompositeSegment(self, geom)
1184         else:
1185             return Mesh_Segment(self, geom)
1186         
1187     ## Creates a triangle 2D algorithm for faces.
1188     #  If the optional \a geom parameter is not sets, this algorithm is global.
1189     #  \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1190     #  @param algo values are: smesh.MEFISTO or smesh.NETGEN
1191     #  @param geom If defined, subshape to be meshed
1192     def Triangle(self, algo=MEFISTO, geom=0):
1193         ## if Triangle(geom) is called by mistake
1194         if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1195             geom = algo
1196             algo = MEFISTO
1197         
1198         return Mesh_Triangle(self, algo, geom)
1199         
1200     ## Creates a quadrangle 2D algorithm for faces.
1201     #  If the optional \a geom parameter is not sets, this algorithm is global.
1202     #  \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1203     #  @param geom If defined, subshape to be meshed
1204     def Quadrangle(self, geom=0):
1205         return Mesh_Quadrangle(self, geom)
1206
1207     ## Creates a tetrahedron 3D algorithm for solids.
1208     #  The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1209     #  If the optional \a geom parameter is not sets, this algorithm is global.
1210     #  \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1211     #  @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1212     #  @param geom If defined, subshape to be meshed
1213     def Tetrahedron(self, algo=NETGEN, geom=0):
1214         ## if Tetrahedron(geom) is called by mistake
1215         if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1216             algo, geom = geom, algo
1217             pass
1218         return Mesh_Tetrahedron(self, algo, geom)
1219         
1220     ## Creates a hexahedron 3D algorithm for solids.
1221     #  If the optional \a geom parameter is not sets, this algorithm is global.
1222     #  \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1223     #  @param geom If defined, subshape to be meshed
1224     def Hexahedron(self, geom=0):
1225         return Mesh_Hexahedron(self, geom)
1226
1227     ## Deprecated, only for compatibility!
1228     def Netgen(self, is3D, geom=0):
1229         return Mesh_Netgen(self, is3D, geom)
1230
1231     ## Creates a projection 1D algorithm for edges.
1232     #  If the optional \a geom parameter is not sets, this algorithm is global.
1233     #  Otherwise, this algorithm define a submesh based on \a geom subshape.
1234     #  @param geom If defined, subshape to be meshed
1235     def Projection1D(self, geom=0):
1236         return Mesh_Projection1D(self, geom)
1237
1238     ## Creates a projection 2D algorithm for faces.
1239     #  If the optional \a geom parameter is not sets, this algorithm is global.
1240     #  Otherwise, this algorithm define a submesh based on \a geom subshape.
1241     #  @param geom If defined, subshape to be meshed
1242     def Projection2D(self, geom=0):
1243         return Mesh_Projection2D(self, geom)
1244
1245     ## Creates a projection 3D algorithm for solids.
1246     #  If the optional \a geom parameter is not sets, this algorithm is global.
1247     #  Otherwise, this algorithm define a submesh based on \a geom subshape.
1248     #  @param geom If defined, subshape to be meshed
1249     def Projection3D(self, geom=0):
1250         return Mesh_Projection3D(self, geom)
1251
1252     ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1253     #  If the optional \a geom parameter is not sets, this algorithm is global.
1254     #  Otherwise, this algorithm define a submesh based on \a geom subshape.
1255     #  @param geom If defined, subshape to be meshed
1256     def Prism(self, geom=0):
1257         shape = geom
1258         if shape==0:
1259             shape = self.geom
1260         nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1261         nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1262         if nbSolids == 0 or nbSolids == nbShells:
1263             return Mesh_Prism3D(self, geom)
1264         return Mesh_RadialPrism3D(self, geom)
1265
1266     ## Compute the mesh and return the status of the computation
1267     def Compute(self, geom=0):
1268         if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1269             if self.geom == 0:
1270                 print "Compute impossible: mesh is not constructed on geom shape."
1271                 return 0
1272             else:
1273                 geom = self.geom
1274         ok = False
1275         try:
1276             ok = smesh.Compute(self.mesh, geom)
1277         except SALOME.SALOME_Exception, ex:
1278             print "Mesh computation failed, exception cought:"
1279             print "    ", ex.details.text
1280         except:
1281             import traceback
1282             print "Mesh computation failed, exception cought:"
1283             traceback.print_exc()
1284         if not ok:
1285             errors = smesh.GetAlgoState( self.mesh, geom )
1286             allReasons = ""
1287             for err in errors:
1288                 if err.isGlobalAlgo:
1289                     glob = " global "
1290                 else:
1291                     glob = " local "
1292                     pass
1293                 dim = str(err.algoDim)
1294                 if err.name == MISSING_ALGO:
1295                     reason = glob + dim + "D algorithm is missing"
1296                 elif err.name == MISSING_HYPO:
1297                     name = '"' + err.algoName + '"'
1298                     reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1299                 elif err.name == NOT_CONFORM_MESH:
1300                     reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1301                 elif err.name == BAD_PARAM_VALUE:
1302                     name = '"' + err.algoName + '"'
1303                     reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1304                              " has a bad parameter value"
1305                 else:
1306                     reason = "For unknown reason."+\
1307                              " Revise Mesh.Compute() implementation in smesh.py!"
1308                     pass
1309                 if allReasons != "":
1310                     allReasons += "\n"
1311                     pass
1312                 allReasons += reason
1313                 pass
1314             if allReasons != "":
1315                 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1316                 print allReasons
1317             else:
1318                 print '"' + GetName(self.mesh) + '"',"has not been computed."
1319                 pass
1320             pass
1321         if salome.sg.hasDesktop():
1322             smeshgui = salome.ImportComponentGUI("SMESH")
1323             smeshgui.Init(salome.myStudyId)
1324             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1325             salome.sg.updateObjBrowser(1)
1326             pass
1327         return ok
1328
1329     ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1330     #  The parameter \a fineness [0,-1] defines mesh fineness
1331     def AutomaticTetrahedralization(self, fineness=0):
1332         dim = self.MeshDimension()
1333         # assign hypotheses
1334         self.RemoveGlobalHypotheses()
1335         self.Segment().AutomaticLength(fineness)
1336         if dim > 1 :
1337             self.Triangle().LengthFromEdges()
1338             pass
1339         if dim > 2 :
1340             self.Tetrahedron(NETGEN)
1341             pass
1342         return self.Compute()
1343         
1344     ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1345     #  The parameter \a fineness [0,-1] defines mesh fineness
1346     def AutomaticHexahedralization(self, fineness=0):
1347         dim = self.MeshDimension()
1348         # assign hypotheses
1349         self.RemoveGlobalHypotheses()
1350         self.Segment().AutomaticLength(fineness)
1351         if dim > 1 :
1352             self.Quadrangle()
1353             pass
1354         if dim > 2 :
1355             self.Hexahedron()            
1356             pass
1357         return self.Compute()
1358
1359     ## Assign hypothesis
1360     #  @param hyp is a hypothesis to assign
1361     #  @param geom is subhape of mesh geometry
1362     def AddHypothesis(self, hyp, geom=0 ):
1363         if isinstance( hyp, Mesh_Algorithm ):
1364             hyp = hyp.GetAlgorithm()
1365             pass
1366         if not geom:
1367             geom = self.geom
1368             pass
1369         status = self.mesh.AddHypothesis(geom, hyp)
1370         isAlgo = ( hyp._narrow( SMESH.SMESH_Algo ) is not None )
1371         TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1372         return status
1373     
1374     ## Get the list of hypothesis added on a geom
1375     #  @param geom is subhape of mesh geometry
1376     def GetHypothesisList(self, geom):
1377         return self.mesh.GetHypothesisList( geom )
1378                 
1379     ## Removes all global hypotheses
1380     def RemoveGlobalHypotheses(self):
1381         current_hyps = self.mesh.GetHypothesisList( self.geom )
1382         for hyp in current_hyps:
1383             self.mesh.RemoveHypothesis( self.geom, hyp )
1384             pass
1385         pass
1386         
1387     ## Create a mesh group based on geometric object \a grp
1388     #  and give a \a name, \n if this parameter is not defined
1389     #  the name is the same as the geometric group name \n
1390     #  Note: Works like GroupOnGeom(). 
1391     #  @param grp  is a geometric group, a vertex, an edge, a face or a solid
1392     #  @param name is the name of the mesh group
1393     #  @return SMESH_GroupOnGeom
1394     def Group(self, grp, name=""):
1395         return self.GroupOnGeom(grp, name)
1396        
1397     ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1398     #  Export the mesh in a file with the MED format and choice the \a version of MED format
1399     #  @param f is the file name
1400     #  @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1401     def ExportToMED(self, f, version, opt=0):
1402         self.mesh.ExportToMED(f, opt, version)
1403         
1404     ## Export the mesh in a file with the MED format
1405     #  @param f is the file name
1406     #  @param auto_groups boolean parameter for creating/not creating
1407     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1408     #  the typical use is auto_groups=false.
1409     #  @param version MED format version(MED_V2_1 or MED_V2_2)
1410     def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1411         self.mesh.ExportToMED(f, auto_groups, version)
1412         
1413     ## Export the mesh in a file with the DAT format
1414     #  @param f is the file name
1415     def ExportDAT(self, f):
1416         self.mesh.ExportDAT(f)
1417         
1418     ## Export the mesh in a file with the UNV format
1419     #  @param f is the file name
1420     def ExportUNV(self, f):
1421         self.mesh.ExportUNV(f)
1422         
1423     ## Export the mesh in a file with the STL format
1424     #  @param f is the file name
1425     #  @param ascii defined the kind of file contents
1426     def ExportSTL(self, f, ascii=1):
1427         self.mesh.ExportSTL(f, ascii)
1428    
1429         
1430     # Operations with groups:
1431     # ----------------------
1432
1433     ## Creates an empty mesh group
1434     #  @param elementType is the type of elements in the group
1435     #  @param name is the name of the mesh group
1436     #  @return SMESH_Group
1437     def CreateEmptyGroup(self, elementType, name):
1438         return self.mesh.CreateGroup(elementType, name)
1439     
1440     ## Creates a mesh group based on geometric object \a grp
1441     #  and give a \a name, \n if this parameter is not defined
1442     #  the name is the same as the geometric group name
1443     #  @param grp  is a geometric group, a vertex, an edge, a face or a solid
1444     #  @param name is the name of the mesh group
1445     #  @return SMESH_GroupOnGeom
1446     def GroupOnGeom(self, grp, name="", type=None):
1447         if name == "":
1448             name = grp.GetName()
1449
1450         if type == None:
1451             tgeo = str(grp.GetShapeType())
1452             if tgeo == "VERTEX":
1453                 type = NODE
1454             elif tgeo == "EDGE":
1455                 type = EDGE
1456             elif tgeo == "FACE":
1457                 type = FACE
1458             elif tgeo == "SOLID":
1459                 type = VOLUME
1460             elif tgeo == "SHELL":
1461                 type = VOLUME
1462             elif tgeo == "COMPOUND":
1463                 if len( geompy.GetObjectIDs( grp )) == 0:
1464                     print "Mesh.Group: empty geometric group", GetName( grp )
1465                     return 0
1466                 tgeo = geompy.GetType(grp)
1467                 if tgeo == geompy.ShapeType["VERTEX"]:
1468                     type = NODE
1469                 elif tgeo == geompy.ShapeType["EDGE"]:
1470                     type = EDGE
1471                 elif tgeo == geompy.ShapeType["FACE"]:
1472                     type = FACE
1473                 elif tgeo == geompy.ShapeType["SOLID"]:
1474                     type = VOLUME
1475
1476         if type == None:
1477             print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1478             return 0
1479         else:
1480             return self.mesh.CreateGroupFromGEOM(type, name, grp)
1481
1482     ## Create a mesh group by the given ids of elements
1483     #  @param groupName is the name of the mesh group
1484     #  @param elementType is the type of elements in the group
1485     #  @param elemIDs is the list of ids
1486     #  @return SMESH_Group
1487     def MakeGroupByIds(self, groupName, elementType, elemIDs):
1488         group = self.mesh.CreateGroup(elementType, groupName)
1489         group.Add(elemIDs)
1490         return group
1491     
1492     ## Create a mesh group by the given conditions
1493     #  @param groupName is the name of the mesh group
1494     #  @param elementType is the type of elements in the group
1495     #  @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1496     #  @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1497     #  @param Treshold is threshold value (range of id ids as string, shape, numeric)
1498     #  @param UnaryOp is FT_LogicalNOT or FT_Undefined
1499     #  @return SMESH_Group
1500     def MakeGroup(self,
1501                   groupName,
1502                   elementType,
1503                   CritType=FT_Undefined,
1504                   Compare=FT_EqualTo,
1505                   Treshold="",
1506                   UnaryOp=FT_Undefined):
1507         aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1508         group = self.MakeGroupByCriterion(groupName, aCriterion)
1509         return group
1510
1511     ## Create a mesh group by the given criterion
1512     #  @param groupName is the name of the mesh group
1513     #  @param Criterion is the instance of Criterion class
1514     #  @return SMESH_Group
1515     def MakeGroupByCriterion(self, groupName, Criterion):
1516         aFilterMgr = smesh.CreateFilterManager()
1517         aFilter = aFilterMgr.CreateFilter()
1518         aCriteria = []
1519         aCriteria.append(Criterion)
1520         aFilter.SetCriteria(aCriteria)
1521         group = self.MakeGroupByFilter(groupName, aFilter)
1522         return group
1523     
1524     ## Create a mesh group by the given criteria(list of criterions)
1525     #  @param groupName is the name of the mesh group
1526     #  @param Criteria is the list of criterions
1527     #  @return SMESH_Group
1528     def MakeGroupByCriteria(self, groupName, theCriteria):
1529         aFilterMgr = smesh.CreateFilterManager()
1530         aFilter = aFilterMgr.CreateFilter()
1531         aFilter.SetCriteria(theCriteria)
1532         group = self.MakeGroupByFilter(groupName, aFilter)
1533         return group
1534     
1535     ## Create a mesh group by the given filter
1536     #  @param groupName is the name of the mesh group
1537     #  @param Criterion is the instance of Filter class
1538     #  @return SMESH_Group
1539     def MakeGroupByFilter(self, groupName, theFilter):
1540         anIds = theFilter.GetElementsId(self.mesh)
1541         anElemType = theFilter.GetElementType()
1542         group = self.MakeGroupByIds(groupName, anElemType, anIds)
1543         return group
1544
1545     ## Pass mesh elements through the given filter and return ids
1546     #  @param theFilter is SMESH_Filter
1547     #  @return list of ids
1548     def GetIdsFromFilter(self, theFilter):
1549         return theFilter.GetElementsId(self.mesh)
1550
1551     ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1552     #  Returns list of special structures(borders).
1553     #  @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1554     def GetFreeBorders(self):
1555         aFilterMgr = smesh.CreateFilterManager()
1556         aPredicate = aFilterMgr.CreateFreeEdges()
1557         aPredicate.SetMesh(self.mesh)
1558         aBorders = aPredicate.GetBorders()
1559         return aBorders
1560                 
1561     ## Remove a group
1562     def RemoveGroup(self, group):
1563         self.mesh.RemoveGroup(group)
1564
1565     ## Remove group with its contents
1566     def RemoveGroupWithContents(self, group):
1567         self.mesh.RemoveGroupWithContents(group)
1568         
1569     ## Get the list of groups existing in the mesh
1570     def GetGroups(self):
1571         return self.mesh.GetGroups()
1572
1573     ## Get the list of names of groups existing in the mesh
1574     def GetGroupNames(self):
1575         groups = self.GetGroups()
1576         names = []
1577         for group in groups:
1578             names.append(group.GetName())
1579         return names
1580
1581     ## Union of two groups
1582     #  New group is created. All mesh elements that are
1583     #  present in initial groups are added to the new one
1584     def UnionGroups(self, group1, group2, name):
1585         return self.mesh.UnionGroups(group1, group2, name)
1586
1587     ## Intersection of two groups
1588     #  New group is created. All mesh elements that are
1589     #  present in both initial groups are added to the new one.
1590     def IntersectGroups(self, group1, group2, name):
1591         return self.mesh.IntersectGroups(group1, group2, name)
1592     
1593     ## Cut of two groups
1594     #  New group is created. All mesh elements that are present in
1595     #  main group but do not present in tool group are added to the new one
1596     def CutGroups(self, mainGroup, toolGroup, name):
1597         return self.mesh.CutGroups(mainGroup, toolGroup, name)
1598          
1599     
1600     # Get some info about mesh:
1601     # ------------------------
1602
1603     ## Get the log of nodes and elements added or removed since previous
1604     #  clear of the log.
1605     #  @param clearAfterGet log is emptied after Get (safe if concurrents access)
1606     #  @return list of log_block structures:
1607     #                                        commandType
1608     #                                        number
1609     #                                        coords
1610     #                                        indexes
1611     def GetLog(self, clearAfterGet):
1612         return self.mesh.GetLog(clearAfterGet)
1613
1614     ## Clear the log of nodes and elements added or removed since previous
1615     #  clear. Must be used immediately after GetLog if clearAfterGet is false.
1616     def ClearLog(self):
1617         self.mesh.ClearLog()
1618
1619     ## Get the internal Id
1620     def GetId(self):
1621         return self.mesh.GetId()
1622
1623     ## Get the study Id
1624     def GetStudyId(self):
1625         return self.mesh.GetStudyId()
1626
1627     ## Check group names for duplications.
1628     #  Consider maximum group name length stored in MED file.
1629     def HasDuplicatedGroupNamesMED(self):
1630         return self.mesh.GetStudyId()
1631         
1632     ## Obtain instance of SMESH_MeshEditor
1633     def GetMeshEditor(self):
1634         return self.mesh.GetMeshEditor()
1635
1636     ## Get MED Mesh
1637     def GetMEDMesh(self):
1638         return self.mesh.GetMEDMesh()
1639     
1640     
1641     # Get informations about mesh contents:
1642     # ------------------------------------
1643
1644     ## Returns number of nodes in mesh
1645     def NbNodes(self):
1646         return self.mesh.NbNodes()
1647
1648     ## Returns number of elements in mesh
1649     def NbElements(self):
1650         return self.mesh.NbElements()
1651
1652     ## Returns number of edges in mesh
1653     def NbEdges(self):
1654         return self.mesh.NbEdges()
1655
1656     ## Returns number of edges with given order in mesh
1657     #  @param elementOrder is order of elements:
1658     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1659     def NbEdgesOfOrder(self, elementOrder):
1660         return self.mesh.NbEdgesOfOrder(elementOrder)
1661     
1662     ## Returns number of faces in mesh
1663     def NbFaces(self):
1664         return self.mesh.NbFaces()
1665
1666     ## Returns number of faces with given order in mesh
1667     #  @param elementOrder is order of elements:
1668     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1669     def NbFacesOfOrder(self, elementOrder):
1670         return self.mesh.NbFacesOfOrder(elementOrder)
1671
1672     ## Returns number of triangles in mesh
1673     def NbTriangles(self):
1674         return self.mesh.NbTriangles()
1675
1676     ## Returns number of triangles with given order in mesh
1677     #  @param elementOrder is order of elements:
1678     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1679     def NbTrianglesOfOrder(self, elementOrder):
1680         return self.mesh.NbTrianglesOfOrder(elementOrder)
1681
1682     ## Returns number of quadrangles in mesh
1683     def NbQuadrangles(self):
1684         return self.mesh.NbQuadrangles()
1685
1686     ## Returns number of quadrangles with given order in mesh
1687     #  @param elementOrder is order of elements:
1688     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1689     def NbQuadranglesOfOrder(self, elementOrder):
1690         return self.mesh.NbQuadranglesOfOrder(elementOrder)
1691
1692     ## Returns number of polygons in mesh
1693     def NbPolygons(self):
1694         return self.mesh.NbPolygons()
1695
1696     ## Returns number of volumes in mesh
1697     def NbVolumes(self):
1698         return self.mesh.NbVolumes()
1699
1700     ## Returns number of volumes with given order in mesh
1701     #  @param elementOrder is order of elements:
1702     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1703     def NbVolumesOfOrder(self, elementOrder):
1704         return self.mesh.NbVolumesOfOrder(elementOrder)
1705
1706     ## Returns number of tetrahedrons in mesh
1707     def NbTetras(self):
1708         return self.mesh.NbTetras()
1709
1710     ## Returns number of tetrahedrons with given order in mesh
1711     #  @param elementOrder is order of elements:
1712     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1713     def NbTetrasOfOrder(self, elementOrder):
1714         return self.mesh.NbTetrasOfOrder(elementOrder)
1715
1716     ## Returns number of hexahedrons in mesh
1717     def NbHexas(self):
1718         return self.mesh.NbHexas()
1719
1720     ## Returns number of hexahedrons with given order in mesh
1721     #  @param elementOrder is order of elements:
1722     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1723     def NbHexasOfOrder(self, elementOrder):
1724         return self.mesh.NbHexasOfOrder(elementOrder)
1725
1726     ## Returns number of pyramids in mesh
1727     def NbPyramids(self):
1728         return self.mesh.NbPyramids()
1729
1730     ## Returns number of pyramids with given order in mesh
1731     #  @param elementOrder is order of elements:
1732     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1733     def NbPyramidsOfOrder(self, elementOrder):
1734         return self.mesh.NbPyramidsOfOrder(elementOrder)
1735
1736     ## Returns number of prisms in mesh
1737     def NbPrisms(self):
1738         return self.mesh.NbPrisms()
1739
1740     ## Returns number of prisms with given order in mesh
1741     #  @param elementOrder is order of elements:
1742     #  ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1743     def NbPrismsOfOrder(self, elementOrder):
1744         return self.mesh.NbPrismsOfOrder(elementOrder)
1745
1746     ## Returns number of polyhedrons in mesh
1747     def NbPolyhedrons(self):
1748         return self.mesh.NbPolyhedrons()
1749
1750     ## Returns number of submeshes in mesh
1751     def NbSubMesh(self):
1752         return self.mesh.NbSubMesh()
1753
1754     ## Returns list of mesh elements ids
1755     def GetElementsId(self):
1756         return self.mesh.GetElementsId()
1757
1758     ## Returns list of ids of mesh elements with given type
1759     #  @param elementType is required type of elements
1760     def GetElementsByType(self, elementType):
1761         return self.mesh.GetElementsByType(elementType)
1762
1763     ## Returns list of mesh nodes ids
1764     def GetNodesId(self):
1765         return self.mesh.GetNodesId()
1766     
1767     # Get informations about mesh elements:
1768     # ------------------------------------
1769     
1770     ## Returns type of mesh element
1771     def GetElementType(self, id, iselem):
1772         return self.mesh.GetElementType(id, iselem)
1773
1774     ## Returns list of submesh elements ids
1775     #  @param shapeID is geom object(subshape) IOR
1776     def GetSubMeshElementsId(self, shapeID):
1777         return self.mesh.GetSubMeshElementsId(shapeID)
1778
1779     ## Returns list of submesh nodes ids
1780     #  @param shapeID is geom object(subshape) IOR
1781     def GetSubMeshNodesId(self, shapeID, all):
1782         return self.mesh.GetSubMeshNodesId(shapeID, all)
1783     
1784     ## Returns list of ids of submesh elements with given type
1785     #  @param shapeID is geom object(subshape) IOR
1786     def GetSubMeshElementType(self, shapeID):
1787         return self.mesh.GetSubMeshElementType(shapeID)
1788       
1789     ## Get mesh description
1790     def Dump(self):
1791         return self.mesh.Dump()
1792
1793     
1794     # Get information about nodes and elements of mesh by its ids:
1795     # -----------------------------------------------------------
1796
1797     ## Get XYZ coordinates of node as list of double
1798     #  \n If there is not node for given ID - returns empty list
1799     def GetNodeXYZ(self, id):
1800         return self.mesh.GetNodeXYZ(id)
1801
1802     ## For given node returns list of IDs of inverse elements
1803     #  \n If there is not node for given ID - returns empty list
1804     def GetNodeInverseElements(self, id):
1805         return self.mesh.GetNodeInverseElements(id)
1806
1807     ## If given element is node returns IDs of shape from position
1808     #  \n If there is not node for given ID - returns -1
1809     def GetShapeID(self, id):
1810         return self.mesh.GetShapeID(id)
1811
1812     ## For given element returns ID of result shape after 
1813     #  FindShape() from SMESH_MeshEditor
1814     #  \n If there is not element for given ID - returns -1
1815     def GetShapeIDForElem(id):
1816         return self.mesh.GetShapeIDForElem(id)
1817     
1818     ## Returns number of nodes for given element
1819     #  \n If there is not element for given ID - returns -1
1820     def GetElemNbNodes(self, id):
1821         return self.mesh.GetElemNbNodes(id)
1822
1823     ## Returns ID of node by given index for given element
1824     #  \n If there is not element for given ID - returns -1
1825     #  \n If there is not node for given index - returns -2
1826     def GetElemNode(self, id, index):
1827         return self.mesh.GetElemNode(id, index)
1828
1829     ## Returns true if given node is medium node
1830     #  in given quadratic element
1831     def IsMediumNode(self, elementID, nodeID):
1832         return self.mesh.IsMediumNode(elementID, nodeID)
1833     
1834     ## Returns true if given node is medium node
1835     #  in one of quadratic elements
1836     def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1837         return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1838
1839     ## Returns number of edges for given element
1840     def ElemNbEdges(self, id):
1841         return self.mesh.ElemNbEdges(id)
1842         
1843     ## Returns number of faces for given element
1844     def ElemNbFaces(self, id):
1845         return self.mesh.ElemNbFaces(id)
1846
1847     ## Returns true if given element is polygon
1848     def IsPoly(self, id):
1849         return self.mesh.IsPoly(id)
1850
1851     ## Returns true if given element is quadratic
1852     def IsQuadratic(self, id):
1853         return self.mesh.IsQuadratic(id)
1854
1855     ## Returns XYZ coordinates of bary center for given element
1856     #  as list of double
1857     #  \n If there is not element for given ID - returns empty list
1858     def BaryCenter(self, id):
1859         return self.mesh.BaryCenter(id)
1860     
1861     
1862     # Mesh edition (SMESH_MeshEditor functionality):
1863     # ---------------------------------------------
1864
1865     ## Removes elements from mesh by ids
1866     #  @param IDsOfElements is list of ids of elements to remove
1867     def RemoveElements(self, IDsOfElements):
1868         return self.editor.RemoveElements(IDsOfElements)
1869
1870     ## Removes nodes from mesh by ids
1871     #  @param IDsOfNodes is list of ids of nodes to remove
1872     def RemoveNodes(self, IDsOfNodes):
1873         return self.editor.RemoveNodes(IDsOfNodes)
1874
1875     ## Add node to mesh by coordinates
1876     def AddNode(self, x, y, z):
1877         return self.editor.AddNode( x, y, z)
1878
1879     
1880     ## Create edge both similar and quadratic (this is determed
1881     #  by number of given nodes).
1882     #  @param IdsOfNodes List of node IDs for creation of element.
1883     #  Needed order of nodes in this list corresponds to description
1884     #  of MED. \n This description is located by the following link:
1885     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1886     def AddEdge(self, IDsOfNodes):
1887         return self.editor.AddEdge(IDsOfNodes)
1888
1889     ## Create face both similar and quadratic (this is determed
1890     #  by number of given nodes).
1891     #  @param IdsOfNodes List of node IDs for creation of element.
1892     #  Needed order of nodes in this list corresponds to description
1893     #  of MED. \n This description is located by the following link:
1894     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1895     def AddFace(self, IDsOfNodes):
1896         return self.editor.AddFace(IDsOfNodes)
1897     
1898     ## Add polygonal face to mesh by list of nodes ids
1899     def AddPolygonalFace(self, IdsOfNodes):
1900         return self.editor.AddPolygonalFace(IdsOfNodes)
1901     
1902     ## Create volume both similar and quadratic (this is determed
1903     #  by number of given nodes).
1904     #  @param IdsOfNodes List of node IDs for creation of element.
1905     #  Needed order of nodes in this list corresponds to description
1906     #  of MED. \n This description is located by the following link:
1907     #  http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1908     def AddVolume(self, IDsOfNodes):
1909         return self.editor.AddVolume(IDsOfNodes)
1910
1911     ## Create volume of many faces, giving nodes for each face.
1912     #  @param IdsOfNodes List of node IDs for volume creation face by face.
1913     #  @param Quantities List of integer values, Quantities[i]
1914     #         gives quantity of nodes in face number i.
1915     def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1916         return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1917
1918     ## Create volume of many faces, giving IDs of existing faces.
1919     #  @param IdsOfFaces List of face IDs for volume creation.
1920     #
1921     #  Note:  The created volume will refer only to nodes
1922     #         of the given faces, not to the faces itself.
1923     def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1924         return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1925     
1926     ## Move node with given id
1927     #  @param NodeID id of the node
1928     #  @param x new X coordinate
1929     #  @param y new Y coordinate
1930     #  @param z new Z coordinate
1931     def MoveNode(self, NodeID, x, y, z):
1932         return self.editor.MoveNode(NodeID, x, y, z)
1933
1934     ## Find a node closest to a point
1935     #  @param x X coordinate of a point
1936     #  @param y Y coordinate of a point
1937     #  @param z Z coordinate of a point
1938     #  @return id of a node
1939     def FindNodeClosestTo(self, x, y, z):
1940         preview = self.mesh.GetMeshEditPreviewer()
1941         return preview.MoveClosestNodeToPoint(x, y, z, -1)
1942
1943     ## Find a node closest to a point and move it to a point location
1944     #  @param x X coordinate of a point
1945     #  @param y Y coordinate of a point
1946     #  @param z Z coordinate of a point
1947     #  @return id of a moved node
1948     def MeshToPassThroughAPoint(self, x, y, z):
1949         return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1950
1951     ## Replace two neighbour triangles sharing Node1-Node2 link
1952     #  with ones built on the same 4 nodes but having other common link.
1953     #  @param NodeID1 first node id
1954     #  @param NodeID2 second node id
1955     #  @return false if proper faces not found
1956     def InverseDiag(self, NodeID1, NodeID2):
1957         return self.editor.InverseDiag(NodeID1, NodeID2)
1958
1959     ## Replace two neighbour triangles sharing Node1-Node2 link
1960     #  with a quadrangle built on the same 4 nodes.
1961     #  @param NodeID1 first node id
1962     #  @param NodeID2 second node id
1963     #  @return false if proper faces not found
1964     def DeleteDiag(self, NodeID1, NodeID2):
1965         return self.editor.DeleteDiag(NodeID1, NodeID2)
1966
1967     ## Reorient elements by ids
1968     #  @param IDsOfElements if undefined reorient all mesh elements
1969     def Reorient(self, IDsOfElements=None):
1970         if IDsOfElements == None:
1971             IDsOfElements = self.GetElementsId()
1972         return self.editor.Reorient(IDsOfElements)
1973
1974     ## Reorient all elements of the object
1975     #  @param theObject is mesh, submesh or group
1976     def ReorientObject(self, theObject):
1977         return self.editor.ReorientObject(theObject)
1978
1979     ## Fuse neighbour triangles into quadrangles.
1980     #  @param IDsOfElements The triangles to be fused,
1981     #  @param theCriterion     is FT_...; used to choose a neighbour to fuse with.
1982     #  @param MaxAngle      is a max angle between element normals at which fusion
1983     #                       is still performed; theMaxAngle is mesured in radians.
1984     #  @return TRUE in case of success, FALSE otherwise.
1985     def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1986         if IDsOfElements == []:
1987             IDsOfElements = self.GetElementsId()
1988         return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1989
1990     ## Fuse neighbour triangles of the object into quadrangles
1991     #  @param theObject is mesh, submesh or group
1992     #  @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1993     #  @param MaxAngle  is a max angle between element normals at which fusion
1994     #                   is still performed; theMaxAngle is mesured in radians.
1995     #  @return TRUE in case of success, FALSE otherwise.
1996     def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1997         return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1998
1999     ## Split quadrangles into triangles.
2000     #  @param IDsOfElements the faces to be splitted.
2001     #  @param theCriterion  is FT_...; used to choose a diagonal for splitting.
2002     #  @param @return TRUE in case of success, FALSE otherwise.
2003     def QuadToTri (self, IDsOfElements, theCriterion):
2004         if IDsOfElements == []:
2005             IDsOfElements = self.GetElementsId()
2006         return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
2007
2008     ## Split quadrangles into triangles.
2009     #  @param theObject object to taking list of elements from, is mesh, submesh or group
2010     #  @param theCriterion  is FT_...; used to choose a diagonal for splitting.
2011     def QuadToTriObject (self, theObject, theCriterion):
2012         return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
2013
2014     ## Split quadrangles into triangles.
2015     #  @param theElems  The faces to be splitted
2016     #  @param the13Diag is used to choose a diagonal for splitting.
2017     #  @return TRUE in case of success, FALSE otherwise.
2018     def SplitQuad (self, IDsOfElements, Diag13):
2019         if IDsOfElements == []:
2020             IDsOfElements = self.GetElementsId()
2021         return self.editor.SplitQuad(IDsOfElements, Diag13)
2022
2023     ## Split quadrangles into triangles.
2024     #  @param theObject is object to taking list of elements from, is mesh, submesh or group
2025     def SplitQuadObject (self, theObject, Diag13):
2026         return self.editor.SplitQuadObject(theObject, Diag13)
2027
2028     ## Find better splitting of the given quadrangle.
2029     #  @param IDOfQuad  ID of the quadrangle to be splitted.
2030     #  @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2031     #  @return 1 if 1-3 diagonal is better, 2 if 2-4
2032     #          diagonal is better, 0 if error occurs.
2033     def BestSplit (self, IDOfQuad, theCriterion):
2034         return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2035
2036     ## Split quafrangle faces near triangular facets of volumes
2037     #
2038     def SplitQuadsNearTriangularFacets(self):
2039         faces_array = self.GetElementsByType(SMESH.FACE)
2040         for face_id in faces_array:
2041             if self.GetElemNbNodes(face_id) == 4: # quadrangle
2042                 quad_nodes = self.mesh.GetElemNodes(face_id)
2043                 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2044                 isVolumeFound = False
2045                 for node1_elem in node1_elems:
2046                     if not isVolumeFound:
2047                         if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2048                             nb_nodes = self.GetElemNbNodes(node1_elem)
2049                             if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2050                                 volume_elem = node1_elem
2051                                 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2052                                 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2053                                     if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2054                                         isVolumeFound = True
2055                                         if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2056                                             self.SplitQuad([face_id], False) # diagonal 2-4
2057                                     elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2058                                         isVolumeFound = True
2059                                         self.SplitQuad([face_id], True) # diagonal 1-3
2060                                 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2061                                     if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2062                                         isVolumeFound = True
2063                                         self.SplitQuad([face_id], True) # diagonal 1-3
2064
2065     ## @brief Split hexahedrons into tetrahedrons.
2066     #
2067     #  Use pattern mapping functionality for splitting.
2068     #  @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2069     #  @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2070     #         pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2071     #         will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2072     #         key-point will be mapped into <theNode001>-th node of each volume.
2073     #         The (0,0,0) key-point of used pattern corresponds to not split corner.
2074     #  @param @return TRUE in case of success, FALSE otherwise.
2075     def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2076         # Pattern:     5.---------.6
2077         #              /|#*      /|
2078         #             / | #*    / |
2079         #            /  |  # * /  |
2080         #           /   |   # /*  |
2081         # (0,0,1) 4.---------.7 * |
2082         #          |#*  |1   | # *|
2083         #          | # *.----|---#.2
2084         #          |  #/ *   |   /
2085         #          |  /#  *  |  /
2086         #          | /   # * | /
2087         #          |/      #*|/
2088         # (0,0,0) 0.---------.3
2089         pattern_tetra = "!!! Nb of points: \n 8 \n\
2090         !!! Points: \n\
2091         0 0 0  !- 0 \n\
2092         0 1 0  !- 1 \n\
2093         1 1 0  !- 2 \n\
2094         1 0 0  !- 3 \n\
2095         0 0 1  !- 4 \n\
2096         0 1 1  !- 5 \n\
2097         1 1 1  !- 6 \n\
2098         1 0 1  !- 7 \n\
2099         !!! Indices of points of 6 tetras: \n\
2100         0 3 4 1 \n\
2101         7 4 3 1 \n\
2102         4 7 5 1 \n\
2103         6 2 5 7 \n\
2104         1 5 2 7 \n\
2105         2 3 1 7 \n"
2106
2107         pattern = GetPattern()
2108         isDone  = pattern.LoadFromFile(pattern_tetra)
2109         if not isDone:
2110             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2111             return isDone
2112
2113         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2114         isDone = pattern.MakeMesh(self.mesh, False, False)
2115         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2116
2117         # split quafrangle faces near triangular facets of volumes
2118         self.SplitQuadsNearTriangularFacets()
2119
2120         return isDone
2121
2122     ## @brief Split hexahedrons into prisms.
2123     #
2124     #  Use pattern mapping functionality for splitting.
2125     #  @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2126     #  @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2127     #         pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2128     #         will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2129     #         key-point will be mapped into <theNode001>-th node of each volume.
2130     #         The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2131     #  @param @return TRUE in case of success, FALSE otherwise.
2132     def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2133         # Pattern:     5.---------.6
2134         #              /|#       /|
2135         #             / | #     / |
2136         #            /  |  #   /  |
2137         #           /   |   # /   |
2138         # (0,0,1) 4.---------.7   |
2139         #          |    |    |    |
2140         #          |   1.----|----.2
2141         #          |   / *   |   /
2142         #          |  /   *  |  /
2143         #          | /     * | /
2144         #          |/       *|/
2145         # (0,0,0) 0.---------.3
2146         pattern_prism = "!!! Nb of points: \n 8 \n\
2147         !!! Points: \n\
2148         0 0 0  !- 0 \n\
2149         0 1 0  !- 1 \n\
2150         1 1 0  !- 2 \n\
2151         1 0 0  !- 3 \n\
2152         0 0 1  !- 4 \n\
2153         0 1 1  !- 5 \n\
2154         1 1 1  !- 6 \n\
2155         1 0 1  !- 7 \n\
2156         !!! Indices of points of 2 prisms: \n\
2157         0 1 3 4 5 7 \n\
2158         2 3 1 6 7 5 \n"
2159
2160         pattern = GetPattern()
2161         isDone  = pattern.LoadFromFile(pattern_prism)
2162         if not isDone:
2163             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2164             return isDone
2165
2166         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2167         isDone = pattern.MakeMesh(self.mesh, False, False)
2168         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2169
2170         # split quafrangle faces near triangular facets of volumes
2171         self.SplitQuadsNearTriangularFacets()
2172
2173         return isDone
2174     
2175     ## Smooth elements
2176     #  @param IDsOfElements list if ids of elements to smooth
2177     #  @param IDsOfFixedNodes list of ids of fixed nodes.
2178     #  Note that nodes built on edges and boundary nodes are always fixed.
2179     #  @param MaxNbOfIterations maximum number of iterations
2180     #  @param MaxAspectRatio varies in range [1.0, inf]
2181     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2182     def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2183                MaxNbOfIterations, MaxAspectRatio, Method):
2184         if IDsOfElements == []:
2185             IDsOfElements = self.GetElementsId()
2186         return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2187                                   MaxNbOfIterations, MaxAspectRatio, Method)
2188     
2189     ## Smooth elements belong to given object
2190     #  @param theObject object to smooth
2191     #  @param IDsOfFixedNodes list of ids of fixed nodes.
2192     #  Note that nodes built on edges and boundary nodes are always fixed.
2193     #  @param MaxNbOfIterations maximum number of iterations
2194     #  @param MaxAspectRatio varies in range [1.0, inf]
2195     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2196     def SmoothObject(self, theObject, IDsOfFixedNodes, 
2197                      MaxNbOfIterations, MaxxAspectRatio, Method):
2198         return self.editor.SmoothObject(theObject, IDsOfFixedNodes, 
2199                                         MaxNbOfIterations, MaxxAspectRatio, Method)
2200
2201     ## Parametric smooth the given elements
2202     #  @param IDsOfElements list if ids of elements to smooth
2203     #  @param IDsOfFixedNodes list of ids of fixed nodes.
2204     #  Note that nodes built on edges and boundary nodes are always fixed.
2205     #  @param MaxNbOfIterations maximum number of iterations
2206     #  @param MaxAspectRatio varies in range [1.0, inf]
2207     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2208     def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2209                          MaxNbOfIterations, MaxAspectRatio, Method):
2210         if IDsOfElements == []:
2211             IDsOfElements = self.GetElementsId()
2212         return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2213                                             MaxNbOfIterations, MaxAspectRatio, Method)
2214     
2215     ## Parametric smooth elements belong to given object
2216     #  @param theObject object to smooth
2217     #  @param IDsOfFixedNodes list of ids of fixed nodes.
2218     #  Note that nodes built on edges and boundary nodes are always fixed.
2219     #  @param MaxNbOfIterations maximum number of iterations
2220     #  @param MaxAspectRatio varies in range [1.0, inf]
2221     #  @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2222     def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2223                                MaxNbOfIterations, MaxAspectRatio, Method):
2224         return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2225                                                   MaxNbOfIterations, MaxAspectRatio, Method)
2226
2227     ## Converts all mesh to quadratic one, deletes old elements, replacing 
2228     #  them with quadratic ones with the same id.
2229     def ConvertToQuadratic(self, theForce3d):
2230         self.editor.ConvertToQuadratic(theForce3d)
2231
2232     ## Converts all mesh from quadratic to ordinary ones,
2233     #  deletes old quadratic elements, \n replacing 
2234     #  them with ordinary mesh elements with the same id.
2235     def ConvertFromQuadratic(self):
2236         return self.editor.ConvertFromQuadratic()
2237
2238     ## Renumber mesh nodes
2239     def RenumberNodes(self):
2240         self.editor.RenumberNodes()
2241
2242     ## Renumber mesh elements
2243     def RenumberElements(self):
2244         self.editor.RenumberElements()
2245
2246     ## Generate new elements by rotation of the elements around the axis
2247     #  @param IDsOfElements list of ids of elements to sweep
2248     #  @param Axix axis of rotation, AxisStruct or line(geom object)
2249     #  @param AngleInRadians angle of Rotation
2250     #  @param NbOfSteps number of steps
2251     #  @param Tolerance tolerance
2252     def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2253         if IDsOfElements == []:
2254             IDsOfElements = self.GetElementsId()
2255         if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2256             Axix = GetAxisStruct(Axix)
2257         self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2258
2259     ## Generate new elements by rotation of the elements of object around the axis
2260     #  @param theObject object wich elements should be sweeped
2261     #  @param Axix axis of rotation, AxisStruct or line(geom object)
2262     #  @param AngleInRadians angle of Rotation
2263     #  @param NbOfSteps number of steps
2264     #  @param Tolerance tolerance
2265     def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2266         if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2267             Axix = GetAxisStruct(Axix)
2268         self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2269
2270     ## Generate new elements by extrusion of the elements with given ids
2271     #  @param IDsOfElements list of elements ids for extrusion
2272     #  @param StepVector vector, defining the direction and value of extrusion 
2273     #  @param NbOfSteps the number of steps
2274     def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2275         if IDsOfElements == []:
2276             IDsOfElements = self.GetElementsId()
2277         if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2278             StepVector = GetDirStruct(StepVector)
2279         self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2280
2281     ## Generate new elements by extrusion of the elements with given ids
2282     #  @param IDsOfElements is ids of elements
2283     #  @param StepVector vector, defining the direction and value of extrusion 
2284     #  @param NbOfSteps the number of steps
2285     #  @param ExtrFlags set flags for performing extrusion
2286     #  @param SewTolerance uses for comparing locations of nodes if flag
2287     #         EXTRUSION_FLAG_SEW is set
2288     def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2289         if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2290             StepVector = GetDirStruct(StepVector)
2291         self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2292
2293     ## Generate new elements by extrusion of the elements belong to object
2294     #  @param theObject object wich elements should be processed
2295     #  @param StepVector vector, defining the direction and value of extrusion 
2296     #  @param NbOfSteps the number of steps
2297     def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2298         if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2299             StepVector = GetDirStruct(StepVector)
2300         self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2301
2302     ## Generate new elements by extrusion of the elements belong to object
2303     #  @param theObject object wich elements should be processed
2304     #  @param StepVector vector, defining the direction and value of extrusion 
2305     #  @param NbOfSteps the number of steps
2306     def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2307         if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2308             StepVector = GetDirStruct(StepVector)
2309         self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2310     
2311     ## Generate new elements by extrusion of the elements belong to object
2312     #  @param theObject object wich elements should be processed
2313     #  @param StepVector vector, defining the direction and value of extrusion 
2314     #  @param NbOfSteps the number of steps    
2315     def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2316         if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2317             StepVector = GetDirStruct(StepVector)
2318         self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2319
2320     ## Generate new elements by extrusion of the given elements
2321     #  A path of extrusion must be a meshed edge.
2322     #  @param IDsOfElements is ids of elements
2323     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2324     #  @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2325     #  @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2326     #  @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2327     #  @param Angles list of angles
2328     #  @param HasRefPoint allows to use base point 
2329     #  @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2330     #         User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2331     #  @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2332     def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2333                            HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2334         if IDsOfElements == []:
2335             IDsOfElements = self.GetElementsId()
2336         if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2337             RefPoint = GetPointStruct(RefPoint)
2338             pass
2339         return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2340                                               HasAngles, Angles, HasRefPoint, RefPoint)
2341
2342     ## Generate new elements by extrusion of the elements belong to object
2343     #  A path of extrusion must be a meshed edge.
2344     #  @param IDsOfElements is ids of elements
2345     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2346     #  @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2347     #  @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2348     #  @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2349     #  @param Angles list of angles
2350     #  @param HasRefPoint allows to use base point 
2351     #  @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2352     #         User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2353     #  @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2354     def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2355                                  HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2356         if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2357             RefPoint = GetPointStruct(RefPoint) 
2358         return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2359                                                     HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation)
2360     
2361     ## Symmetrical copy of mesh elements
2362     #  @param IDsOfElements list of elements ids
2363     #  @param Mirror is AxisStruct or geom object(point, line, plane)
2364     #  @param theMirrorType is  POINT, AXIS or PLANE
2365     #  If the Mirror is geom object this parameter is unnecessary
2366     #  @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2367     def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2368         if IDsOfElements == []:
2369             IDsOfElements = self.GetElementsId()
2370         if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2371             Mirror = GetAxisStruct(Mirror)
2372         self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2373
2374     ## Symmetrical copy of object
2375     #  @param theObject mesh, submesh or group
2376     #  @param Mirror is AxisStruct or geom object(point, line, plane)
2377     #  @param theMirrorType is  POINT, AXIS or PLANE
2378     #  If the Mirror is geom object this parameter is unnecessary
2379     #  @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2380     def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2381         if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2382             Mirror = GetAxisStruct(Mirror)
2383         self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2384
2385     ## Translates the elements
2386     #  @param IDsOfElements list of elements ids
2387     #  @param Vector direction of translation(DirStruct or vector)
2388     #  @param Copy allows to copy the translated elements
2389     def Translate(self, IDsOfElements, Vector, Copy):
2390         if IDsOfElements == []:
2391             IDsOfElements = self.GetElementsId()
2392         if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2393             Vector = GetDirStruct(Vector)
2394         self.editor.Translate(IDsOfElements, Vector, Copy)
2395
2396     ## Translates the object
2397     #  @param theObject object to translate(mesh, submesh, or group)
2398     #  @param Vector direction of translation(DirStruct or geom vector)
2399     #  @param Copy allows to copy the translated elements
2400     def TranslateObject(self, theObject, Vector, Copy):
2401         if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2402             Vector = GetDirStruct(Vector)
2403         self.editor.TranslateObject(theObject, Vector, Copy)
2404
2405     ## Rotates the elements
2406     #  @param IDsOfElements list of elements ids
2407     #  @param Axis axis of rotation(AxisStruct or geom line)
2408     #  @param AngleInRadians angle of rotation(in radians)
2409     #  @param Copy allows to copy the rotated elements   
2410     def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2411         if IDsOfElements == []:
2412             IDsOfElements = self.GetElementsId()
2413         if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2414             Axis = GetAxisStruct(Axis)
2415         self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2416
2417     ## Rotates the object
2418     #  @param theObject object to rotate(mesh, submesh, or group)
2419     #  @param Axis axis of rotation(AxisStruct or geom line)
2420     #  @param AngleInRadians angle of rotation(in radians)
2421     #  @param Copy allows to copy the rotated elements
2422     def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2423         self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2424
2425     ## Find group of nodes close to each other within Tolerance.
2426     #  @param Tolerance tolerance value
2427     #  @param list of group of nodes
2428     def FindCoincidentNodes (self, Tolerance):
2429         return self.editor.FindCoincidentNodes(Tolerance)
2430
2431     ## Find group of nodes close to each other within Tolerance.
2432     #  @param Tolerance tolerance value
2433     #  @param SubMeshOrGroup SubMesh or Group
2434     #  @param list of group of nodes
2435     def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2436         return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2437
2438     ## Merge nodes
2439     #  @param list of group of nodes
2440     def MergeNodes (self, GroupsOfNodes):
2441         self.editor.MergeNodes(GroupsOfNodes)
2442
2443     ## Find elements built on the same nodes.
2444     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2445     #  @return a list of groups of equal elements
2446     def FindEqualElements (self, MeshOrSubMeshOrGroup):
2447         return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2448
2449     ## Merge elements in each given group.
2450     #  @param GroupsOfElementsID groups of elements for merging
2451     def MergeElements(self, GroupsOfElementsID):
2452         self.editor.MergeElements(GroupsOfElementsID)
2453
2454     ## Remove all but one of elements built on the same nodes.
2455     def MergeEqualElements(self):
2456         self.editor.MergeEqualElements()
2457         
2458     ## Sew free borders
2459     def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2460                         FirstNodeID2, SecondNodeID2, LastNodeID2,
2461                         CreatePolygons, CreatePolyedrs):
2462         return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2463                                           FirstNodeID2, SecondNodeID2, LastNodeID2,
2464                                           CreatePolygons, CreatePolyedrs)
2465
2466     ## Sew conform free borders
2467     def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2468                                FirstNodeID2, SecondNodeID2):
2469         return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2470                                                  FirstNodeID2, SecondNodeID2)
2471     
2472     ## Sew border to side
2473     def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2474                          FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2475         return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2476                                            FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2477
2478     ## Sew two sides of a mesh. Nodes belonging to Side1 are
2479     #  merged with nodes of elements of Side2.
2480     #  Number of elements in theSide1 and in theSide2 must be
2481     #  equal and they should have similar node connectivity.
2482     #  The nodes to merge should belong to sides borders and
2483     #  the first node should be linked to the second.
2484     def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2485                          NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2486                          NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2487         return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2488                                            NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2489                                            NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2490
2491     ## Set new nodes for given element.
2492     #  @param ide the element id
2493     #  @param newIDs nodes ids
2494     #  @return If number of nodes is not corresponded to type of element - returns false
2495     def ChangeElemNodes(self, ide, newIDs):
2496         return self.editor.ChangeElemNodes(ide, newIDs)
2497     
2498     ## If during last operation of MeshEditor some nodes were
2499     #  created this method returns list of it's IDs, \n
2500     #  if new nodes not created - returns empty list
2501     def GetLastCreatedNodes(self):
2502         return self.editor.GetLastCreatedNodes()
2503
2504     ## If during last operation of MeshEditor some elements were
2505     #  created this method returns list of it's IDs, \n
2506     #  if new elements not creared - returns empty list
2507     def GetLastCreatedElems(self):
2508         return self.editor.GetLastCreatedElems()