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