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