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