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