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