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