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