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