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