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