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