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