Salome HOME
cf659380ea586a9955552f2c444816d5b3dbad17
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPluginBuilder.py
1 # Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 ##
21 # @package BLSURFPluginBuilder
22 # Python API for the MG-CADSurf meshing plug-in module.
23
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 import GEOM
26
27 LIBRARY = "libBLSURFEngine.so"
28
29 # ElementType enum
30 Triangles, QuadrangleDominant, Quadrangles = 0, 1, 2
31
32 # Topology treatment way of MG-CADSurf
33 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
34
35 # Element size flag of MG-CADSurf
36 DefaultSize, DefaultGeom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize = 0,0,1,2
37 # Retrocompatibility
38 MG_CADSURF_Custom, SizeMap = MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
39 BLSURF_Custom, BLSURF_GlobalSize, BLSURF_LocalSize = MG_CADSURF_Custom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
40
41 # import BLSURFPlugin module if possible
42 noBLSURFPlugin = 0
43 try:
44   import BLSURFPlugin
45 except ImportError:
46   noBLSURFPlugin = 1
47   pass
48
49 #----------------------------
50 # Mesh algo type identifiers
51 #----------------------------
52
53 ## Algorithm type: MG-CADSurf triangle algorithm, see BLSURF_Algorithm
54 MG_CADSurf = "MG-CADSurf"
55 BLSURF = MG_CADSurf
56
57 #----------------------
58 # Algorithms
59 #----------------------
60
61 ## MG-CADSurf 2D algorithm.
62 #
63 #  It can be created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MG-CADSurf,geom=0)
64 #
65 class BLSURF_Algorithm(Mesh_Algorithm):
66
67   ## name of the dynamic method in smeshBuilder.Mesh class
68   #  @internal
69   meshMethod = "Triangle"
70   ## type of algorithm used with helper function in smeshBuilder.Mesh class
71   #  @internal
72   algoType   = MG_CADSurf
73   ## doc string of the method
74   #  @internal
75   docHelper  = "Creates triangle algorithm for faces"
76
77   _anisotropic_ratio = 0
78   _bad_surface_element_aspect_ratio = 1000
79   _geometric_approximation = 22
80   _gradation  = 1.3
81   _volume_gradation  = 2
82   _metric = "isotropic"
83   _remove_tiny_edges = 0
84
85   ## Private constructor.
86   #  @param mesh parent mesh object algorithm is assigned to
87   #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
88   #              if it is @c 0 (default), the algorithm is assigned to the main shape
89   def __init__(self, mesh, geom=0):
90     Mesh_Algorithm.__init__(self)
91     if noBLSURFPlugin:
92       print("Warning: BLSURFPlugin module unavailable")
93     if mesh.GetMesh().HasShapeToMesh():
94       self.Create(mesh, geom, self.algoType, LIBRARY)
95     else:
96       self.Create(mesh, geom, self.algoType+"_NOGEOM", LIBRARY)
97       mesh.smeshpyD.SetName( self.algo, self.algoType )
98     self.params=None
99     self.geompyD = mesh.geompyD
100     #self.SetPhysicalMesh() - PAL19680
101     pass
102
103   ## Sets a way to define size of mesh elements to generate.
104   #  @param thePhysicalMesh is: DefaultSize, MG_CADSURF_Custom or SizeMap.
105   def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
106     physical_size_mode = thePhysicalMesh
107     if self.Parameters().GetGeometricMesh() == DefaultGeom:
108       if physical_size_mode == DefaultSize:
109         physical_size_mode = MG_CADSURF_GlobalSize
110     self.Parameters().SetPhysicalMesh(physical_size_mode)
111     pass
112
113   ## Sets a way to define maximum angular deflection of mesh from CAD model.
114   #  @param theGeometricMesh is: DefaultGeom (0)) or MG_CADSURF_GlobalSize (1))
115   def SetGeometricMesh(self, theGeometricMesh=DefaultGeom):
116     geometric_size_mode = theGeometricMesh
117     if self.Parameters().GetPhysicalMesh() == DefaultSize:
118       if geometric_size_mode == DefaultGeom:
119         geometric_size_mode = MG_CADSURF_GlobalSize
120     self.Parameters().SetGeometricMesh(geometric_size_mode)
121     pass
122
123   ## Sets size of mesh elements to generate.
124   #  @param theVal : constant global size when using a global physical size.
125   #  @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
126   def SetPhySize(self, theVal, isRelative = False):
127     if self.Parameters().GetPhysicalMesh() == DefaultSize:
128       self.SetPhysicalMesh(MG_CADSURF_GlobalSize)
129     if isRelative:
130       self.Parameters().SetPhySizeRel(theVal)
131     else:
132       self.Parameters().SetPhySize(theVal)
133     pass
134
135   ## Sets lower boundary of mesh element size.
136   #  @param theVal : global minimal cell size desired.
137   #  @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
138   def SetMinSize(self, theVal=-1, isRelative = False):
139     if isRelative:
140       self.Parameters().SetMinSizeRel(theVal)
141     else:
142       self.Parameters().SetMinSize(theVal)
143     pass
144
145   ## Sets upper boundary of mesh element size.
146   #  @param theVal : global maximal cell size desired.
147   #  @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
148   def SetMaxSize(self, theVal=-1, isRelative = False):
149     if isRelative:
150       self.Parameters().SetMaxSizeRel(theVal)
151     else:
152       self.Parameters().SetMaxSize(theVal)
153     pass
154
155   ## Sets angular deflection (in degrees) from CAD surface.
156   #  @param theVal value of angular deflection
157   def SetAngleMesh(self, theVal=_geometric_approximation):
158     if self.Parameters().GetGeometricMesh() == DefaultGeom:
159       self.SetGeometricMesh(MG_CADSURF_GlobalSize)
160     self.Parameters().SetAngleMesh(theVal)
161     pass
162
163   ## Sets the maximum desired distance between a triangle and its supporting CAD surface
164   #  @param distance the distance between a triangle and a surface
165   def SetChordalError(self, distance):
166     self.Parameters().SetChordalError(distance)
167     pass
168
169   ## Sets maximal allowed ratio between the lengths of two adjacent edges.
170   #  @param toUseGradation to use gradation
171   #  @param theVal value of maximal length ratio
172   def SetGradation(self, toUseGradation=True, theVal=_gradation):
173     if isinstance( toUseGradation, float ): ## backward compatibility
174       toUseGradation, theVal = True, toUseGradation
175     if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
176     self.Parameters().SetUseGradation(toUseGradation)
177     self.Parameters().SetGradation(theVal)
178     pass
179
180   ## Sets maximal allowed ratio between the lengths of two adjacent edges in 3D mesh.
181   #  @param toUseGradation to use gradation
182   #  @param theVal value of maximal length ratio
183   def SetVolumeGradation(self, toUseGradation=True, theVal=_gradation):
184     if self.Parameters().GetGeometricMesh() == 0: theVal = self._volume_gradation
185     self.Parameters().SetUseVolumeGradation(toUseGradation)
186     self.Parameters().SetVolumeGradation(theVal)
187     pass
188
189   ## Sets topology usage way.
190   # @param way defines how mesh conformity is assured <ul>
191   # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
192   # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model (OBSOLETE: FromCAD will be used)</li>
193   # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
194   def SetTopology(self, way):
195     if way != PreCAD and way != FromCAD:
196       print("Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way)
197       way = FromCAD
198     self.Parameters().SetTopology(way)
199     pass
200
201   ## Activate/deactivate surface proximity computation
202   # @param toUse boolean flag
203   #
204   def SetSurfaceProximity(self, toUse ):
205     self.Parameters().SetSurfaceProximity(toUse)
206     return
207
208   ## Set number of surface element layers to be generated due to surface proximity
209   # @param nbLayers number of layers
210   #
211   def SetNbSurfaceProximityLayers(self, nbLayers ):
212     self.Parameters().SetNbSurfaceProximityLayers( nbLayers )
213     return
214
215   ## Set coefficient by which size of element refined due to surface proximity is increased
216   # @param ratio proximity coefficient
217   #
218   def SetSurfaceProximityRatio(self, ratio ):
219     self.Parameters().SetSurfaceProximityRatio(ratio)
220     return
221   
222   ## Activate/deactivate volume proximity computation
223   # @param toUse boolean flag
224   #
225   def SetVolumeProximity(self, toUse ):
226     self.Parameters().SetVolumeProximity(toUse)
227     return
228   
229   ## Set number of surface element layers to be generated due to volume proximity
230   # @param nbLayers number of layers
231   #
232   def SetNbVolumeProximityLayers(self, nbLayers ):
233     self.Parameters().SetNbVolumeProximityLayers(nbLayers)
234     return
235
236   ## Set coefficient by which size of element refined due to volume proximity is increased
237   # @param ratio proximity coefficient
238   #
239   def SetVolumeProximityRatio(self, ratio ):
240     self.Parameters().SetVolumeProximityRatio(ratio)
241     return
242
243
244   ## Sets verbosity level in the range 0 to 100.
245   #  @param level verbosity level
246   def SetVerbosity(self, level):
247     self.Parameters().SetVerbosity(level)
248     pass
249
250   ## Set enforce_cad_edge_sizes parameter
251   #  
252   #  Relaxes the given sizemap constraint around CAD edges to allow a better
253   #  element quality and a better geometric approximation. It is only useful in 
254   #  combination with the gradation option.
255   #  
256   def SetEnforceCadEdgesSize( self, toEnforce ):
257     self.Parameters().SetEnforceCadEdgesSize( toEnforce )
258
259   ## Set jacobian_rectification_respect_geometry parameter
260   #  
261   #  While making the mesh quadratic, allows to lose the CAD-mesh associativity in order
262   #  to correct elements with nagative Jacobian
263   #  
264   def SetJacobianRectificationRespectGeometry( self, allowRectification ):
265     self.Parameters().SetJacobianRectificationRespectGeometry( allowRectification )
266     
267   ## Set rectify_jacobian parameter
268   #  
269   #  While making the mesh quadratic, allow to fix nagative Jacobian surface elements
270   #  
271   def SetJacobianRectification( self, allowRectification ):
272     self.Parameters().SetJacobianRectification( allowRectification )
273
274   ## Set use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
275   #  
276   # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
277   # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
278   #  
279   def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
280     self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
281
282   ## Set respect_geometry parameter
283   #  
284   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
285   #  to lower the geometry accuracy in its patch independent process.
286   #  
287   def SetRespectGeometry( self, toRespect ):
288     self.Parameters().SetRespectGeometry( toRespect )
289
290   ## Set max_number_of_points_per_patch parameter
291   #  
292   #  This parameter controls the maximum amount of points MeshGems-CADSurf is allowed
293   #  to generate on a single CAD patch. For an automatic gestion of the memory, one
294   #  can set this parameter to 0
295   #  
296   def SetMaxNumberOfPointsPerPatch( self, nb ):
297     self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
298
299   ## Set max_number_of_threads parameter
300   #
301   #  Set the maximum of threads to use for multithreading mesh computation
302   #
303   def SetMaxNumberOfThreads( self, nb ):
304     self.Parameters().SetMaxNumberOfThreads( nb )
305
306   ## Set respect_geometry parameter
307   #  
308   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
309   #  to lower the geometry accuracy in its patch independent process.
310   #  
311   def SetRespectGeometry( self, toRespect ):
312     self.Parameters().SetRespectGeometry( toRespect )
313
314   ## Set tiny_edges_avoid_surface_intersections parameter
315   #  
316   #  This option defines the priority between the tiny feature
317   #  suppression and the surface intersection prevention. 
318   #  
319   def SetTinyEdgesAvoidSurfaceIntersections( self, toAvoidIntersection ):
320     self.Parameters().SetTinyEdgesAvoidSurfaceIntersections( toAvoidIntersection )
321
322   ## Set closed_geometry parameter parameter
323   #  
324   #  Describes whether the geometry is expected to be closed or not. 
325   #  When activated, this option helps MeshGems-PreCAD to treat the dirtiest geometries.
326   #  
327   def SetClosedGeometry( self, isClosed ):
328     self.Parameters().SetClosedGeometry( isClosed )
329
330   ## Set debug parameter
331   #  
332   #  Make MeshGems-CADSurf will be very verbose and will output some intermediate
333   #  files in the working directory. This option is mainly meant for Distene support issues.
334   #  
335   def SetDebug( self, isDebug ):
336     self.Parameters().SetDebug( isDebug )
337
338   ## Set periodic_tolerance parameter
339   #  
340   #  This parameter defines the maximum size difference between two periodic edges
341   #  and also the maximum distance error between two periodic entities.
342   #  
343   def SetPeriodicTolerance( self, tol ):
344     self.Parameters().SetPeriodicTolerance( tol )
345
346   ## Set required_entities parameter
347   #  
348   #  The required entities control the correction operations. 
349   #  Accepted values for this parameter are :
350   #  - "respect" : MeshGems-CADSurf is not allowed to alter any required entity, 
351   #                even for correction purposes,
352   #  - "ignore" : MeshGems-CADSurf will ignore the required entities in its processing,
353   #  - "clear" : MeshGems-CADSurf will clear any required status for the entities. 
354   #              There will not be any entity marked as required in the generated mesh.
355   #  
356   def SetRequiredEntities( self, howToTreat ):
357     self.Parameters().SetRequiredEntities( howToTreat )
358
359   ## Set sewing_tolerance parameter
360   #  
361   #  This parameter is the tolerance of the assembly.
362   #  
363   def SetSewingTolerance( self, tol ):
364     self.Parameters().SetSewingTolerance( tol )
365
366   ## Set tags parameter
367   #  
368   #  The tag (attribute) system controls the optimisation process. 
369   #  Accepted values for this parameter are :
370   #  - "respect"  : the CAD tags will be preserved and unaltered by the optimisation operations,
371   #  - "ignore" : the CAD tags will be ignored by the optimisation operations 
372   #               but they will still be present in the output mesh,
373   #  - "clear" : MeshGems-CADSurf will clear any tag on any entity and optimise accordingly. 
374   #              There will not be any tag in the generated mesh.
375   #  
376   def SetTags( self, howToTreat ):
377     self.Parameters().SetTags( howToTreat )
378
379   ## Activate/deactivate fully patch independent meshing
380   #   @param isIndependent boolean flag
381   #
382   # This feature can only be used if the @a tags parameter is set to "respect".
383   # By default this option deactivated.
384   #
385   def SetPatchIndependent( self, isIndependent ):
386     self.SetOptionValue( "allow_patch_independent", "yes" if isIndependent else "no" )
387
388   ## Set to preserve lines defined by a sharp angle in the input discrete geometry
389   #   @param toCompute boolean flag
390   #
391   # If this option is deactivated, MeshGems-CADSurf will not try to preserve lines
392   # defined by a sharp angle in the input discrete geometry. Only input ridges, free
393   # edges, non manifold edges and separation betwen zones with different attributes
394   # will be respected (if tags is set to respect).
395   # By default this option activated.
396   #
397   def SetComputeRidges( self, toCompute ):
398     self.SetOptionValue( "compute_ridges", "yes" if toCompute else "no" )
399
400
401   ## Activate removal of the tiny edges from the generated
402   # mesh when it improves the local mesh quality, without taking into account the
403   # tags (attributes) specifications.
404   #  @param toOptimise "to optimize" flag value
405   #  @param length minimal length under which an edge is considered to be a tiny
406   def SetOptimiseTinyEdges(self, toOptimise, length=-1):
407     self.Parameters().SetOptimiseTinyEdges( toOptimise )
408     if toOptimise:
409       self.Parameters().SetTinyEdgeOptimisationLength( length )
410
411   ## Activate correction of all surface intersections
412   #  @param toCorrect "to correct" flag value
413   #  @param maxCost  the time the user is ready to spend in the intersection prevention process
414   #         For example, maxCost = 3 means that MeshGems-CADSurf will not spend more time
415   #         in the intersection removal process than 3 times the time required to mesh
416   #         without processing the intersections.
417   def SetCorrectSurfaceIntersection(self, toCorrect, maxCost ):
418     self.Parameters().SetCorrectSurfaceIntersection( toCorrect )
419     if toCorrect:
420       self.Parameters().SetCorrectSurfaceIntersectionMaxCost( maxCost )
421
422   ## To optimize merges edges.
423   #  @param toMergeEdges "merge edges" flag value
424   def SetPreCADMergeEdges(self, toMergeEdges=False):
425     self.Parameters().SetPreCADMergeEdges(toMergeEdges)
426     pass
427
428   ## To remove duplicate CAD Faces
429   #  @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
430   def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
431     self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
432     pass
433
434   ## To process 3D topology.
435   #  @param toProcess "PreCAD process 3D" flag value
436   def SetPreCADProcess3DTopology(self, toProcess=False):
437     self.Parameters().SetPreCADProcess3DTopology(toProcess)
438     pass
439
440   ## To remove nano edges.
441   #  @param toRemoveNanoEdges "remove nano edges" flag value
442   def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
443     if toRemoveNanoEdges:
444       self.SetPreCADOptionValue("remove_tiny_edges","1")
445     else:
446       self.SetPreCADOptionValue("remove_tiny_edges","0")
447     pass
448
449   ## To compute topology from scratch
450   #  @param toDiscardInput "discard input" flag value
451   def SetPreCADDiscardInput(self, toDiscardInput=False):
452     self.Parameters().SetPreCADDiscardInput(toDiscardInput)
453     pass
454
455   ## Sets the length below which an edge is considered as nano
456   #  for the topology processing.
457   #  @param epsNano nano edge length threshold value
458   def SetPreCADEpsNano(self, epsNano):
459     self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
460     pass
461
462   ## Sets advanced option value.
463   #  @param optionName advanced option name
464   #  @param level advanced option value
465   def SetOptionValue(self, optionName, level):
466     self.Parameters().SetOptionValue(optionName,level)
467     pass
468
469   ## Sets advanced PreCAD option value.
470   #  @param optionName name of the option
471   #  @param optionValue value of the option
472   def SetPreCADOptionValue(self, optionName, optionValue):
473     self.Parameters().SetPreCADOptionValue(optionName,optionValue)
474     pass
475   
476   ## Adds custom advanced option values
477   #  @param optionsAndValues options and values in a form "option_1 v1 option_2 v2'"
478   def SetAdvancedOption(self, optionsAndValues):
479     self.Parameters().SetAdvancedOption(optionsAndValues)
480     pass
481
482   ## Adds custom advanced option value.
483   #  @param optionName custom advanced option name
484   #  @param level custom advanced option value
485   def AddOption(self, optionName, level):
486     self.Parameters().AddOption(optionName,level)
487     pass
488
489   ## Adds custom advanced PreCAD option value.
490   #  @param optionName custom name of the option
491   #  @param optionValue value of the option
492   def AddPreCADOption(self, optionName, optionValue):
493     self.Parameters().AddPreCADOption(optionName,optionValue)
494     pass
495
496   ## Sets GMF file for export at computation
497   #  @param fileName GMF file name
498   def SetGMFFile(self, fileName):
499     self.Parameters().SetGMFFile(fileName)
500     pass
501
502   #-----------------------------------------
503   # Enforced vertices (BLSURF)
504   #-----------------------------------------
505
506   ## To get all the enforced vertices
507   def GetAllEnforcedVertices(self):
508     return self.Parameters().GetAllEnforcedVertices()
509
510   ## To get all the enforced vertices sorted by face (or group, compound)
511   def GetAllEnforcedVerticesByFace(self):
512     return self.Parameters().GetAllEnforcedVerticesByFace()
513
514   ## To get all the enforced vertices sorted by coords of input vertices
515   def GetAllEnforcedVerticesByCoords(self):
516     return self.Parameters().GetAllEnforcedVerticesByCoords()
517
518   ## To get all the coords of input vertices sorted by face (or group, compound)
519   def GetAllCoordsByFace(self):
520     return self.Parameters().GetAllCoordsByFace()
521
522   ## To get all the enforced vertices on a face (or group, compound)
523   #  @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
524   def GetEnforcedVertices(self, theFace):
525     from salome.smesh.smeshBuilder import AssureGeomPublished
526     AssureGeomPublished( self.mesh, theFace )
527     return self.Parameters().GetEnforcedVertices(theFace)
528
529   ## To clear all the enforced vertices
530   def ClearAllEnforcedVertices(self):
531     return self.Parameters().ClearAllEnforcedVertices()
532
533   ## To set an enforced vertex on a face (or group, compound) given the coordinates of a point. If the point is not on the face, it will projected on it. If there is no projection, no enforced vertex is created.
534   #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
535   #  @param x            : x coordinate
536   #  @param y            : y coordinate
537   #  @param z            : z coordinate
538   #  @param vertexName   : name of the enforced vertex
539   #  @param groupName    : name of the group
540   def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
541     from salome.smesh.smeshBuilder import AssureGeomPublished
542     AssureGeomPublished( self.mesh, theFace )
543     if vertexName == "":
544       if groupName == "":
545         return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
546       else:
547         return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
548       pass
549     else:
550       if groupName == "":
551         return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
552       else:
553         return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
554       pass
555     pass
556
557   ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
558   #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
559   #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
560   #  @param groupName    : name of the group
561   def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
562     from salome.smesh.smeshBuilder import AssureGeomPublished
563     AssureGeomPublished( self.mesh, theFace )
564     AssureGeomPublished( self.mesh, theVertex )
565     if groupName == "":
566       return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
567     else:
568       return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
569     pass
570
571   ## Set an enforced vertex on a face given the coordinates of a point.
572   #  The face if found by the application.
573   #  @param x            : x coordinate
574   #  @param y            : y coordinate
575   #  @param z            : z coordinate
576   #  @param vertexName   : name of the enforced vertex
577   #  @param groupName    : name of the group
578   def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
579     from salome.smesh.smeshBuilder import AssureGeomPublished
580     if vertexName == "":
581       if groupName == "":
582         return self.Parameters().AddEnforcedVertex(x, y, z)
583       else:
584         return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
585       pass
586     else:
587       if groupName == "":
588         return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
589       else:
590         return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
591       pass
592     pass
593
594   ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
595   #  The face if found by the application.
596   #  @param theVertex    : GEOM vertex (or group, compound).
597   #  @param groupName    : name of the group
598   def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
599     from salome.smesh.smeshBuilder import AssureGeomPublished
600     AssureGeomPublished( self.mesh, theVertex )
601     if groupName == "":
602       return self.Parameters().AddEnforcedVertexGeom(theVertex)
603     else:
604       return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
605     pass
606
607   ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
608   #  @param theFace      : GEOM face (or group, compound) on which to remove the enforced vertex
609   #  @param x            : x coordinate
610   #  @param y            : y coordinate
611   #  @param z            : z coordinate
612   def UnsetEnforcedVertex(self, theFace, x, y, z):
613     from salome.smesh.smeshBuilder import AssureGeomPublished
614     AssureGeomPublished( self.mesh, theFace )
615     return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
616
617   ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
618   #  @param theFace      : GEOM face (or group, compound) on which to remove the enforced vertex
619   #  @param theVertex    : GEOM vertex (or group, compound) to remove.
620   def UnsetEnforcedVertexGeom(self, theFace, theVertex):
621     from salome.smesh.smeshBuilder import AssureGeomPublished
622     AssureGeomPublished( self.mesh, theFace )
623     AssureGeomPublished( self.mesh, theVertex )
624     return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
625
626   ## To remove all enforced vertices on a given face.
627   #  @param theFace      : face (or group/compound of faces) on which to remove all enforced vertices
628   def UnsetEnforcedVertices(self, theFace):
629     from salome.smesh.smeshBuilder import AssureGeomPublished
630     AssureGeomPublished( self.mesh, theFace )
631     return self.Parameters().UnsetEnforcedVertices(theFace)
632
633   ## To tell BLSURF to add a node on internal vertices
634   #  @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
635   def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
636     return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
637
638   ## To know if BLSURF will add a node on internal vertices
639   def GetInternalEnforcedVertexAllFaces(self):
640     return self.Parameters().GetInternalEnforcedVertexAllFaces()
641
642   ## To define a group for the nodes of internal vertices
643   #  @param groupName : string; name of the group
644   def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
645     return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
646
647   ## To get the group name of the nodes of internal vertices
648   def GetInternalEnforcedVertexAllFacesGroup(self):
649     return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
650
651   #-----------------------------------------
652   #  Attractors
653   #-----------------------------------------
654
655   ## Sets an attractor on the chosen face. The mesh size will decrease exponentially with the distance from theAttractor, following the rule h(d) = theEndSize - (theEndSize - theStartSize) * exp [ - ( d / theInfluenceDistance ) ^ 2 ]
656   #  @param theFace      : face on which the attractor will be defined
657   #  @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
658   #  @param theStartSize : mesh size on theAttractor
659   #  @param theEndSize   : maximum size that will be reached on theFace
660   #  @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
661   #  @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
662   def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
663     from salome.smesh.smeshBuilder import AssureGeomPublished
664     AssureGeomPublished( self.mesh, theFace )
665     AssureGeomPublished( self.mesh, theAttractor )
666     self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
667     pass
668
669   ## Unsets an attractor on the chosen face.
670   #  @param theFace      : face on which the attractor has to be removed
671   def UnsetAttractorGeom(self, theFace):
672     from salome.smesh.smeshBuilder import AssureGeomPublished
673     AssureGeomPublished( self.mesh, theFace )
674     self.Parameters().SetAttractorGeom(theFace)
675     pass
676
677   #-----------------------------------------
678   # Size maps (BLSURF)
679   #-----------------------------------------
680
681   ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
682   #  If theObject is a face, the function can be: def f(u,v): return u+v
683   #  If theObject is an edge, the function can be: def f(t): return t/2
684   #  If theObject is a vertex, the function can be: def f(): return 10
685   #  @param theObject   : GEOM face, edge or vertex (or group, compound) on which to define a size map
686   #  @param theSizeMap  : Size map defined as a string
687   def SetSizeMap(self, theObject, theSizeMap):
688     from salome.smesh.smeshBuilder import AssureGeomPublished
689     AssureGeomPublished( self.mesh, theObject )
690     self.Parameters().SetSizeMap(theObject, theSizeMap)
691     pass
692
693   ## To set a constant size map on a face, edge or vertex (or group, compound).
694   #  @param theObject   : GEOM face, edge or vertex (or group, compound) on which to define a size map
695   #  @param theSizeMap  : Size map defined as a double
696   def SetConstantSizeMap(self, theObject, theSizeMap):
697     from salome.smesh.smeshBuilder import AssureGeomPublished
698     AssureGeomPublished( self.mesh, theObject )
699     self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
700
701   ## To remove a size map defined on a face, edge or vertex (or group, compound)
702   #  @param theObject   : GEOM face, edge or vertex (or group, compound) on which to define a size map
703   def UnsetSizeMap(self, theObject):
704     from salome.smesh.smeshBuilder import AssureGeomPublished
705     AssureGeomPublished( self.mesh, theObject )
706     self.Parameters().UnsetSizeMap(theObject)
707     pass
708
709   ## To remove all the size maps
710   def ClearSizeMaps(self):
711     self.Parameters().ClearSizeMaps()
712     pass
713
714   ## Sets QuadAllowed flag (DEPRECATED: use SetElementType)
715   #  @param toAllow "allow quadrangles" flag value
716   # TODO: to remove in Salome 9
717   def SetQuadAllowed(self, toAllow=True):
718     self.Parameters().SetQuadAllowed(toAllow)
719     pass
720
721   ## Sets elements type
722   #  @param theElementType: 0 (Triangles), 1 (QuadrangleDominant), 2 (Quadrangles)
723   def SetElementType(self, theElementType=Triangles):
724     self.Parameters().SetElementType(theElementType)
725     pass
726
727   ## Defines hypothesis having several parameters
728   #  @return hypothesis object
729   def Parameters(self):
730     if not self.params:
731       hypType = "MG-CADSurf Parameters"
732       hasGeom = self.mesh.GetMesh().HasShapeToMesh()
733       if hasGeom:
734         self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
735       else:
736         self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
737         self.mesh.smeshpyD.SetName( self.params, hypType )
738       pass
739     return self.params
740
741   #-----------------------------------------
742   # Periodicity (BLSURF with PreCAD)
743   #-----------------------------------------
744   
745   ## Defines periodicity between two groups of faces, using PreCAD
746   #  @param theFace1 : GEOM face (or group, compound) to associate with theFace2
747   #  @param theFace2 : GEOM face (or group, compound) associated with theFace1
748   #  @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
749   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
750   #  @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
751   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
752   def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
753     """calls preCad function:
754     status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
755           integer *fid1, integer size1, integer *fid2, integer size2,
756           periodicity_transformation_t transf, void *user data);
757     """
758     if theSourceVertices and theTargetVertices:
759       self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
760     else:
761       self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
762     pass
763
764   ## Defines periodicity between two groups of edges, using PreCAD
765   #  @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
766   #  @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
767   #  @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
768   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
769   #  @param  theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
770   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
771   def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
772     """calls preCad function:
773     status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
774           integer *eid1, integer size1, integer *eid2, integer size2,
775           periodicity_transformation_t transf, void *user data);
776     """
777     if theSourceVertices and theTargetVertices:
778         self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
779     else:
780         self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
781     pass
782
783   #-----------------------------------------
784   # Hyper-Patches
785   #-----------------------------------------
786   
787   ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
788   #  ignoring edges between them
789   #  @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
790   #         faces or groups of faces. A face can be identified either as a GEOM object or
791   #         a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
792   #         
793   #  Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
794   def SetHyperPatches(self, hyperPatchList):
795     hpl = []
796     for patch in hyperPatchList:
797       ids = []
798       for face in patch:
799         if isinstance( face, int ):
800           ids.append( face )
801         elif isinstance( face, GEOM._objref_GEOM_Object):
802           faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
803           for f in faces:
804             ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
805         else:
806           raise TypeError("Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face))
807         pass
808       hpl.append( ids )
809       pass
810     self.Parameters().SetHyperPatches( hpl )
811     return
812
813   pass # end of BLSURF_Algorithm class