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