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