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