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