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