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