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