Salome HOME
correction for bug #23439: add use_deprecated_patch_mesher parameter to allow the...
[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 use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
238   #  
239   # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
240   # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
241   #  
242   def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
243     self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
244
245   ## Set respect_geometry parameter
246   #  
247   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
248   #  to lower the geometry accuracy in its patch independent process.
249   #  
250   def SetRespectGeometry( self, toRespect ):
251     self.Parameters().SetRespectGeometry( toRespect )
252
253   ## Set max_number_of_points_per_patch parameter
254   #  
255   #  This parameter controls the maximum amount of points MeshGems-CADSurf is allowed
256   #  to generate on a single CAD patch. For an automatic gestion of the memory, one
257   #  can set this parameter to 0
258   #  
259   def SetMaxNumberOfPointsPerPatch( self, nb ):
260     self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
261
262   ## Set max_number_of_threads parameter
263   #
264   #  Set the maximum of threads to use for multithreading mesh computation
265   #
266   def SetMaxNumberOfThreads( self, nb ):
267     self.Parameters().SetMaxNumberOfThreads( nb )
268
269   ## Set respect_geometry parameter
270   #  
271   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
272   #  to lower the geometry accuracy in its patch independent process.
273   #  
274   def SetRespectGeometry( self, toRespect ):
275     self.Parameters().SetRespectGeometry( toRespect )
276
277   ## Set tiny_edges_avoid_surface_intersections parameter
278   #  
279   #  This option defines the priority between the tiny feature
280   #  suppression and the surface intersection prevention. 
281   #  
282   def SetTinyEdgesAvoidSurfaceIntersections( self, toAvoidIntersection ):
283     self.Parameters().SetTinyEdgesAvoidSurfaceIntersections( toAvoidIntersection )
284
285   ## Set closed_geometry parameter parameter
286   #  
287   #  Describes whether the geometry is expected to be closed or not. 
288   #  When activated, this option helps MeshGems-PreCAD to treat the dirtiest geometries.
289   #  
290   def SetClosedGeometry( self, isClosed ):
291     self.Parameters().SetClosedGeometry( isClosed )
292
293   ## Set debug parameter
294   #  
295   #  Make MeshGems-CADSurf will be very verbose and will output some intermediate
296   #  files in the working directory. This option is mainly meant for Distene support issues.
297   #  
298   def SetDebug( self, isDebug ):
299     self.Parameters().SetDebug( isDebug )
300
301   ## Set periodic_tolerance parameter
302   #  
303   #  This parameter defines the maximum size difference between two periodic edges
304   #  and also the maximum distance error between two periodic entities.
305   #  
306   def SetPeriodicTolerance( self, tol ):
307     self.Parameters().SetPeriodicTolerance( tol )
308
309   ## Set required_entities parameter
310   #  
311   #  The required entities control the correction operations. 
312   #  Accepted values for this parameter are :
313   #  - "respect" : MeshGems-CADSurf is not allowed to alter any required entity, 
314   #                even for correction purposes,
315   #  - "ignore" : MeshGems-CADSurf will ignore the required entities in its processing,
316   #  - "clear" : MeshGems-CADSurf will clear any required status for the entities. 
317   #              There will not be any entity marked as required in the generated mesh.
318   #  
319   def SetRequiredEntities( self, howToTreat ):
320     self.Parameters().SetRequiredEntities( howToTreat )
321
322   ## Set sewing_tolerance parameter
323   #  
324   #  This parameter is the tolerance of the assembly.
325   #  
326   def SetSewingTolerance( self, tol ):
327     self.Parameters().SetSewingTolerance( tol )
328
329   ## Set tags parameter
330   #  
331   #  The tag (attribute) system controls the optimisation process. 
332   #  Accepted values for this parameter are :
333   #  - "respect"  : the CAD tags will be preserved and unaltered by the optimisation operations,
334   #  - "ignore" : the CAD tags will be ignored by the optimisation operations 
335   #               but they will still be present in the output mesh,
336   #  - "clear" : MeshGems-CADSurf will clear any tag on any entity and optimise accordingly. 
337   #              There will not be any tag in the generated mesh.
338   #  
339   def SetTags( self, howToTreat ):
340     self.Parameters().SetTags( howToTreat )
341
342   ## Activate removal of the tiny edges from the generated
343   # mesh when it improves the local mesh quality, without taking into account the
344   # tags (attributes) specifications.
345   #  @param toOptimise "to optimize" flag value
346   #  @param length minimal length under which an edge is considered to be a tiny
347   def SetOptimiseTinyEdges(self, toOptimise, length=-1):
348     self.Parameters().SetOptimiseTinyEdges( toOptimise )
349     if toOptimise:
350       self.Parameters().SetTinyEdgeOptimisationLength( length )
351
352   ## Activate correction of all surface intersections
353   #  @param toCorrect "to correct" flag value
354   #  @param maxCost  the time the user is ready to spend in the intersection prevention process
355   #         For example, maxCost = 3 means that MeshGems-CADSurf will not spend more time
356   #         in the intersection removal process than 3 times the time required to mesh
357   #         without processing the intersections.
358   def SetCorrectSurfaceIntersection(self, toCorrect, maxCost ):
359     self.Parameters().SetCorrectSurfaceIntersection( toCorrect )
360     if toCorrect:
361       self.Parameters().SetCorrectSurfaceIntersectionMaxCost( maxCost )
362
363   ## To optimize merges edges.
364   #  @param toMergeEdges "merge edges" flag value
365   def SetPreCADMergeEdges(self, toMergeEdges=False):
366     self.Parameters().SetPreCADMergeEdges(toMergeEdges)
367     pass
368
369   ## To remove duplicate CAD Faces
370   #  @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
371   def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
372     self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
373     pass
374
375   ## To process 3D topology.
376   #  @param toProcess "PreCAD process 3D" flag value
377   def SetPreCADProcess3DTopology(self, toProcess=False):
378     self.Parameters().SetPreCADProcess3DTopology(toProcess)
379     pass
380
381   ## To remove nano edges.
382   #  @param toRemoveNanoEdges "remove nano edges" flag value
383   def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
384     if toRemoveNanoEdges:
385       self.SetPreCADOptionValue("remove_tiny_edges","1")
386     else:
387       self.SetPreCADOptionValue("remove_tiny_edges","0")
388     pass
389
390   ## To compute topology from scratch
391   #  @param toDiscardInput "discard input" flag value
392   def SetPreCADDiscardInput(self, toDiscardInput=False):
393     self.Parameters().SetPreCADDiscardInput(toDiscardInput)
394     pass
395
396   ## Sets the length below which an edge is considered as nano
397   #  for the topology processing.
398   #  @param epsNano nano edge length threshold value
399   def SetPreCADEpsNano(self, epsNano):
400     self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
401     pass
402
403   ## Sets advanced option value.
404   #  @param optionName advanced option name
405   #  @param level advanced option value
406   def SetOptionValue(self, optionName, level):
407     self.Parameters().SetOptionValue(optionName,level)
408     pass
409
410   ## Sets advanced PreCAD option value.
411   #  @param optionName name of the option
412   #  @param optionValue value of the option
413   def SetPreCADOptionValue(self, optionName, optionValue):
414     self.Parameters().SetPreCADOptionValue(optionName,optionValue)
415     pass
416   
417   ## Adds custom advanced option values
418   #  @param optionsAndValues options and values in a form "option_1 v1 option_2 v2'"
419   def SetAdvancedOption(self, optionsAndValues):
420     self.Parameters().SetAdvancedOption(optionsAndValues)
421     pass
422
423   ## Adds custom advanced option value.
424   #  @param optionName custom advanced option name
425   #  @param level custom advanced option value
426   def AddOption(self, optionName, level):
427     self.Parameters().AddOption(optionName,level)
428     pass
429
430   ## Adds custom advanced PreCAD option value.
431   #  @param optionName custom name of the option
432   #  @param optionValue value of the option
433   def AddPreCADOption(self, optionName, optionValue):
434     self.Parameters().AddPreCADOption(optionName,optionValue)
435     pass
436
437   ## Sets GMF file for export at computation
438   #  @param fileName GMF file name
439   def SetGMFFile(self, fileName):
440     self.Parameters().SetGMFFile(fileName)
441     pass
442
443   #-----------------------------------------
444   # Enforced vertices (BLSURF)
445   #-----------------------------------------
446
447   ## To get all the enforced vertices
448   def GetAllEnforcedVertices(self):
449     return self.Parameters().GetAllEnforcedVertices()
450
451   ## To get all the enforced vertices sorted by face (or group, compound)
452   def GetAllEnforcedVerticesByFace(self):
453     return self.Parameters().GetAllEnforcedVerticesByFace()
454
455   ## To get all the enforced vertices sorted by coords of input vertices
456   def GetAllEnforcedVerticesByCoords(self):
457     return self.Parameters().GetAllEnforcedVerticesByCoords()
458
459   ## To get all the coords of input vertices sorted by face (or group, compound)
460   def GetAllCoordsByFace(self):
461     return self.Parameters().GetAllCoordsByFace()
462
463   ## To get all the enforced vertices on a face (or group, compound)
464   #  @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
465   def GetEnforcedVertices(self, theFace):
466     from salome.smesh.smeshBuilder import AssureGeomPublished
467     AssureGeomPublished( self.mesh, theFace )
468     return self.Parameters().GetEnforcedVertices(theFace)
469
470   ## To clear all the enforced vertices
471   def ClearAllEnforcedVertices(self):
472     return self.Parameters().ClearAllEnforcedVertices()
473
474   ## 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.
475   #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
476   #  @param x            : x coordinate
477   #  @param y            : y coordinate
478   #  @param z            : z coordinate
479   #  @param vertexName   : name of the enforced vertex
480   #  @param groupName    : name of the group
481   def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
482     from salome.smesh.smeshBuilder import AssureGeomPublished
483     AssureGeomPublished( self.mesh, theFace )
484     if vertexName == "":
485       if groupName == "":
486         return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
487       else:
488         return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
489       pass
490     else:
491       if groupName == "":
492         return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
493       else:
494         return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
495       pass
496     pass
497
498   ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
499   #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
500   #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
501   #  @param groupName    : name of the group
502   def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
503     from salome.smesh.smeshBuilder import AssureGeomPublished
504     AssureGeomPublished( self.mesh, theFace )
505     AssureGeomPublished( self.mesh, theVertex )
506     if groupName == "":
507       return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
508     else:
509       return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
510     pass
511
512   ## Set an enforced vertex on a face given the coordinates of a point.
513   #  The face if found by the application.
514   #  @param x            : x coordinate
515   #  @param y            : y coordinate
516   #  @param z            : z coordinate
517   #  @param vertexName   : name of the enforced vertex
518   #  @param groupName    : name of the group
519   def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
520     from salome.smesh.smeshBuilder import AssureGeomPublished
521     if vertexName == "":
522       if groupName == "":
523         return self.Parameters().AddEnforcedVertex(x, y, z)
524       else:
525         return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
526       pass
527     else:
528       if groupName == "":
529         return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
530       else:
531         return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
532       pass
533     pass
534
535   ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
536   #  The face if found by the application.
537   #  @param theVertex    : GEOM vertex (or group, compound).
538   #  @param groupName    : name of the group
539   def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
540     from salome.smesh.smeshBuilder import AssureGeomPublished
541     AssureGeomPublished( self.mesh, theVertex )
542     if groupName == "":
543       return self.Parameters().AddEnforcedVertexGeom(theVertex)
544     else:
545       return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
546     pass
547
548   ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
549   #  @param theFace      : GEOM face (or group, compound) on which to remove the enforced vertex
550   #  @param x            : x coordinate
551   #  @param y            : y coordinate
552   #  @param z            : z coordinate
553   def UnsetEnforcedVertex(self, theFace, x, y, z):
554     from salome.smesh.smeshBuilder import AssureGeomPublished
555     AssureGeomPublished( self.mesh, theFace )
556     return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
557
558   ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
559   #  @param theFace      : GEOM face (or group, compound) on which to remove the enforced vertex
560   #  @param theVertex    : GEOM vertex (or group, compound) to remove.
561   def UnsetEnforcedVertexGeom(self, theFace, theVertex):
562     from salome.smesh.smeshBuilder import AssureGeomPublished
563     AssureGeomPublished( self.mesh, theFace )
564     AssureGeomPublished( self.mesh, theVertex )
565     return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
566
567   ## To remove all enforced vertices on a given face.
568   #  @param theFace      : face (or group/compound of faces) on which to remove all enforced vertices
569   def UnsetEnforcedVertices(self, theFace):
570     from salome.smesh.smeshBuilder import AssureGeomPublished
571     AssureGeomPublished( self.mesh, theFace )
572     return self.Parameters().UnsetEnforcedVertices(theFace)
573
574   ## To tell BLSURF to add a node on internal vertices
575   #  @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
576   def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
577     return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
578
579   ## To know if BLSURF will add a node on internal vertices
580   def GetInternalEnforcedVertexAllFaces(self):
581     return self.Parameters().GetInternalEnforcedVertexAllFaces()
582
583   ## To define a group for the nodes of internal vertices
584   #  @param groupName : string; name of the group
585   def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
586     return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
587
588   ## To get the group name of the nodes of internal vertices
589   def GetInternalEnforcedVertexAllFacesGroup(self):
590     return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
591
592   #-----------------------------------------
593   #  Attractors
594   #-----------------------------------------
595
596   ## 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 ]
597   #  @param theFace      : face on which the attractor will be defined
598   #  @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
599   #  @param theStartSize : mesh size on theAttractor
600   #  @param theEndSize   : maximum size that will be reached on theFace
601   #  @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
602   #  @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
603   def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
604     from salome.smesh.smeshBuilder import AssureGeomPublished
605     AssureGeomPublished( self.mesh, theFace )
606     AssureGeomPublished( self.mesh, theAttractor )
607     self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
608     pass
609
610   ## Unsets an attractor on the chosen face.
611   #  @param theFace      : face on which the attractor has to be removed
612   def UnsetAttractorGeom(self, theFace):
613     from salome.smesh.smeshBuilder import AssureGeomPublished
614     AssureGeomPublished( self.mesh, theFace )
615     self.Parameters().SetAttractorGeom(theFace)
616     pass
617
618   #-----------------------------------------
619   # Size maps (BLSURF)
620   #-----------------------------------------
621
622   ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
623   #  If theObject is a face, the function can be: def f(u,v): return u+v
624   #  If theObject is an edge, the function can be: def f(t): return t/2
625   #  If theObject is a vertex, the function can be: def f(): return 10
626   #  @param theObject   : GEOM face, edge or vertex (or group, compound) on which to define a size map
627   #  @param theSizeMap  : Size map defined as a string
628   def SetSizeMap(self, theObject, theSizeMap):
629     from salome.smesh.smeshBuilder import AssureGeomPublished
630     AssureGeomPublished( self.mesh, theObject )
631     self.Parameters().SetSizeMap(theObject, theSizeMap)
632     pass
633
634   ## To set a constant size map 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   #  @param theSizeMap  : Size map defined as a double
637   def SetConstantSizeMap(self, theObject, theSizeMap):
638     from salome.smesh.smeshBuilder import AssureGeomPublished
639     AssureGeomPublished( self.mesh, theObject )
640     self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
641
642   ## To remove a size map defined on a face, edge or vertex (or group, compound)
643   #  @param theObject   : GEOM face, edge or vertex (or group, compound) on which to define a size map
644   def UnsetSizeMap(self, theObject):
645     from salome.smesh.smeshBuilder import AssureGeomPublished
646     AssureGeomPublished( self.mesh, theObject )
647     self.Parameters().UnsetSizeMap(theObject)
648     pass
649
650   ## To remove all the size maps
651   def ClearSizeMaps(self):
652     self.Parameters().ClearSizeMaps()
653     pass
654
655   ## Sets QuadAllowed flag.
656   #  @param toAllow "allow quadrangles" flag value
657   def SetQuadAllowed(self, toAllow=True):
658     self.Parameters().SetQuadAllowed(toAllow)
659     pass
660
661   ## Defines hypothesis having several parameters
662   #  @return hypothesis object
663   def Parameters(self):
664     if not self.params:
665       hypType = "MG-CADSurf Parameters"
666       hasGeom = self.mesh.GetMesh().HasShapeToMesh()
667       if hasGeom:
668         self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
669       else:
670         self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
671         self.mesh.smeshpyD.SetName( self.params, hypType )
672       pass
673     return self.params
674
675   #-----------------------------------------
676   # Periodicity (BLSURF with PreCAD)
677   #-----------------------------------------
678   
679   ## Defines periodicity between two groups of faces, using PreCAD
680   #  @param theFace1 : GEOM face (or group, compound) to associate with theFace2
681   #  @param theFace2 : GEOM face (or group, compound) associated with theFace1
682   #  @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
683   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
684   #  @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
685   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
686   def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
687     """calls preCad function:
688     status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
689           integer *fid1, integer size1, integer *fid2, integer size2,
690           periodicity_transformation_t transf, void *user data);
691     """
692     if theSourceVertices and theTargetVertices:
693       self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
694     else:
695       self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
696     pass
697
698   ## Defines periodicity between two groups of edges, using PreCAD
699   #  @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
700   #  @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
701   #  @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
702   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
703   #  @param  theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
704   #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
705   def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
706     """calls preCad function:
707     status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
708           integer *eid1, integer size1, integer *eid2, integer size2,
709           periodicity_transformation_t transf, void *user data);
710     """
711     if theSourceVertices and theTargetVertices:
712         self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
713     else:
714         self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
715     pass
716
717   #-----------------------------------------
718   # Hyper-Patches
719   #-----------------------------------------
720   
721   ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
722   #  ignoring edges between them
723   #  @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
724   #         faces or groups of faces. A face can be identified either as a GEOM object or
725   #         a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
726   #         
727   #  Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
728   def SetHyperPatches(self, hyperPatchList):
729     hpl = []
730     for patch in hyperPatchList:
731       ids = []
732       for face in patch:
733         if isinstance( face, int ):
734           ids.append( face )
735         elif isinstance( face, GEOM._objref_GEOM_Object):
736           faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
737           for f in faces:
738             ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
739         else:
740           raise TypeError, \
741             "Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face)
742         pass
743       hpl.append( ids )
744       pass
745     self.Parameters().SetHyperPatches( hpl )
746     return
747
748   #=====================
749   # Obsolete methods
750   #=====================
751   #
752   # SALOME 6.6.0
753   #
754
755   ## Sets lower boundary of mesh element size (PhySize).
756   def SetPhyMin(self, theVal=-1):
757     """
758     Obsolete function. Use SetMinSize.
759     """
760     print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
761     self.SetMinSize(theVal)
762     pass
763
764   ## Sets upper boundary of mesh element size (PhySize).
765   def SetPhyMax(self, theVal=-1):
766     """
767     Obsolete function. Use SetMaxSize.
768     """
769     print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
770     self.SetMaxSize(theVal)
771     pass
772
773   ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
774   def SetAngleMeshS(self, theVal=_geometric_approximation):
775     """
776     Obsolete function. Use SetAngleMesh.
777     """
778     print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
779     self.SetAngleMesh(theVal)
780     pass
781
782   ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
783   def SetAngleMeshC(self, theVal=_geometric_approximation):
784     """
785     Obsolete function. Use SetAngleMesh.
786     """
787     print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
788     self.SetAngleMesh(theVal)
789     pass
790
791   ## Sets lower boundary of mesh element size computed to respect angular deflection.
792   def SetGeoMin(self, theVal=-1):
793     """
794     Obsolete function. Use SetMinSize.
795     """
796     print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
797     self.SetMinSize(theVal)
798     pass
799
800   ## Sets upper boundary of mesh element size computed to respect angular deflection.
801   def SetGeoMax(self, theVal=-1):
802     """
803     Obsolete function. Use SetMaxSize.
804     """
805     print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
806     self.SetMaxSize(theVal)
807     pass
808
809
810   pass # end of BLSURF_Algorithm class