1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Francis KLOSS, OCC
29 ## @defgroup l1_auxiliary Auxiliary methods and structures
30 ## @defgroup l1_creating Creating meshes
32 ## @defgroup l2_impexp Importing and exporting meshes
33 ## @defgroup l2_construct Constructing meshes
34 ## @defgroup l2_algorithms Defining Algorithms
36 ## @defgroup l3_algos_basic Basic meshing algorithms
37 ## @defgroup l3_algos_proj Projection Algorithms
38 ## @defgroup l3_algos_radialp Radial Prism
39 ## @defgroup l3_algos_segmarv Segments around Vertex
40 ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm
43 ## @defgroup l2_hypotheses Defining hypotheses
45 ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
46 ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
47 ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis
48 ## @defgroup l3_hypos_netgen Netgen 2D and 3D hypotheses
49 ## @defgroup l3_hypos_ghs3dh GHS3D Parameters hypothesis
50 ## @defgroup l3_hypos_blsurf BLSURF Parameters hypothesis
51 ## @defgroup l3_hypos_hexotic Hexotic Parameters hypothesis
52 ## @defgroup l3_hypos_additi Additional Hypotheses
55 ## @defgroup l2_submeshes Constructing submeshes
56 ## @defgroup l2_compounds Building Compounds
57 ## @defgroup l2_editing Editing Meshes
60 ## @defgroup l1_meshinfo Mesh Information
61 ## @defgroup l1_controls Quality controls and Filtering
62 ## @defgroup l1_grouping Grouping elements
64 ## @defgroup l2_grps_create Creating groups
65 ## @defgroup l2_grps_edit Editing groups
66 ## @defgroup l2_grps_operon Using operations on groups
67 ## @defgroup l2_grps_delete Deleting Groups
70 ## @defgroup l1_modifying Modifying meshes
72 ## @defgroup l2_modif_add Adding nodes and elements
73 ## @defgroup l2_modif_del Removing nodes and elements
74 ## @defgroup l2_modif_edit Modifying nodes and elements
75 ## @defgroup l2_modif_renumber Renumbering nodes and elements
76 ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
77 ## @defgroup l2_modif_movenode Moving nodes
78 ## @defgroup l2_modif_throughp Mesh through point
79 ## @defgroup l2_modif_invdiag Diagonal inversion of elements
80 ## @defgroup l2_modif_unitetri Uniting triangles
81 ## @defgroup l2_modif_changori Changing orientation of elements
82 ## @defgroup l2_modif_cutquadr Cutting quadrangles
83 ## @defgroup l2_modif_smooth Smoothing
84 ## @defgroup l2_modif_extrurev Extrusion and Revolution
85 ## @defgroup l2_modif_patterns Pattern mapping
86 ## @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
93 import SMESH # This is necessary for back compatibility
100 # import NETGENPlugin module if possible
108 ## @addtogroup l1_auxiliary
111 # Types of algorithms
122 NETGEN_1D2D3D = FULL_NETGEN
123 NETGEN_FULL = FULL_NETGEN
128 # MirrorType enumeration
129 POINT = SMESH_MeshEditor.POINT
130 AXIS = SMESH_MeshEditor.AXIS
131 PLANE = SMESH_MeshEditor.PLANE
133 # Smooth_Method enumeration
134 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
135 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
137 # Fineness enumeration (for NETGEN)
145 # Optimization level of GHS3D
146 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
148 # Topology treatment way of BLSURF
149 FromCAD, PreProcess, PreProcessPlus = 0,1,2
151 # Element size flag of BLSURF
152 DefaultSize, DefaultGeom, Custom = 0,0,1
154 PrecisionConfusion = 1e-07
156 def IsEqual(val1, val2, tol=PrecisionConfusion):
157 if abs(val1 - val2) < tol:
165 ior = salome.orb.object_to_string(obj)
166 sobj = salome.myStudy.FindObjectIOR(ior)
170 attr = sobj.FindAttribute("AttributeName")[1]
173 ## Sets a name to the object
174 def SetName(obj, name):
175 ior = salome.orb.object_to_string(obj)
176 sobj = salome.myStudy.FindObjectIOR(ior)
178 attr = sobj.FindAttribute("AttributeName")[1]
181 ## Prints error message if a hypothesis was not assigned.
182 def TreatHypoStatus(status, hypName, geomName, isAlgo):
184 hypType = "algorithm"
186 hypType = "hypothesis"
188 if status == HYP_UNKNOWN_FATAL :
189 reason = "for unknown reason"
190 elif status == HYP_INCOMPATIBLE :
191 reason = "this hypothesis mismatches the algorithm"
192 elif status == HYP_NOTCONFORM :
193 reason = "a non-conform mesh would be built"
194 elif status == HYP_ALREADY_EXIST :
195 reason = hypType + " of the same dimension is already assigned to this shape"
196 elif status == HYP_BAD_DIM :
197 reason = hypType + " mismatches the shape"
198 elif status == HYP_CONCURENT :
199 reason = "there are concurrent hypotheses on sub-shapes"
200 elif status == HYP_BAD_SUBSHAPE :
201 reason = "the shape is neither the main one, nor its subshape, nor a valid group"
202 elif status == HYP_BAD_GEOMETRY:
203 reason = "geometry mismatches the expectation of the algorithm"
204 elif status == HYP_HIDDEN_ALGO:
205 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
206 elif status == HYP_HIDING_ALGO:
207 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
208 elif status == HYP_NEED_SHAPE:
209 reason = "Algorithm can't work without shape"
212 hypName = '"' + hypName + '"'
213 geomName= '"' + geomName+ '"'
214 if status < HYP_UNKNOWN_FATAL:
215 print hypName, "was assigned to", geomName,"but", reason
217 print hypName, "was not assigned to",geomName,":", reason
220 ## Converts an angle from degrees to radians
221 def DegreesToRadians(AngleInDegrees):
223 return AngleInDegrees * pi / 180.0
225 # end of l1_auxiliary
228 # All methods of this class are accessible directly from the smesh.py package.
229 class smeshDC(SMESH._objref_SMESH_Gen):
231 ## Sets the current study and Geometry component
232 # @ingroup l1_auxiliary
233 def init_smesh(self,theStudy,geompyD):
235 self.SetGeomEngine(geompyD)
236 self.SetCurrentStudy(theStudy)
238 ## Creates an empty Mesh. This mesh can have an underlying geometry.
239 # @param obj the Geometrical object on which the mesh is built. If not defined,
240 # the mesh will have no underlying geometry.
241 # @param name the name for the new mesh.
242 # @return an instance of Mesh class.
243 # @ingroup l2_construct
244 def Mesh(self, obj=0, name=0):
245 return Mesh(self,self.geompyD,obj,name)
247 ## Returns a long value from enumeration
248 # Should be used for SMESH.FunctorType enumeration
249 # @ingroup l1_controls
250 def EnumToLong(self,theItem):
253 ## Gets PointStruct from vertex
254 # @param theVertex a GEOM object(vertex)
255 # @return SMESH.PointStruct
256 # @ingroup l1_auxiliary
257 def GetPointStruct(self,theVertex):
258 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
259 return PointStruct(x,y,z)
261 ## Gets DirStruct from vector
262 # @param theVector a GEOM object(vector)
263 # @return SMESH.DirStruct
264 # @ingroup l1_auxiliary
265 def GetDirStruct(self,theVector):
266 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
267 if(len(vertices) != 2):
268 print "Error: vector object is incorrect."
270 p1 = self.geompyD.PointCoordinates(vertices[0])
271 p2 = self.geompyD.PointCoordinates(vertices[1])
272 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
273 dirst = DirStruct(pnt)
276 ## Makes DirStruct from a triplet
277 # @param x,y,z vector components
278 # @return SMESH.DirStruct
279 # @ingroup l1_auxiliary
280 def MakeDirStruct(self,x,y,z):
281 pnt = PointStruct(x,y,z)
282 return DirStruct(pnt)
284 ## Get AxisStruct from object
285 # @param theObj a GEOM object (line or plane)
286 # @return SMESH.AxisStruct
287 # @ingroup l1_auxiliary
288 def GetAxisStruct(self,theObj):
289 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
291 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
292 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
293 vertex1 = self.geompyD.PointCoordinates(vertex1)
294 vertex2 = self.geompyD.PointCoordinates(vertex2)
295 vertex3 = self.geompyD.PointCoordinates(vertex3)
296 vertex4 = self.geompyD.PointCoordinates(vertex4)
297 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
298 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
299 normal = [ v1[1]*v2[2]-v2[1]*v1[2], v1[2]*v2[0]-v2[2]*v1[0], v1[0]*v2[1]-v2[0]*v1[1] ]
300 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
302 elif len(edges) == 1:
303 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
304 p1 = self.geompyD.PointCoordinates( vertex1 )
305 p2 = self.geompyD.PointCoordinates( vertex2 )
306 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
310 # From SMESH_Gen interface:
311 # ------------------------
313 ## Sets the current mode
314 # @ingroup l1_auxiliary
315 def SetEmbeddedMode( self,theMode ):
316 #self.SetEmbeddedMode(theMode)
317 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
319 ## Gets the current mode
320 # @ingroup l1_auxiliary
321 def IsEmbeddedMode(self):
322 #return self.IsEmbeddedMode()
323 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
325 ## Sets the current study
326 # @ingroup l1_auxiliary
327 def SetCurrentStudy( self, theStudy ):
328 #self.SetCurrentStudy(theStudy)
329 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
331 ## Gets the current study
332 # @ingroup l1_auxiliary
333 def GetCurrentStudy(self):
334 #return self.GetCurrentStudy()
335 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
337 ## Creates a Mesh object importing data from the given UNV file
338 # @return an instance of Mesh class
340 def CreateMeshesFromUNV( self,theFileName ):
341 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
342 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
345 ## Creates a Mesh object(s) importing data from the given MED file
346 # @return a list of Mesh class instances
348 def CreateMeshesFromMED( self,theFileName ):
349 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
351 for iMesh in range(len(aSmeshMeshes)) :
352 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
353 aMeshes.append(aMesh)
354 return aMeshes, aStatus
356 ## Creates a Mesh object importing data from the given STL file
357 # @return an instance of Mesh class
359 def CreateMeshesFromSTL( self, theFileName ):
360 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
361 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
364 ## From SMESH_Gen interface
365 # @return the list of integer values
366 # @ingroup l1_auxiliary
367 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
368 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
370 ## From SMESH_Gen interface. Creates a pattern
371 # @return an instance of SMESH_Pattern
373 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
374 # @ingroup l2_modif_patterns
375 def GetPattern(self):
376 return SMESH._objref_SMESH_Gen.GetPattern(self)
379 # Filtering. Auxiliary functions:
380 # ------------------------------
382 ## Creates an empty criterion
383 # @return SMESH.Filter.Criterion
384 # @ingroup l1_controls
385 def GetEmptyCriterion(self):
386 Type = self.EnumToLong(FT_Undefined)
387 Compare = self.EnumToLong(FT_Undefined)
391 UnaryOp = self.EnumToLong(FT_Undefined)
392 BinaryOp = self.EnumToLong(FT_Undefined)
395 Precision = -1 ##@1e-07
396 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
397 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
399 ## Creates a criterion by the given parameters
400 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
401 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
402 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
403 # @param Treshold the threshold value (range of ids as string, shape, numeric)
404 # @param UnaryOp FT_LogicalNOT or FT_Undefined
405 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
406 # FT_Undefined (must be for the last criterion of all criteria)
407 # @return SMESH.Filter.Criterion
408 # @ingroup l1_controls
409 def GetCriterion(self,elementType,
411 Compare = FT_EqualTo,
413 UnaryOp=FT_Undefined,
414 BinaryOp=FT_Undefined):
415 aCriterion = self.GetEmptyCriterion()
416 aCriterion.TypeOfElement = elementType
417 aCriterion.Type = self.EnumToLong(CritType)
421 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
422 aCriterion.Compare = self.EnumToLong(Compare)
423 elif Compare == "=" or Compare == "==":
424 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
426 aCriterion.Compare = self.EnumToLong(FT_LessThan)
428 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
430 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
433 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
434 FT_BelongToCylinder, FT_LyingOnGeom]:
435 # Checks the treshold
436 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
437 aCriterion.ThresholdStr = GetName(aTreshold)
438 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
440 print "Error: The treshold should be a shape."
442 elif CritType == FT_RangeOfIds:
443 # Checks the treshold
444 if isinstance(aTreshold, str):
445 aCriterion.ThresholdStr = aTreshold
447 print "Error: The treshold should be a string."
449 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
450 # At this point the treshold is unnecessary
451 if aTreshold == FT_LogicalNOT:
452 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
453 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
454 aCriterion.BinaryOp = aTreshold
458 aTreshold = float(aTreshold)
459 aCriterion.Threshold = aTreshold
461 print "Error: The treshold should be a number."
464 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
465 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
467 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
468 aCriterion.BinaryOp = self.EnumToLong(Treshold)
470 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
471 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
473 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
474 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
478 ## Creates a filter with the given parameters
479 # @param elementType the type of elements in the group
480 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
481 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
482 # @param Treshold the threshold value (range of id ids as string, shape, numeric)
483 # @param UnaryOp FT_LogicalNOT or FT_Undefined
484 # @return SMESH_Filter
485 # @ingroup l1_controls
486 def GetFilter(self,elementType,
487 CritType=FT_Undefined,
490 UnaryOp=FT_Undefined):
491 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
492 aFilterMgr = self.CreateFilterManager()
493 aFilter = aFilterMgr.CreateFilter()
495 aCriteria.append(aCriterion)
496 aFilter.SetCriteria(aCriteria)
499 ## Creates a numerical functor by its type
500 # @param theCriterion FT_...; functor type
501 # @return SMESH_NumericalFunctor
502 # @ingroup l1_controls
503 def GetFunctor(self,theCriterion):
504 aFilterMgr = self.CreateFilterManager()
505 if theCriterion == FT_AspectRatio:
506 return aFilterMgr.CreateAspectRatio()
507 elif theCriterion == FT_AspectRatio3D:
508 return aFilterMgr.CreateAspectRatio3D()
509 elif theCriterion == FT_Warping:
510 return aFilterMgr.CreateWarping()
511 elif theCriterion == FT_MinimumAngle:
512 return aFilterMgr.CreateMinimumAngle()
513 elif theCriterion == FT_Taper:
514 return aFilterMgr.CreateTaper()
515 elif theCriterion == FT_Skew:
516 return aFilterMgr.CreateSkew()
517 elif theCriterion == FT_Area:
518 return aFilterMgr.CreateArea()
519 elif theCriterion == FT_Volume3D:
520 return aFilterMgr.CreateVolume3D()
521 elif theCriterion == FT_MultiConnection:
522 return aFilterMgr.CreateMultiConnection()
523 elif theCriterion == FT_MultiConnection2D:
524 return aFilterMgr.CreateMultiConnection2D()
525 elif theCriterion == FT_Length:
526 return aFilterMgr.CreateLength()
527 elif theCriterion == FT_Length2D:
528 return aFilterMgr.CreateLength2D()
530 print "Error: given parameter is not numerucal functor type."
534 #Registering the new proxy for SMESH_Gen
535 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
541 ## This class allows defining and managing a mesh.
542 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
543 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
544 # new nodes and elements and by changing the existing entities), to get information
545 # about a mesh and to export a mesh into different formats.
554 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
555 # sets the GUI name of this mesh to \a name.
556 # @param smeshpyD an instance of smeshDC class
557 # @param geompyD an instance of geompyDC class
558 # @param obj Shape to be meshed or SMESH_Mesh object
559 # @param name Study name of the mesh
560 # @ingroup l2_construct
561 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
562 self.smeshpyD=smeshpyD
567 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
569 self.mesh = self.smeshpyD.CreateMesh(self.geom)
570 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
573 self.mesh = self.smeshpyD.CreateEmptyMesh()
575 SetName(self.mesh, name)
577 SetName(self.mesh, GetName(obj))
580 self.geom = self.mesh.GetShapeToMesh()
582 self.editor = self.mesh.GetMeshEditor()
584 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
585 # @param theMesh a SMESH_Mesh object
586 # @ingroup l2_construct
587 def SetMesh(self, theMesh):
589 self.geom = self.mesh.GetShapeToMesh()
591 ## Returns the mesh, that is an instance of SMESH_Mesh interface
592 # @return a SMESH_Mesh object
593 # @ingroup l2_construct
597 ## Gets the name of the mesh
598 # @return the name of the mesh as a string
599 # @ingroup l2_construct
601 name = GetName(self.GetMesh())
604 ## Sets a name to the mesh
605 # @param name a new name of the mesh
606 # @ingroup l2_construct
607 def SetName(self, name):
608 SetName(self.GetMesh(), name)
610 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
611 # The subMesh object gives access to the IDs of nodes and elements.
612 # @param theSubObject a geometrical object (shape)
613 # @param theName a name for the submesh
614 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
615 # @ingroup l2_submeshes
616 def GetSubMesh(self, theSubObject, theName):
617 submesh = self.mesh.GetSubMesh(theSubObject, theName)
620 ## Returns the shape associated to the mesh
621 # @return a GEOM_Object
622 # @ingroup l2_construct
626 ## Associates the given shape to the mesh (entails the recreation of the mesh)
627 # @param geom the shape to be meshed (GEOM_Object)
628 # @ingroup l2_construct
629 def SetShape(self, geom):
630 self.mesh = self.smeshpyD.CreateMesh(geom)
632 ## Returns true if the hypotheses are defined well
633 # @param theSubObject a subshape of a mesh shape
634 # @return True or False
635 # @ingroup l2_construct
636 def IsReadyToCompute(self, theSubObject):
637 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
639 ## Returns errors of hypotheses definition.
640 # The list of errors is empty if everything is OK.
641 # @param theSubObject a subshape of a mesh shape
642 # @return a list of errors
643 # @ingroup l2_construct
644 def GetAlgoState(self, theSubObject):
645 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
647 ## Returns a geometrical object on which the given element was built.
648 # The returned geometrical object, if not nil, is either found in the
649 # study or published by this method with the given name
650 # @param theElementID the id of the mesh element
651 # @param theGeomName the user-defined name of the geometrical object
652 # @return GEOM::GEOM_Object instance
653 # @ingroup l2_construct
654 def GetGeometryByMeshElement(self, theElementID, theGeomName):
655 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
657 ## Returns the mesh dimension depending on the dimension of the underlying shape
658 # @return mesh dimension as an integer value [0,3]
659 # @ingroup l1_auxiliary
660 def MeshDimension(self):
661 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
662 if len( shells ) > 0 :
664 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
666 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
672 ## Creates a segment discretization 1D algorithm.
673 # If the optional \a algo parameter is not set, this algorithm is REGULAR.
674 # \n If the optional \a geom parameter is not set, this algorithm is global.
675 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
676 # @param algo the type of the required algorithm. Possible values are:
678 # - smesh.PYTHON for discretization via a python function,
679 # - smesh.COMPOSITE for meshing a set of edges on one face side as a whole.
680 # @param geom If defined is the subshape to be meshed
681 # @return an instance of Mesh_Segment or Mesh_Segment_Python, or Mesh_CompositeSegment class
682 # @ingroup l3_algos_basic
683 def Segment(self, algo=REGULAR, geom=0):
684 ## if Segment(geom) is called by mistake
685 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
686 algo, geom = geom, algo
687 if not algo: algo = REGULAR
690 return Mesh_Segment(self, geom)
692 return Mesh_Segment_Python(self, geom)
693 elif algo == COMPOSITE:
694 return Mesh_CompositeSegment(self, geom)
696 return Mesh_Segment(self, geom)
698 ## Enables creation of nodes and segments usable by 2D algoritms.
699 # The added nodes and segments must be bound to edges and vertices by
700 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
701 # If the optional \a geom parameter is not set, this algorithm is global.
702 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
703 # @param geom the subshape to be manually meshed
704 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
705 # @ingroup l3_algos_basic
706 def UseExistingSegments(self, geom=0):
707 algo = Mesh_UseExisting(1,self,geom)
708 return algo.GetAlgorithm()
710 ## Enables creation of nodes and faces usable by 3D algoritms.
711 # The added nodes and faces must be bound to geom faces by SetNodeOnFace()
712 # and SetMeshElementOnShape()
713 # If the optional \a geom parameter is not set, this algorithm is global.
714 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
715 # @param geom the subshape to be manually meshed
716 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
717 # @ingroup l3_algos_basic
718 def UseExistingFaces(self, geom=0):
719 algo = Mesh_UseExisting(2,self,geom)
720 return algo.GetAlgorithm()
722 ## Creates a triangle 2D algorithm for faces.
723 # If the optional \a geom parameter is not set, this algorithm is global.
724 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
725 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D || smesh.BLSURF
726 # @param geom If defined, the subshape to be meshed (GEOM_Object)
727 # @return an instance of Mesh_Triangle algorithm
728 # @ingroup l3_algos_basic
729 def Triangle(self, algo=MEFISTO, geom=0):
730 ## if Triangle(geom) is called by mistake
731 if (isinstance(algo, geompyDC.GEOM._objref_GEOM_Object)):
735 return Mesh_Triangle(self, algo, geom)
737 ## Creates a quadrangle 2D algorithm for faces.
738 # If the optional \a geom parameter is not set, this algorithm is global.
739 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
740 # @param geom If defined, the subshape to be meshed (GEOM_Object)
741 # @return an instance of Mesh_Quadrangle algorithm
742 # @ingroup l3_algos_basic
743 def Quadrangle(self, geom=0):
744 return Mesh_Quadrangle(self, geom)
746 ## Creates a tetrahedron 3D algorithm for solids.
747 # The parameter \a algo permits to choose the algorithm: NETGEN or GHS3D
748 # If the optional \a geom parameter is not set, this algorithm is global.
749 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
750 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
751 # @param geom If defined, the subshape to be meshed (GEOM_Object)
752 # @return an instance of Mesh_Tetrahedron algorithm
753 # @ingroup l3_algos_basic
754 def Tetrahedron(self, algo=NETGEN, geom=0):
755 ## if Tetrahedron(geom) is called by mistake
756 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
757 algo, geom = geom, algo
758 if not algo: algo = NETGEN
760 return Mesh_Tetrahedron(self, algo, geom)
762 ## Creates a hexahedron 3D algorithm for solids.
763 # If the optional \a geom parameter is not set, this algorithm is global.
764 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
765 # @param algo possible values are: smesh.Hexa, smesh.Hexotic
766 # @param geom If defined, the subshape to be meshed (GEOM_Object)
767 # @return an instance of Mesh_Hexahedron algorithm
768 # @ingroup l3_algos_basic
769 def Hexahedron(self, algo=Hexa, geom=0):
770 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
771 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
772 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
773 elif geom == 0: algo, geom = Hexa, algo
774 return Mesh_Hexahedron(self, algo, geom)
776 ## Deprecated, used only for compatibility!
777 # @return an instance of Mesh_Netgen algorithm
778 # @ingroup l3_algos_basic
779 def Netgen(self, is3D, geom=0):
780 return Mesh_Netgen(self, is3D, geom)
782 ## Creates a projection 1D algorithm for edges.
783 # If the optional \a geom parameter is not set, this algorithm is global.
784 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
785 # @param geom If defined, the subshape to be meshed
786 # @return an instance of Mesh_Projection1D algorithm
787 # @ingroup l3_algos_proj
788 def Projection1D(self, geom=0):
789 return Mesh_Projection1D(self, geom)
791 ## Creates a projection 2D algorithm for faces.
792 # If the optional \a geom parameter is not set, this algorithm is global.
793 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
794 # @param geom If defined, the subshape to be meshed
795 # @return an instance of Mesh_Projection2D algorithm
796 # @ingroup l3_algos_proj
797 def Projection2D(self, geom=0):
798 return Mesh_Projection2D(self, geom)
800 ## Creates a projection 3D algorithm for solids.
801 # If the optional \a geom parameter is not set, this algorithm is global.
802 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
803 # @param geom If defined, the subshape to be meshed
804 # @return an instance of Mesh_Projection3D algorithm
805 # @ingroup l3_algos_proj
806 def Projection3D(self, geom=0):
807 return Mesh_Projection3D(self, geom)
809 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
810 # If the optional \a geom parameter is not set, this algorithm is global.
811 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
812 # @param geom If defined, the subshape to be meshed
813 # @return an instance of Mesh_Prism3D or Mesh_RadialPrism3D algorithm
814 # @ingroup l3_algos_radialp l3_algos_3dextr
815 def Prism(self, geom=0):
819 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
820 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
821 if nbSolids == 0 or nbSolids == nbShells:
822 return Mesh_Prism3D(self, geom)
823 return Mesh_RadialPrism3D(self, geom)
825 ## Computes the mesh and returns the status of the computation
826 # @return True or False
827 # @ingroup l2_construct
828 def Compute(self, geom=0):
829 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
831 geom = self.mesh.GetShapeToMesh()
836 ok = self.smeshpyD.Compute(self.mesh, geom)
837 except SALOME.SALOME_Exception, ex:
838 print "Mesh computation failed, exception caught:"
839 print " ", ex.details.text
842 print "Mesh computation failed, exception caught:"
843 traceback.print_exc()
845 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
856 reason = '%s %sD algorithm is missing' % (glob, dim)
857 elif err.state == HYP_MISSING:
858 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
859 % (glob, dim, name, dim))
860 elif err.state == HYP_NOTCONFORM:
861 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
862 elif err.state == HYP_BAD_PARAMETER:
863 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
864 % ( glob, dim, name ))
865 elif err.state == HYP_BAD_GEOMETRY:
866 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
867 'geometry' % ( glob, dim, name ))
869 reason = "For unknown reason."+\
870 " Revise Mesh.Compute() implementation in smeshDC.py!"
878 print '"' + GetName(self.mesh) + '"',"has not been computed:"
882 print '"' + GetName(self.mesh) + '"',"has not been computed."
885 if salome.sg.hasDesktop():
886 smeshgui = salome.ImportComponentGUI("SMESH")
887 smeshgui.Init(salome.myStudyId)
888 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
889 salome.sg.updateObjBrowser(1)
893 ## Removes all nodes and elements
894 # @ingroup l2_construct
897 if salome.sg.hasDesktop():
898 smeshgui = salome.ImportComponentGUI("SMESH")
899 smeshgui.Init(salome.myStudyId)
900 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
901 salome.sg.updateObjBrowser(1)
903 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
904 # @param fineness [0,-1] defines mesh fineness
905 # @return True or False
906 # @ingroup l3_algos_basic
907 def AutomaticTetrahedralization(self, fineness=0):
908 dim = self.MeshDimension()
910 self.RemoveGlobalHypotheses()
911 self.Segment().AutomaticLength(fineness)
913 self.Triangle().LengthFromEdges()
916 self.Tetrahedron(NETGEN)
918 return self.Compute()
920 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
921 # @param fineness [0,-1] defines mesh fineness
922 # @return True or False
923 # @ingroup l3_algos_basic
924 def AutomaticHexahedralization(self, fineness=0):
925 dim = self.MeshDimension()
926 # assign the hypotheses
927 self.RemoveGlobalHypotheses()
928 self.Segment().AutomaticLength(fineness)
935 return self.Compute()
937 ## Assigns a hypothesis
938 # @param hyp a hypothesis to assign
939 # @param geom a subhape of mesh geometry
940 # @return SMESH.Hypothesis_Status
941 # @ingroup l2_hypotheses
942 def AddHypothesis(self, hyp, geom=0):
943 if isinstance( hyp, Mesh_Algorithm ):
944 hyp = hyp.GetAlgorithm()
949 geom = self.mesh.GetShapeToMesh()
951 status = self.mesh.AddHypothesis(geom, hyp)
952 isAlgo = hyp._narrow( SMESH_Algo )
953 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
956 ## Unassigns a hypothesis
957 # @param hyp a hypothesis to unassign
958 # @param geom a subshape of mesh geometry
959 # @return SMESH.Hypothesis_Status
960 # @ingroup l2_hypotheses
961 def RemoveHypothesis(self, hyp, geom=0):
962 if isinstance( hyp, Mesh_Algorithm ):
963 hyp = hyp.GetAlgorithm()
968 status = self.mesh.RemoveHypothesis(geom, hyp)
971 ## Gets the list of hypotheses added on a geometry
972 # @param geom a subshape of mesh geometry
973 # @return the sequence of SMESH_Hypothesis
974 # @ingroup l2_hypotheses
975 def GetHypothesisList(self, geom):
976 return self.mesh.GetHypothesisList( geom )
978 ## Removes all global hypotheses
979 # @ingroup l2_hypotheses
980 def RemoveGlobalHypotheses(self):
981 current_hyps = self.mesh.GetHypothesisList( self.geom )
982 for hyp in current_hyps:
983 self.mesh.RemoveHypothesis( self.geom, hyp )
987 ## Creates a mesh group based on the geometric object \a grp
988 # and gives a \a name, \n if this parameter is not defined
989 # the name is the same as the geometric group name \n
990 # Note: Works like GroupOnGeom().
991 # @param grp a geometric group, a vertex, an edge, a face or a solid
992 # @param name the name of the mesh group
993 # @return SMESH_GroupOnGeom
994 # @ingroup l2_grps_create
995 def Group(self, grp, name=""):
996 return self.GroupOnGeom(grp, name)
998 ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
999 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1000 # @param f the file name
1001 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1002 # @ingroup l2_impexp
1003 def ExportToMED(self, f, version, opt=0):
1004 self.mesh.ExportToMED(f, opt, version)
1006 ## Exports the mesh in a file in MED format
1007 # @param f is the file name
1008 # @param auto_groups boolean parameter for creating/not creating
1009 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1010 # the typical use is auto_groups=false.
1011 # @param version MED format version(MED_V2_1 or MED_V2_2)
1012 # @ingroup l2_impexp
1013 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1014 self.mesh.ExportToMED(f, auto_groups, version)
1016 ## Exports the mesh in a file in DAT format
1017 # @param f the file name
1018 # @ingroup l2_impexp
1019 def ExportDAT(self, f):
1020 self.mesh.ExportDAT(f)
1022 ## Exports the mesh in a file in UNV format
1023 # @param f the file name
1024 # @ingroup l2_impexp
1025 def ExportUNV(self, f):
1026 self.mesh.ExportUNV(f)
1028 ## Export the mesh in a file in STL format
1029 # @param f the file name
1030 # @param ascii defines the file encoding
1031 # @ingroup l2_impexp
1032 def ExportSTL(self, f, ascii=1):
1033 self.mesh.ExportSTL(f, ascii)
1036 # Operations with groups:
1037 # ----------------------
1039 ## Creates an empty mesh group
1040 # @param elementType the type of elements in the group
1041 # @param name the name of the mesh group
1042 # @return SMESH_Group
1043 # @ingroup l2_grps_create
1044 def CreateEmptyGroup(self, elementType, name):
1045 return self.mesh.CreateGroup(elementType, name)
1047 ## Creates a mesh group based on the geometrical object \a grp
1048 # and gives a \a name, \n if this parameter is not defined
1049 # the name is the same as the geometrical group name
1050 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1051 # @param name the name of the mesh group
1052 # @param typ the type of elements in the group. If not set, it is
1053 # automatically detected by the type of the geometry
1054 # @return SMESH_GroupOnGeom
1055 # @ingroup l2_grps_create
1056 def GroupOnGeom(self, grp, name="", typ=None):
1058 name = grp.GetName()
1061 tgeo = str(grp.GetShapeType())
1062 if tgeo == "VERTEX":
1064 elif tgeo == "EDGE":
1066 elif tgeo == "FACE":
1068 elif tgeo == "SOLID":
1070 elif tgeo == "SHELL":
1072 elif tgeo == "COMPOUND":
1073 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1074 print "Mesh.Group: empty geometric group", GetName( grp )
1076 tgeo = self.geompyD.GetType(grp)
1077 if tgeo == geompyDC.ShapeType["VERTEX"]:
1079 elif tgeo == geompyDC.ShapeType["EDGE"]:
1081 elif tgeo == geompyDC.ShapeType["FACE"]:
1083 elif tgeo == geompyDC.ShapeType["SOLID"]:
1087 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1090 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1092 ## Creates a mesh group by the given ids of elements
1093 # @param groupName the name of the mesh group
1094 # @param elementType the type of elements in the group
1095 # @param elemIDs the list of ids
1096 # @return SMESH_Group
1097 # @ingroup l2_grps_create
1098 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1099 group = self.mesh.CreateGroup(elementType, groupName)
1103 ## Creates a mesh group by the given conditions
1104 # @param groupName the name of the mesh group
1105 # @param elementType the type of elements in the group
1106 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1107 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1108 # @param Treshold the threshold value (range of id ids as string, shape, numeric)
1109 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1110 # @return SMESH_Group
1111 # @ingroup l2_grps_create
1115 CritType=FT_Undefined,
1118 UnaryOp=FT_Undefined):
1119 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1120 group = self.MakeGroupByCriterion(groupName, aCriterion)
1123 ## Creates a mesh group by the given criterion
1124 # @param groupName the name of the mesh group
1125 # @param Criterion the instance of Criterion class
1126 # @return SMESH_Group
1127 # @ingroup l2_grps_create
1128 def MakeGroupByCriterion(self, groupName, Criterion):
1129 aFilterMgr = self.smeshpyD.CreateFilterManager()
1130 aFilter = aFilterMgr.CreateFilter()
1132 aCriteria.append(Criterion)
1133 aFilter.SetCriteria(aCriteria)
1134 group = self.MakeGroupByFilter(groupName, aFilter)
1137 ## Creates a mesh group by the given criteria (list of criteria)
1138 # @param groupName the name of the mesh group
1139 # @param theCriteria the list of criteria
1140 # @return SMESH_Group
1141 # @ingroup l2_grps_create
1142 def MakeGroupByCriteria(self, groupName, theCriteria):
1143 aFilterMgr = self.smeshpyD.CreateFilterManager()
1144 aFilter = aFilterMgr.CreateFilter()
1145 aFilter.SetCriteria(theCriteria)
1146 group = self.MakeGroupByFilter(groupName, aFilter)
1149 ## Creates a mesh group by the given filter
1150 # @param groupName the name of the mesh group
1151 # @param theFilter the instance of Filter class
1152 # @return SMESH_Group
1153 # @ingroup l2_grps_create
1154 def MakeGroupByFilter(self, groupName, theFilter):
1155 anIds = theFilter.GetElementsId(self.mesh)
1156 anElemType = theFilter.GetElementType()
1157 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1160 ## Passes mesh elements through the given filter and return IDs of fitting elements
1161 # @param theFilter SMESH_Filter
1162 # @return a list of ids
1163 # @ingroup l1_controls
1164 def GetIdsFromFilter(self, theFilter):
1165 return theFilter.GetElementsId(self.mesh)
1167 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
1168 # Returns a list of special structures (borders).
1169 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
1170 # @ingroup l1_controls
1171 def GetFreeBorders(self):
1172 aFilterMgr = self.smeshpyD.CreateFilterManager()
1173 aPredicate = aFilterMgr.CreateFreeEdges()
1174 aPredicate.SetMesh(self.mesh)
1175 aBorders = aPredicate.GetBorders()
1179 # @ingroup l2_grps_delete
1180 def RemoveGroup(self, group):
1181 self.mesh.RemoveGroup(group)
1183 ## Removes a group with its contents
1184 # @ingroup l2_grps_delete
1185 def RemoveGroupWithContents(self, group):
1186 self.mesh.RemoveGroupWithContents(group)
1188 ## Gets the list of groups existing in the mesh
1189 # @return a sequence of SMESH_GroupBase
1190 # @ingroup l2_grps_create
1191 def GetGroups(self):
1192 return self.mesh.GetGroups()
1194 ## Gets the number of groups existing in the mesh
1195 # @return the quantity of groups as an integer value
1196 # @ingroup l2_grps_create
1198 return self.mesh.NbGroups()
1200 ## Gets the list of names of groups existing in the mesh
1201 # @return list of strings
1202 # @ingroup l2_grps_create
1203 def GetGroupNames(self):
1204 groups = self.GetGroups()
1206 for group in groups:
1207 names.append(group.GetName())
1210 ## Produces a union of two groups
1211 # A new group is created. All mesh elements that are
1212 # present in the initial groups are added to the new one
1213 # @return an instance of SMESH_Group
1214 # @ingroup l2_grps_operon
1215 def UnionGroups(self, group1, group2, name):
1216 return self.mesh.UnionGroups(group1, group2, name)
1218 ## Prodices an intersection of two groups
1219 # A new group is created. All mesh elements that are common
1220 # for the two initial groups are added to the new one.
1221 # @return an instance of SMESH_Group
1222 # @ingroup l2_grps_operon
1223 def IntersectGroups(self, group1, group2, name):
1224 return self.mesh.IntersectGroups(group1, group2, name)
1226 ## Produces a cut of two groups
1227 # A new group is created. All mesh elements that are present in
1228 # the main group but are not present in the tool group are added to the new one
1229 # @return an instance of SMESH_Group
1230 # @ingroup l2_grps_operon
1231 def CutGroups(self, mainGroup, toolGroup, name):
1232 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1235 # Get some info about mesh:
1236 # ------------------------
1238 ## Returns the log of nodes and elements added or removed
1239 # since the previous clear of the log.
1240 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1241 # @return list of log_block structures:
1246 # @ingroup l1_auxiliary
1247 def GetLog(self, clearAfterGet):
1248 return self.mesh.GetLog(clearAfterGet)
1250 ## Clears the log of nodes and elements added or removed since the previous
1251 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1252 # @ingroup l1_auxiliary
1254 self.mesh.ClearLog()
1256 ## Toggles auto color mode on the object.
1257 # @param theAutoColor the flag which toggles auto color mode.
1258 # @ingroup l1_auxiliary
1259 def SetAutoColor(self, theAutoColor):
1260 self.mesh.SetAutoColor(theAutoColor)
1262 ## Gets flag of object auto color mode.
1263 # @return True or False
1264 # @ingroup l1_auxiliary
1265 def GetAutoColor(self):
1266 return self.mesh.GetAutoColor()
1268 ## Gets the internal ID
1269 # @return integer value, which is the internal Id of the mesh
1270 # @ingroup l1_auxiliary
1272 return self.mesh.GetId()
1275 # @return integer value, which is the study Id of the mesh
1276 # @ingroup l1_auxiliary
1277 def GetStudyId(self):
1278 return self.mesh.GetStudyId()
1280 ## Checks the group names for duplications.
1281 # Consider the maximum group name length stored in MED file.
1282 # @return True or False
1283 # @ingroup l1_auxiliary
1284 def HasDuplicatedGroupNamesMED(self):
1285 return self.mesh.HasDuplicatedGroupNamesMED()
1287 ## Obtains the mesh editor tool
1288 # @return an instance of SMESH_MeshEditor
1289 # @ingroup l1_modifying
1290 def GetMeshEditor(self):
1291 return self.mesh.GetMeshEditor()
1294 # @return an instance of SALOME_MED::MESH
1295 # @ingroup l1_auxiliary
1296 def GetMEDMesh(self):
1297 return self.mesh.GetMEDMesh()
1300 # Get informations about mesh contents:
1301 # ------------------------------------
1303 ## Returns the number of nodes in the mesh
1304 # @return an integer value
1305 # @ingroup l1_meshinfo
1307 return self.mesh.NbNodes()
1309 ## Returns the number of elements in the mesh
1310 # @return an integer value
1311 # @ingroup l1_meshinfo
1312 def NbElements(self):
1313 return self.mesh.NbElements()
1315 ## Returns the number of edges in the mesh
1316 # @return an integer value
1317 # @ingroup l1_meshinfo
1319 return self.mesh.NbEdges()
1321 ## Returns the number of edges with the given order in the mesh
1322 # @param elementOrder the order of elements:
1323 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1324 # @return an integer value
1325 # @ingroup l1_meshinfo
1326 def NbEdgesOfOrder(self, elementOrder):
1327 return self.mesh.NbEdgesOfOrder(elementOrder)
1329 ## Returns the number of faces in the mesh
1330 # @return an integer value
1331 # @ingroup l1_meshinfo
1333 return self.mesh.NbFaces()
1335 ## Returns the number of faces with the given order in the mesh
1336 # @param elementOrder the order of elements:
1337 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1338 # @return an integer value
1339 # @ingroup l1_meshinfo
1340 def NbFacesOfOrder(self, elementOrder):
1341 return self.mesh.NbFacesOfOrder(elementOrder)
1343 ## Returns the number of triangles in the mesh
1344 # @return an integer value
1345 # @ingroup l1_meshinfo
1346 def NbTriangles(self):
1347 return self.mesh.NbTriangles()
1349 ## Returns the number of triangles with the given order in the mesh
1350 # @param elementOrder is the order of elements:
1351 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1352 # @return an integer value
1353 # @ingroup l1_meshinfo
1354 def NbTrianglesOfOrder(self, elementOrder):
1355 return self.mesh.NbTrianglesOfOrder(elementOrder)
1357 ## Returns the number of quadrangles in the mesh
1358 # @return an integer value
1359 # @ingroup l1_meshinfo
1360 def NbQuadrangles(self):
1361 return self.mesh.NbQuadrangles()
1363 ## Returns the number of quadrangles with the given order in the mesh
1364 # @param elementOrder the order of elements:
1365 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1366 # @return an integer value
1367 # @ingroup l1_meshinfo
1368 def NbQuadranglesOfOrder(self, elementOrder):
1369 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1371 ## Returns the number of polygons in the mesh
1372 # @return an integer value
1373 # @ingroup l1_meshinfo
1374 def NbPolygons(self):
1375 return self.mesh.NbPolygons()
1377 ## Returns the number of volumes in the mesh
1378 # @return an integer value
1379 # @ingroup l1_meshinfo
1380 def NbVolumes(self):
1381 return self.mesh.NbVolumes()
1383 ## Returns the number of volumes with the given order in the mesh
1384 # @param elementOrder the order of elements:
1385 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1386 # @return an integer value
1387 # @ingroup l1_meshinfo
1388 def NbVolumesOfOrder(self, elementOrder):
1389 return self.mesh.NbVolumesOfOrder(elementOrder)
1391 ## Returns the number of tetrahedrons in the mesh
1392 # @return an integer value
1393 # @ingroup l1_meshinfo
1395 return self.mesh.NbTetras()
1397 ## Returns the number of tetrahedrons with the given order in the mesh
1398 # @param elementOrder the order of elements:
1399 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1400 # @return an integer value
1401 # @ingroup l1_meshinfo
1402 def NbTetrasOfOrder(self, elementOrder):
1403 return self.mesh.NbTetrasOfOrder(elementOrder)
1405 ## Returns the number of hexahedrons in the mesh
1406 # @return an integer value
1407 # @ingroup l1_meshinfo
1409 return self.mesh.NbHexas()
1411 ## Returns the number of hexahedrons with the given order in the mesh
1412 # @param elementOrder the order of elements:
1413 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1414 # @return an integer value
1415 # @ingroup l1_meshinfo
1416 def NbHexasOfOrder(self, elementOrder):
1417 return self.mesh.NbHexasOfOrder(elementOrder)
1419 ## Returns the number of pyramids in the mesh
1420 # @return an integer value
1421 # @ingroup l1_meshinfo
1422 def NbPyramids(self):
1423 return self.mesh.NbPyramids()
1425 ## Returns the number of pyramids with the given order in the mesh
1426 # @param elementOrder the order of elements:
1427 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1428 # @return an integer value
1429 # @ingroup l1_meshinfo
1430 def NbPyramidsOfOrder(self, elementOrder):
1431 return self.mesh.NbPyramidsOfOrder(elementOrder)
1433 ## Returns the number of prisms in the mesh
1434 # @return an integer value
1435 # @ingroup l1_meshinfo
1437 return self.mesh.NbPrisms()
1439 ## Returns the number of prisms with the given order in the mesh
1440 # @param elementOrder the order of elements:
1441 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1442 # @return an integer value
1443 # @ingroup l1_meshinfo
1444 def NbPrismsOfOrder(self, elementOrder):
1445 return self.mesh.NbPrismsOfOrder(elementOrder)
1447 ## Returns the number of polyhedrons in the mesh
1448 # @return an integer value
1449 # @ingroup l1_meshinfo
1450 def NbPolyhedrons(self):
1451 return self.mesh.NbPolyhedrons()
1453 ## Returns the number of submeshes in the mesh
1454 # @return an integer value
1455 # @ingroup l1_meshinfo
1456 def NbSubMesh(self):
1457 return self.mesh.NbSubMesh()
1459 ## Returns the list of mesh elements IDs
1460 # @return the list of integer values
1461 # @ingroup l1_meshinfo
1462 def GetElementsId(self):
1463 return self.mesh.GetElementsId()
1465 ## Returns the list of IDs of mesh elements with the given type
1466 # @param elementType the required type of elements
1467 # @return list of integer values
1468 # @ingroup l1_meshinfo
1469 def GetElementsByType(self, elementType):
1470 return self.mesh.GetElementsByType(elementType)
1472 ## Returns the list of mesh nodes IDs
1473 # @return the list of integer values
1474 # @ingroup l1_meshinfo
1475 def GetNodesId(self):
1476 return self.mesh.GetNodesId()
1478 # Get the information about mesh elements:
1479 # ------------------------------------
1481 ## Returns the type of mesh element
1482 # @return the value from SMESH::ElementType enumeration
1483 # @ingroup l1_meshinfo
1484 def GetElementType(self, id, iselem):
1485 return self.mesh.GetElementType(id, iselem)
1487 ## Returns the list of submesh elements IDs
1488 # @param Shape a geom object(subshape) IOR
1489 # Shape must be the subshape of a ShapeToMesh()
1490 # @return the list of integer values
1491 # @ingroup l1_meshinfo
1492 def GetSubMeshElementsId(self, Shape):
1493 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1494 ShapeID = Shape.GetSubShapeIndices()[0]
1497 return self.mesh.GetSubMeshElementsId(ShapeID)
1499 ## Returns the list of submesh nodes IDs
1500 # @param Shape a geom object(subshape) IOR
1501 # Shape must be the subshape of a ShapeToMesh()
1502 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
1503 # @return the list of integer values
1504 # @ingroup l1_meshinfo
1505 def GetSubMeshNodesId(self, Shape, all):
1506 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1507 ShapeID = Shape.GetSubShapeIndices()[0]
1510 return self.mesh.GetSubMeshNodesId(ShapeID, all)
1512 ## Returns the list of IDs of submesh elements with the given type
1513 # @param Shape a geom object(subshape) IOR
1514 # Shape must be a subshape of a ShapeToMesh()
1515 # @return the list of integer values
1516 # @ingroup l1_meshinfo
1517 def GetSubMeshElementType(self, Shape):
1518 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1519 ShapeID = Shape.GetSubShapeIndices()[0]
1522 return self.mesh.GetSubMeshElementType(ShapeID)
1524 ## Gets the mesh description
1525 # @return string value
1526 # @ingroup l1_meshinfo
1528 return self.mesh.Dump()
1531 # Get the information about nodes and elements of a mesh by its IDs:
1532 # -----------------------------------------------------------
1534 ## Gets XYZ coordinates of a node
1535 # \n If there is no nodes for the given ID - returns an empty list
1536 # @return a list of double precision values
1537 # @ingroup l1_meshinfo
1538 def GetNodeXYZ(self, id):
1539 return self.mesh.GetNodeXYZ(id)
1541 ## Returns list of IDs of inverse elements for the given node
1542 # \n If there is no node for the given ID - returns an empty list
1543 # @return a list of integer values
1544 # @ingroup l1_meshinfo
1545 def GetNodeInverseElements(self, id):
1546 return self.mesh.GetNodeInverseElements(id)
1548 ## @brief Returns the position of a node on the shape
1549 # @return SMESH::NodePosition
1550 # @ingroup l1_meshinfo
1551 def GetNodePosition(self,NodeID):
1552 return self.mesh.GetNodePosition(NodeID)
1554 ## If the given element is a node, returns the ID of shape
1555 # \n If there is no node for the given ID - returns -1
1556 # @return an integer value
1557 # @ingroup l1_meshinfo
1558 def GetShapeID(self, id):
1559 return self.mesh.GetShapeID(id)
1561 ## Returns the ID of the result shape after
1562 # FindShape() from SMESH_MeshEditor for the given element
1563 # \n If there is no element for the given ID - returns -1
1564 # @return an integer value
1565 # @ingroup l1_meshinfo
1566 def GetShapeIDForElem(self,id):
1567 return self.mesh.GetShapeIDForElem(id)
1569 ## Returns the number of nodes for the given element
1570 # \n If there is no element for the given ID - returns -1
1571 # @return an integer value
1572 # @ingroup l1_meshinfo
1573 def GetElemNbNodes(self, id):
1574 return self.mesh.GetElemNbNodes(id)
1576 ## Returns the node ID the given index for the given element
1577 # \n If there is no element for the given ID - returns -1
1578 # \n If there is no node for the given index - returns -2
1579 # @return an integer value
1580 # @ingroup l1_meshinfo
1581 def GetElemNode(self, id, index):
1582 return self.mesh.GetElemNode(id, index)
1584 ## Returns the IDs of nodes of the given element
1585 # @return a list of integer values
1586 # @ingroup l1_meshinfo
1587 def GetElemNodes(self, id):
1588 return self.mesh.GetElemNodes(id)
1590 ## Returns true if the given node is the medium node in the given quadratic element
1591 # @ingroup l1_meshinfo
1592 def IsMediumNode(self, elementID, nodeID):
1593 return self.mesh.IsMediumNode(elementID, nodeID)
1595 ## Returns true if the given node is the medium node in one of quadratic elements
1596 # @ingroup l1_meshinfo
1597 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1598 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1600 ## Returns the number of edges for the given element
1601 # @ingroup l1_meshinfo
1602 def ElemNbEdges(self, id):
1603 return self.mesh.ElemNbEdges(id)
1605 ## Returns the number of faces for the given element
1606 # @ingroup l1_meshinfo
1607 def ElemNbFaces(self, id):
1608 return self.mesh.ElemNbFaces(id)
1610 ## Returns true if the given element is a polygon
1611 # @ingroup l1_meshinfo
1612 def IsPoly(self, id):
1613 return self.mesh.IsPoly(id)
1615 ## Returns true if the given element is quadratic
1616 # @ingroup l1_meshinfo
1617 def IsQuadratic(self, id):
1618 return self.mesh.IsQuadratic(id)
1620 ## Returns XYZ coordinates of the barycenter of the given element
1621 # \n If there is no element for the given ID - returns an empty list
1622 # @return a list of three double values
1623 # @ingroup l1_meshinfo
1624 def BaryCenter(self, id):
1625 return self.mesh.BaryCenter(id)
1628 # Mesh edition (SMESH_MeshEditor functionality):
1629 # ---------------------------------------------
1631 ## Removes the elements from the mesh by ids
1632 # @param IDsOfElements is a list of ids of elements to remove
1633 # @return True or False
1634 # @ingroup l2_modif_del
1635 def RemoveElements(self, IDsOfElements):
1636 return self.editor.RemoveElements(IDsOfElements)
1638 ## Removes nodes from mesh by ids
1639 # @param IDsOfNodes is a list of ids of nodes to remove
1640 # @return True or False
1641 # @ingroup l2_modif_del
1642 def RemoveNodes(self, IDsOfNodes):
1643 return self.editor.RemoveNodes(IDsOfNodes)
1645 ## Add a node to the mesh by coordinates
1646 # @return Id of the new node
1647 # @ingroup l2_modif_add
1648 def AddNode(self, x, y, z):
1649 return self.editor.AddNode( x, y, z)
1651 ## Creates a linear or quadratic edge (this is determined
1652 # by the number of given nodes).
1653 # @param IDsOfNodes the list of node IDs for creation of the element.
1654 # The order of nodes in this list should correspond to the description
1655 # of MED. \n This description is located by the following link:
1656 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1657 # @return the Id of the new edge
1658 # @ingroup l2_modif_add
1659 def AddEdge(self, IDsOfNodes):
1660 return self.editor.AddEdge(IDsOfNodes)
1662 ## Creates a linear or quadratic face (this is determined
1663 # by the number of given nodes).
1664 # @param IDsOfNodes the list of node IDs for creation of the element.
1665 # The order of nodes in this list should correspond to the description
1666 # of MED. \n This description is located by the following link:
1667 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1668 # @return the Id of the new face
1669 # @ingroup l2_modif_add
1670 def AddFace(self, IDsOfNodes):
1671 return self.editor.AddFace(IDsOfNodes)
1673 ## Adds a polygonal face to the mesh by the list of node IDs
1674 # @param IdsOfNodes the list of node IDs for creation of the element.
1675 # @return the Id of the new face
1676 # @ingroup l2_modif_add
1677 def AddPolygonalFace(self, IdsOfNodes):
1678 return self.editor.AddPolygonalFace(IdsOfNodes)
1680 ## Creates both simple and quadratic volume (this is determined
1681 # by the number of given nodes).
1682 # @param IDsOfNodes the list of node IDs for creation of the element.
1683 # The order of nodes in this list should correspond to the description
1684 # of MED. \n This description is located by the following link:
1685 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1686 # @return the Id of the new volumic element
1687 # @ingroup l2_modif_add
1688 def AddVolume(self, IDsOfNodes):
1689 return self.editor.AddVolume(IDsOfNodes)
1691 ## Creates a volume of many faces, giving nodes for each face.
1692 # @param IdsOfNodes the list of node IDs for volume creation face by face.
1693 # @param Quantities the list of integer values, Quantities[i]
1694 # gives the quantity of nodes in face number i.
1695 # @return the Id of the new volumic element
1696 # @ingroup l2_modif_add
1697 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1698 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1700 ## Creates a volume of many faces, giving the IDs of the existing faces.
1701 # @param IdsOfFaces the list of face IDs for volume creation.
1703 # Note: The created volume will refer only to the nodes
1704 # of the given faces, not to the faces themselves.
1705 # @return the Id of the new volumic element
1706 # @ingroup l2_modif_add
1707 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1708 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1711 ## @brief Binds a node to a vertex
1712 # @param NodeID a node ID
1713 # @param Vertex a vertex or vertex ID
1714 # @return True if succeed else raises an exception
1715 # @ingroup l2_modif_add
1716 def SetNodeOnVertex(self, NodeID, Vertex):
1717 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
1718 VertexID = Vertex.GetSubShapeIndices()[0]
1722 self.editor.SetNodeOnVertex(NodeID, VertexID)
1723 except SALOME.SALOME_Exception, inst:
1724 raise ValueError, inst.details.text
1728 ## @brief Stores the node position on an edge
1729 # @param NodeID a node ID
1730 # @param Edge an edge or edge ID
1731 # @param paramOnEdge a parameter on the edge where the node is located
1732 # @return True if succeed else raises an exception
1733 # @ingroup l2_modif_add
1734 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
1735 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
1736 EdgeID = Edge.GetSubShapeIndices()[0]
1740 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
1741 except SALOME.SALOME_Exception, inst:
1742 raise ValueError, inst.details.text
1745 ## @brief Stores node position on a face
1746 # @param NodeID a node ID
1747 # @param Face a face or face ID
1748 # @param u U parameter on the face where the node is located
1749 # @param v V parameter on the face where the node is located
1750 # @return True if succeed else raises an exception
1751 # @ingroup l2_modif_add
1752 def SetNodeOnFace(self, NodeID, Face, u, v):
1753 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
1754 FaceID = Face.GetSubShapeIndices()[0]
1758 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
1759 except SALOME.SALOME_Exception, inst:
1760 raise ValueError, inst.details.text
1763 ## @brief Binds a node to a solid
1764 # @param NodeID a node ID
1765 # @param Solid a solid or solid ID
1766 # @return True if succeed else raises an exception
1767 # @ingroup l2_modif_add
1768 def SetNodeInVolume(self, NodeID, Solid):
1769 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
1770 SolidID = Solid.GetSubShapeIndices()[0]
1774 self.editor.SetNodeInVolume(NodeID, SolidID)
1775 except SALOME.SALOME_Exception, inst:
1776 raise ValueError, inst.details.text
1779 ## @brief Bind an element to a shape
1780 # @param ElementID an element ID
1781 # @param Shape a shape or shape ID
1782 # @return True if succeed else raises an exception
1783 # @ingroup l2_modif_add
1784 def SetMeshElementOnShape(self, ElementID, Shape):
1785 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1786 ShapeID = Shape.GetSubShapeIndices()[0]
1790 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
1791 except SALOME.SALOME_Exception, inst:
1792 raise ValueError, inst.details.text
1796 ## Moves the node with the given id
1797 # @param NodeID the id of the node
1798 # @param x a new X coordinate
1799 # @param y a new Y coordinate
1800 # @param z a new Z coordinate
1801 # @return True if succeed else False
1802 # @ingroup l2_modif_movenode
1803 def MoveNode(self, NodeID, x, y, z):
1804 return self.editor.MoveNode(NodeID, x, y, z)
1806 ## Finds the node closest to a point
1807 # @param x the X coordinate of a point
1808 # @param y the Y coordinate of a point
1809 # @param z the Z coordinate of a point
1810 # @return the ID of a node
1811 # @ingroup l2_modif_throughp
1812 def FindNodeClosestTo(self, x, y, z):
1813 preview = self.mesh.GetMeshEditPreviewer()
1814 return preview.MoveClosestNodeToPoint(x, y, z, -1)
1816 ## Finds the node closest to a point and moves it to a point location
1817 # @param x the X coordinate of a point
1818 # @param y the Y coordinate of a point
1819 # @param z the Z coordinate of a point
1820 # @return the ID of a moved node
1821 # @ingroup l2_modif_throughp
1822 def MeshToPassThroughAPoint(self, x, y, z):
1823 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1825 ## Replaces two neighbour triangles sharing Node1-Node2 link
1826 # with the triangles built on the same 4 nodes but having other common link.
1827 # @param NodeID1 the ID of the first node
1828 # @param NodeID2 the ID of the second node
1829 # @return false if proper faces were not found
1830 # @ingroup l2_modif_invdiag
1831 def InverseDiag(self, NodeID1, NodeID2):
1832 return self.editor.InverseDiag(NodeID1, NodeID2)
1834 ## Replaces two neighbour triangles sharing Node1-Node2 link
1835 # with a quadrangle built on the same 4 nodes.
1836 # @param NodeID1 the ID of the first node
1837 # @param NodeID2 the ID of the second node
1838 # @return false if proper faces were not found
1839 # @ingroup l2_modif_unitetri
1840 def DeleteDiag(self, NodeID1, NodeID2):
1841 return self.editor.DeleteDiag(NodeID1, NodeID2)
1843 ## Reorients elements by ids
1844 # @param IDsOfElements if undefined reorients all mesh elements
1845 # @return True if succeed else False
1846 # @ingroup l2_modif_changori
1847 def Reorient(self, IDsOfElements=None):
1848 if IDsOfElements == None:
1849 IDsOfElements = self.GetElementsId()
1850 return self.editor.Reorient(IDsOfElements)
1852 ## Reorients all elements of the object
1853 # @param theObject mesh, submesh or group
1854 # @return True if succeed else False
1855 # @ingroup l2_modif_changori
1856 def ReorientObject(self, theObject):
1857 if ( isinstance( theObject, Mesh )):
1858 theObject = theObject.GetMesh()
1859 return self.editor.ReorientObject(theObject)
1861 ## Fuses the neighbouring triangles into quadrangles.
1862 # @param IDsOfElements The triangles to be fused,
1863 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1864 # @param MaxAngle is the maximum angle between element normals at which the fusion
1865 # is still performed; theMaxAngle is mesured in radians.
1866 # @return TRUE in case of success, FALSE otherwise.
1867 # @ingroup l2_modif_unitetri
1868 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1869 if IDsOfElements == []:
1870 IDsOfElements = self.GetElementsId()
1871 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1873 ## Fuses the neighbouring triangles of the object into quadrangles
1874 # @param theObject is mesh, submesh or group
1875 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1876 # @param MaxAngle a max angle between element normals at which the fusion
1877 # is still performed; theMaxAngle is mesured in radians.
1878 # @return TRUE in case of success, FALSE otherwise.
1879 # @ingroup l2_modif_unitetri
1880 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1881 if ( isinstance( theObject, Mesh )):
1882 theObject = theObject.GetMesh()
1883 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1885 ## Splits quadrangles into triangles.
1886 # @param IDsOfElements the faces to be splitted.
1887 # @param theCriterion FT_...; used to choose a diagonal for splitting.
1888 # @return TRUE in case of success, FALSE otherwise.
1889 # @ingroup l2_modif_cutquadr
1890 def QuadToTri (self, IDsOfElements, theCriterion):
1891 if IDsOfElements == []:
1892 IDsOfElements = self.GetElementsId()
1893 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
1895 ## Splits quadrangles into triangles.
1896 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
1897 # @param theCriterion FT_...; used to choose a diagonal for splitting.
1898 # @return TRUE in case of success, FALSE otherwise.
1899 # @ingroup l2_modif_cutquadr
1900 def QuadToTriObject (self, theObject, theCriterion):
1901 if ( isinstance( theObject, Mesh )):
1902 theObject = theObject.GetMesh()
1903 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
1905 ## Splits quadrangles into triangles.
1906 # @param IDsOfElements the faces to be splitted
1907 # @param Diag13 is used to choose a diagonal for splitting.
1908 # @return TRUE in case of success, FALSE otherwise.
1909 # @ingroup l2_modif_cutquadr
1910 def SplitQuad (self, IDsOfElements, Diag13):
1911 if IDsOfElements == []:
1912 IDsOfElements = self.GetElementsId()
1913 return self.editor.SplitQuad(IDsOfElements, Diag13)
1915 ## Splits quadrangles into triangles.
1916 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
1917 # @param Diag13 is used to choose a diagonal for splitting.
1918 # @return TRUE in case of success, FALSE otherwise.
1919 # @ingroup l2_modif_cutquadr
1920 def SplitQuadObject (self, theObject, Diag13):
1921 if ( isinstance( theObject, Mesh )):
1922 theObject = theObject.GetMesh()
1923 return self.editor.SplitQuadObject(theObject, Diag13)
1925 ## Finds a better splitting of the given quadrangle.
1926 # @param IDOfQuad the ID of the quadrangle to be splitted.
1927 # @param theCriterion FT_...; a criterion to choose a diagonal for splitting.
1928 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1929 # diagonal is better, 0 if error occurs.
1930 # @ingroup l2_modif_cutquadr
1931 def BestSplit (self, IDOfQuad, theCriterion):
1932 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
1934 ## Splits quadrangle faces near triangular facets of volumes
1936 # @ingroup l1_auxiliary
1937 def SplitQuadsNearTriangularFacets(self):
1938 faces_array = self.GetElementsByType(SMESH.FACE)
1939 for face_id in faces_array:
1940 if self.GetElemNbNodes(face_id) == 4: # quadrangle
1941 quad_nodes = self.mesh.GetElemNodes(face_id)
1942 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1943 isVolumeFound = False
1944 for node1_elem in node1_elems:
1945 if not isVolumeFound:
1946 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1947 nb_nodes = self.GetElemNbNodes(node1_elem)
1948 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1949 volume_elem = node1_elem
1950 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1951 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1952 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1953 isVolumeFound = True
1954 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1955 self.SplitQuad([face_id], False) # diagonal 2-4
1956 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1957 isVolumeFound = True
1958 self.SplitQuad([face_id], True) # diagonal 1-3
1959 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1960 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1961 isVolumeFound = True
1962 self.SplitQuad([face_id], True) # diagonal 1-3
1964 ## @brief Splits hexahedrons into tetrahedrons.
1966 # This operation uses pattern mapping functionality for splitting.
1967 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
1968 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
1969 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
1970 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
1971 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
1972 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
1973 # @return TRUE in case of success, FALSE otherwise.
1974 # @ingroup l1_auxiliary
1975 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
1976 # Pattern: 5.---------.6
1981 # (0,0,1) 4.---------.7 * |
1988 # (0,0,0) 0.---------.3
1989 pattern_tetra = "!!! Nb of points: \n 8 \n\
1999 !!! Indices of points of 6 tetras: \n\
2007 pattern = self.smeshpyD.GetPattern()
2008 isDone = pattern.LoadFromFile(pattern_tetra)
2010 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2013 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2014 isDone = pattern.MakeMesh(self.mesh, False, False)
2015 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2017 # split quafrangle faces near triangular facets of volumes
2018 self.SplitQuadsNearTriangularFacets()
2022 ## @brief Split hexahedrons into prisms.
2024 # Uses the pattern mapping functionality for splitting.
2025 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2026 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2027 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2028 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2029 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2030 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2031 # @return TRUE in case of success, FALSE otherwise.
2032 # @ingroup l1_auxiliary
2033 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2034 # Pattern: 5.---------.6
2039 # (0,0,1) 4.---------.7 |
2046 # (0,0,0) 0.---------.3
2047 pattern_prism = "!!! Nb of points: \n 8 \n\
2057 !!! Indices of points of 2 prisms: \n\
2061 pattern = self.smeshpyD.GetPattern()
2062 isDone = pattern.LoadFromFile(pattern_prism)
2064 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2067 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2068 isDone = pattern.MakeMesh(self.mesh, False, False)
2069 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2071 # Splits quafrangle faces near triangular facets of volumes
2072 self.SplitQuadsNearTriangularFacets()
2076 ## Smoothes elements
2077 # @param IDsOfElements the list if ids of elements to smooth
2078 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2079 # Note that nodes built on edges and boundary nodes are always fixed.
2080 # @param MaxNbOfIterations the maximum number of iterations
2081 # @param MaxAspectRatio varies in range [1.0, inf]
2082 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2083 # @return TRUE in case of success, FALSE otherwise.
2084 # @ingroup l2_modif_smooth
2085 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2086 MaxNbOfIterations, MaxAspectRatio, Method):
2087 if IDsOfElements == []:
2088 IDsOfElements = self.GetElementsId()
2089 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2090 MaxNbOfIterations, MaxAspectRatio, Method)
2092 ## Smoothes elements which belong to the given object
2093 # @param theObject the object to smooth
2094 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2095 # Note that nodes built on edges and boundary nodes are always fixed.
2096 # @param MaxNbOfIterations the maximum number of iterations
2097 # @param MaxAspectRatio varies in range [1.0, inf]
2098 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2099 # @return TRUE in case of success, FALSE otherwise.
2100 # @ingroup l2_modif_smooth
2101 def SmoothObject(self, theObject, IDsOfFixedNodes,
2102 MaxNbOfIterations, MaxAspectRatio, Method):
2103 if ( isinstance( theObject, Mesh )):
2104 theObject = theObject.GetMesh()
2105 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2106 MaxNbOfIterations, MaxAspectRatio, Method)
2108 ## Parametrically smoothes the given elements
2109 # @param IDsOfElements the list if ids of elements to smooth
2110 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2111 # Note that nodes built on edges and boundary nodes are always fixed.
2112 # @param MaxNbOfIterations the maximum number of iterations
2113 # @param MaxAspectRatio varies in range [1.0, inf]
2114 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2115 # @return TRUE in case of success, FALSE otherwise.
2116 # @ingroup l2_modif_smooth
2117 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2118 MaxNbOfIterations, MaxAspectRatio, Method):
2119 if IDsOfElements == []:
2120 IDsOfElements = self.GetElementsId()
2121 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2122 MaxNbOfIterations, MaxAspectRatio, Method)
2124 ## Parametrically smoothes the elements which belong to the given object
2125 # @param theObject the object to smooth
2126 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2127 # Note that nodes built on edges and boundary nodes are always fixed.
2128 # @param MaxNbOfIterations the maximum number of iterations
2129 # @param MaxAspectRatio varies in range [1.0, inf]
2130 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2131 # @return TRUE in case of success, FALSE otherwise.
2132 # @ingroup l2_modif_smooth
2133 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2134 MaxNbOfIterations, MaxAspectRatio, Method):
2135 if ( isinstance( theObject, Mesh )):
2136 theObject = theObject.GetMesh()
2137 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2138 MaxNbOfIterations, MaxAspectRatio, Method)
2140 ## Converts the mesh to quadratic, deletes old elements, replacing
2141 # them with quadratic with the same id.
2142 # @ingroup l2_modif_tofromqu
2143 def ConvertToQuadratic(self, theForce3d):
2144 self.editor.ConvertToQuadratic(theForce3d)
2146 ## Converts the mesh from quadratic to ordinary,
2147 # deletes old quadratic elements, \n replacing
2148 # them with ordinary mesh elements with the same id.
2149 # @return TRUE in case of success, FALSE otherwise.
2150 # @ingroup l2_modif_tofromqu
2151 def ConvertFromQuadratic(self):
2152 return self.editor.ConvertFromQuadratic()
2154 ## Renumber mesh nodes
2155 # @ingroup l2_modif_renumber
2156 def RenumberNodes(self):
2157 self.editor.RenumberNodes()
2159 ## Renumber mesh elements
2160 # @ingroup l2_modif_renumber
2161 def RenumberElements(self):
2162 self.editor.RenumberElements()
2164 ## Generates new elements by rotation of the elements around the axis
2165 # @param IDsOfElements the list of ids of elements to sweep
2166 # @param Axis the axis of rotation, AxisStruct or line(geom object)
2167 # @param AngleInRadians the angle of Rotation
2168 # @param NbOfSteps the number of steps
2169 # @param Tolerance tolerance
2170 # @param MakeGroups forces the generation of new groups from existing ones
2171 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
2172 # of all steps, else - size of each step
2173 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2174 # @ingroup l2_modif_extrurev
2175 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
2176 MakeGroups=False, TotalAngle=False):
2177 if IDsOfElements == []:
2178 IDsOfElements = self.GetElementsId()
2179 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2180 Axis = self.smeshpyD.GetAxisStruct(Axis)
2181 if TotalAngle and NbOfSteps:
2182 AngleInRadians /= NbOfSteps
2184 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
2185 AngleInRadians, NbOfSteps, Tolerance)
2186 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
2189 ## Generates new elements by rotation of the elements of object around the axis
2190 # @param theObject object which elements should be sweeped
2191 # @param Axis the axis of rotation, AxisStruct or line(geom object)
2192 # @param AngleInRadians the angle of Rotation
2193 # @param NbOfSteps number of steps
2194 # @param Tolerance tolerance
2195 # @param MakeGroups forces the generation of new groups from existing ones
2196 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
2197 # of all steps, else - size of each step
2198 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2199 # @ingroup l2_modif_extrurev
2200 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
2201 MakeGroups=False, TotalAngle=False):
2202 if ( isinstance( theObject, Mesh )):
2203 theObject = theObject.GetMesh()
2204 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2205 Axis = self.smeshpyD.GetAxisStruct(Axis)
2206 if TotalAngle and NbOfSteps:
2207 AngleInRadians /= NbOfSteps
2209 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
2210 NbOfSteps, Tolerance)
2211 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
2214 ## Generates new elements by extrusion of the elements with given ids
2215 # @param IDsOfElements the list of elements ids for extrusion
2216 # @param StepVector vector, defining the direction and value of extrusion
2217 # @param NbOfSteps the number of steps
2218 # @param MakeGroups forces the generation of new groups from existing ones
2219 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2220 # @ingroup l2_modif_extrurev
2221 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2222 if IDsOfElements == []:
2223 IDsOfElements = self.GetElementsId()
2224 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2225 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2227 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2228 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2231 ## Generates new elements by extrusion of the elements with given ids
2232 # @param IDsOfElements is ids of elements
2233 # @param StepVector vector, defining the direction and value of extrusion
2234 # @param NbOfSteps the number of steps
2235 # @param ExtrFlags sets flags for extrusion
2236 # @param SewTolerance uses for comparing locations of nodes if flag
2237 # EXTRUSION_FLAG_SEW is set
2238 # @param MakeGroups forces the generation of new groups from existing ones
2239 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2240 # @ingroup l2_modif_extrurev
2241 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
2242 ExtrFlags, SewTolerance, MakeGroups=False):
2243 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2244 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2246 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2247 ExtrFlags, SewTolerance)
2248 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2249 ExtrFlags, SewTolerance)
2252 ## Generates new elements by extrusion of the elements which belong to the object
2253 # @param theObject the object which elements should be processed
2254 # @param StepVector vector, defining the direction and value of extrusion
2255 # @param NbOfSteps the number of steps
2256 # @param MakeGroups forces the generation of new groups from existing ones
2257 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2258 # @ingroup l2_modif_extrurev
2259 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2260 if ( isinstance( theObject, Mesh )):
2261 theObject = theObject.GetMesh()
2262 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2263 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2265 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2266 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2269 ## Generates new elements by extrusion of the elements which belong to the object
2270 # @param theObject object which elements should be processed
2271 # @param StepVector vector, defining the direction and value of extrusion
2272 # @param NbOfSteps the number of steps
2273 # @param MakeGroups to generate new groups from existing ones
2274 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2275 # @ingroup l2_modif_extrurev
2276 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2277 if ( isinstance( theObject, Mesh )):
2278 theObject = theObject.GetMesh()
2279 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2280 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2282 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2283 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2286 ## Generates new elements by extrusion of the elements which belong to the object
2287 # @param theObject object which elements should be processed
2288 # @param StepVector vector, defining the direction and value of extrusion
2289 # @param NbOfSteps the number of steps
2290 # @param MakeGroups forces the generation of new groups from existing ones
2291 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2292 # @ingroup l2_modif_extrurev
2293 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2294 if ( isinstance( theObject, Mesh )):
2295 theObject = theObject.GetMesh()
2296 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2297 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2299 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2300 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2303 ## Generates new elements by extrusion of the given elements
2304 # The path of extrusion must be a meshed edge.
2305 # @param IDsOfElements ids of elements
2306 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2307 # @param PathShape shape(edge) defines the sub-mesh for the path
2308 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2309 # @param HasAngles allows the shape to be rotated around the path
2310 # to get the resulting mesh in a helical fashion
2311 # @param Angles list of angles
2312 # @param HasRefPoint allows using the reference point
2313 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2314 # The User can specify any point as the Reference Point.
2315 # @param MakeGroups forces the generation of new groups from existing ones
2316 # @param LinearVariation forces the computation of rotation angles as linear
2317 # variation of the given Angles along path steps
2318 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2319 # only SMESH::Extrusion_Error otherwise
2320 # @ingroup l2_modif_extrurev
2321 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2322 HasAngles, Angles, HasRefPoint, RefPoint,
2323 MakeGroups=False, LinearVariation=False):
2324 if IDsOfElements == []:
2325 IDsOfElements = self.GetElementsId()
2326 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2327 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2329 if ( isinstance( PathMesh, Mesh )):
2330 PathMesh = PathMesh.GetMesh()
2331 if HasAngles and Angles and LinearVariation:
2332 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2335 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
2336 PathShape, NodeStart, HasAngles,
2337 Angles, HasRefPoint, RefPoint)
2338 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
2339 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2341 ## Generates new elements by extrusion of the elements which belong to the object
2342 # The path of extrusion must be a meshed edge.
2343 # @param theObject the object which elements should be processed
2344 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
2345 # @param PathShape shape(edge) defines the sub-mesh for the path
2346 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2347 # @param HasAngles allows the shape to be rotated around the path
2348 # to get the resulting mesh in a helical fashion
2349 # @param Angles list of angles
2350 # @param HasRefPoint allows using the reference point
2351 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2352 # The User can specify any point as the Reference Point.
2353 # @param MakeGroups forces the generation of new groups from existing ones
2354 # @param LinearVariation forces the computation of rotation angles as linear
2355 # variation of the given Angles along path steps
2356 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2357 # only SMESH::Extrusion_Error otherwise
2358 # @ingroup l2_modif_extrurev
2359 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2360 HasAngles, Angles, HasRefPoint, RefPoint,
2361 MakeGroups=False, LinearVariation=False):
2362 if ( isinstance( theObject, Mesh )):
2363 theObject = theObject.GetMesh()
2364 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2365 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2366 if ( isinstance( PathMesh, Mesh )):
2367 PathMesh = PathMesh.GetMesh()
2368 if HasAngles and Angles and LinearVariation:
2369 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2372 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
2373 PathShape, NodeStart, HasAngles,
2374 Angles, HasRefPoint, RefPoint)
2375 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
2376 NodeStart, HasAngles, Angles, HasRefPoint,
2379 ## Creates a symmetrical copy of mesh elements
2380 # @param IDsOfElements list of elements ids
2381 # @param Mirror is AxisStruct or geom object(point, line, plane)
2382 # @param theMirrorType is POINT, AXIS or PLANE
2383 # If the Mirror is a geom object this parameter is unnecessary
2384 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
2385 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2386 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2387 # @ingroup l2_modif_trsf
2388 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2389 if IDsOfElements == []:
2390 IDsOfElements = self.GetElementsId()
2391 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2392 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2393 if Copy and MakeGroups:
2394 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2395 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2398 ## Creates a new mesh by a symmetrical copy of mesh elements
2399 # @param IDsOfElements the list of elements ids
2400 # @param Mirror is AxisStruct or geom object (point, line, plane)
2401 # @param theMirrorType is POINT, AXIS or PLANE
2402 # If the Mirror is a geom object this parameter is unnecessary
2403 # @param MakeGroups to generate new groups from existing ones
2404 # @param NewMeshName a name of the new mesh to create
2405 # @return instance of Mesh class
2406 # @ingroup l2_modif_trsf
2407 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
2408 if IDsOfElements == []:
2409 IDsOfElements = self.GetElementsId()
2410 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2411 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2412 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
2413 MakeGroups, NewMeshName)
2414 return Mesh(self.smeshpyD,self.geompyD,mesh)
2416 ## Creates a symmetrical copy of the object
2417 # @param theObject mesh, submesh or group
2418 # @param Mirror AxisStruct or geom object (point, line, plane)
2419 # @param theMirrorType is POINT, AXIS or PLANE
2420 # If the Mirror is a geom object this parameter is unnecessary
2421 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
2422 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2423 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2424 # @ingroup l2_modif_trsf
2425 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2426 if ( isinstance( theObject, Mesh )):
2427 theObject = theObject.GetMesh()
2428 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2429 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2430 if Copy and MakeGroups:
2431 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2432 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2435 ## Creates a new mesh by a symmetrical copy of the object
2436 # @param theObject mesh, submesh or group
2437 # @param Mirror AxisStruct or geom object (point, line, plane)
2438 # @param theMirrorType POINT, AXIS or PLANE
2439 # If the Mirror is a geom object this parameter is unnecessary
2440 # @param MakeGroups forces the generation of new groups from existing ones
2441 # @param NewMeshName the name of the new mesh to create
2442 # @return instance of Mesh class
2443 # @ingroup l2_modif_trsf
2444 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
2445 if ( isinstance( theObject, Mesh )):
2446 theObject = theObject.GetMesh()
2447 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2448 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2449 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
2450 MakeGroups, NewMeshName)
2451 return Mesh( self.smeshpyD,self.geompyD,mesh )
2453 ## Translates the elements
2454 # @param IDsOfElements list of elements ids
2455 # @param Vector the direction of translation (DirStruct or vector)
2456 # @param Copy allows copying the translated elements
2457 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2458 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2459 # @ingroup l2_modif_trsf
2460 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2461 if IDsOfElements == []:
2462 IDsOfElements = self.GetElementsId()
2463 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2464 Vector = self.smeshpyD.GetDirStruct(Vector)
2465 if Copy and MakeGroups:
2466 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2467 self.editor.Translate(IDsOfElements, Vector, Copy)
2470 ## Creates a new mesh of translated elements
2471 # @param IDsOfElements list of elements ids
2472 # @param Vector the direction of translation (DirStruct or vector)
2473 # @param MakeGroups forces the generation of new groups from existing ones
2474 # @param NewMeshName the name of the newly created mesh
2475 # @return instance of Mesh class
2476 # @ingroup l2_modif_trsf
2477 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
2478 if IDsOfElements == []:
2479 IDsOfElements = self.GetElementsId()
2480 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2481 Vector = self.smeshpyD.GetDirStruct(Vector)
2482 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
2483 return Mesh ( self.smeshpyD, self.geompyD, mesh )
2485 ## Translates the object
2486 # @param theObject the object to translate (mesh, submesh, or group)
2487 # @param Vector direction of translation (DirStruct or geom vector)
2488 # @param Copy allows copying the translated elements
2489 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2490 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2491 # @ingroup l2_modif_trsf
2492 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2493 if ( isinstance( theObject, Mesh )):
2494 theObject = theObject.GetMesh()
2495 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2496 Vector = self.smeshpyD.GetDirStruct(Vector)
2497 if Copy and MakeGroups:
2498 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2499 self.editor.TranslateObject(theObject, Vector, Copy)
2502 ## Creates a new mesh from the translated object
2503 # @param theObject the object to translate (mesh, submesh, or group)
2504 # @param Vector the direction of translation (DirStruct or geom vector)
2505 # @param MakeGroups forces the generation of new groups from existing ones
2506 # @param NewMeshName the name of the newly created mesh
2507 # @return instance of Mesh class
2508 # @ingroup l2_modif_trsf
2509 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
2510 if (isinstance(theObject, Mesh)):
2511 theObject = theObject.GetMesh()
2512 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
2513 Vector = self.smeshpyD.GetDirStruct(Vector)
2514 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
2515 return Mesh( self.smeshpyD, self.geompyD, mesh )
2517 ## Rotates the elements
2518 # @param IDsOfElements list of elements ids
2519 # @param Axis the axis of rotation (AxisStruct or geom line)
2520 # @param AngleInRadians the angle of rotation (in radians)
2521 # @param Copy allows copying the rotated elements
2522 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2523 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2524 # @ingroup l2_modif_trsf
2525 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2526 if IDsOfElements == []:
2527 IDsOfElements = self.GetElementsId()
2528 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2529 Axis = self.smeshpyD.GetAxisStruct(Axis)
2530 if Copy and MakeGroups:
2531 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2532 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2535 ## Creates a new mesh of rotated elements
2536 # @param IDsOfElements list of element ids
2537 # @param Axis the axis of rotation (AxisStruct or geom line)
2538 # @param AngleInRadians the angle of rotation (in radians)
2539 # @param MakeGroups forces the generation of new groups from existing ones
2540 # @param NewMeshName the name of the newly created mesh
2541 # @return instance of Mesh class
2542 # @ingroup l2_modif_trsf
2543 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
2544 if IDsOfElements == []:
2545 IDsOfElements = self.GetElementsId()
2546 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2547 Axis = self.smeshpyD.GetAxisStruct(Axis)
2548 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
2549 MakeGroups, NewMeshName)
2550 return Mesh( self.smeshpyD, self.geompyD, mesh )
2552 ## Rotates the object
2553 # @param theObject the object to rotate( mesh, submesh, or group)
2554 # @param Axis the axis of rotation (AxisStruct or geom line)
2555 # @param AngleInRadians the angle of rotation (in radians)
2556 # @param Copy allows copying the rotated elements
2557 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2558 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2559 # @ingroup l2_modif_trsf
2560 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2561 if (isinstance(theObject, Mesh)):
2562 theObject = theObject.GetMesh()
2563 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2564 Axis = self.smeshpyD.GetAxisStruct(Axis)
2565 if Copy and MakeGroups:
2566 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2567 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2570 ## Creates a new mesh from the rotated object
2571 # @param theObject the object to rotate (mesh, submesh, or group)
2572 # @param Axis the axis of rotation (AxisStruct or geom line)
2573 # @param AngleInRadians the angle of rotation (in radians)
2574 # @param MakeGroups forces the generation of new groups from existing ones
2575 # @param NewMeshName the name of the newly created mesh
2576 # @return instance of Mesh class
2577 # @ingroup l2_modif_trsf
2578 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
2579 if (isinstance( theObject, Mesh )):
2580 theObject = theObject.GetMesh()
2581 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2582 Axis = self.smeshpyD.GetAxisStruct(Axis)
2583 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
2584 MakeGroups, NewMeshName)
2585 return Mesh( self.smeshpyD, self.geompyD, mesh )
2587 ## Finds groups of ajacent nodes within Tolerance.
2588 # @param Tolerance the value of tolerance
2589 # @return the list of groups of nodes
2590 # @ingroup l2_modif_trsf
2591 def FindCoincidentNodes (self, Tolerance):
2592 return self.editor.FindCoincidentNodes(Tolerance)
2594 ## Finds groups of ajacent nodes within Tolerance.
2595 # @param Tolerance the value of tolerance
2596 # @param SubMeshOrGroup SubMesh or Group
2597 # @return the list of groups of nodes
2598 # @ingroup l2_modif_trsf
2599 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2600 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2603 # @param GroupsOfNodes the list of groups of nodes
2604 # @ingroup l2_modif_trsf
2605 def MergeNodes (self, GroupsOfNodes):
2606 self.editor.MergeNodes(GroupsOfNodes)
2608 ## Finds the elements built on the same nodes.
2609 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2610 # @return a list of groups of equal elements
2611 # @ingroup l2_modif_trsf
2612 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2613 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2615 ## Merges elements in each given group.
2616 # @param GroupsOfElementsID groups of elements for merging
2617 # @ingroup l2_modif_trsf
2618 def MergeElements(self, GroupsOfElementsID):
2619 self.editor.MergeElements(GroupsOfElementsID)
2621 ## Leaves one element and removes all other elements built on the same nodes.
2622 # @ingroup l2_modif_trsf
2623 def MergeEqualElements(self):
2624 self.editor.MergeEqualElements()
2626 ## Sews free borders
2627 # @return SMESH::Sew_Error
2628 # @ingroup l2_modif_trsf
2629 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2630 FirstNodeID2, SecondNodeID2, LastNodeID2,
2631 CreatePolygons, CreatePolyedrs):
2632 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2633 FirstNodeID2, SecondNodeID2, LastNodeID2,
2634 CreatePolygons, CreatePolyedrs)
2636 ## Sews conform free borders
2637 # @return SMESH::Sew_Error
2638 # @ingroup l2_modif_trsf
2639 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2640 FirstNodeID2, SecondNodeID2):
2641 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2642 FirstNodeID2, SecondNodeID2)
2644 ## Sews border to side
2645 # @return SMESH::Sew_Error
2646 # @ingroup l2_modif_trsf
2647 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2648 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2649 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2650 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2652 ## Sews two sides of a mesh. The nodes belonging to Side1 are
2653 # merged with the nodes of elements of Side2.
2654 # The number of elements in theSide1 and in theSide2 must be
2655 # equal and they should have similar nodal connectivity.
2656 # The nodes to merge should belong to side borders and
2657 # the first node should be linked to the second.
2658 # @return SMESH::Sew_Error
2659 # @ingroup l2_modif_trsf
2660 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2661 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2662 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2663 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2664 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2665 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2667 ## Sets new nodes for the given element.
2668 # @param ide the element id
2669 # @param newIDs nodes ids
2670 # @return If the number of nodes does not correspond to the type of element - returns false
2671 # @ingroup l2_modif_edit
2672 def ChangeElemNodes(self, ide, newIDs):
2673 return self.editor.ChangeElemNodes(ide, newIDs)
2675 ## If during the last operation of MeshEditor some nodes were
2676 # created, this method returns the list of their IDs, \n
2677 # if new nodes were not created - returns empty list
2678 # @return the list of integer values (can be empty)
2679 # @ingroup l1_auxiliary
2680 def GetLastCreatedNodes(self):
2681 return self.editor.GetLastCreatedNodes()
2683 ## If during the last operation of MeshEditor some elements were
2684 # created this method returns the list of their IDs, \n
2685 # if new elements were not created - returns empty list
2686 # @return the list of integer values (can be empty)
2687 # @ingroup l1_auxiliary
2688 def GetLastCreatedElems(self):
2689 return self.editor.GetLastCreatedElems()
2691 ## The mother class to define algorithm, it is not recommended to use it directly.
2694 # @ingroup l2_algorithms
2695 class Mesh_Algorithm:
2696 # @class Mesh_Algorithm
2697 # @brief Class Mesh_Algorithm
2699 #def __init__(self,smesh):
2707 ## Finds a hypothesis in the study by its type name and parameters.
2708 # Finds only the hypotheses created in smeshpyD engine.
2709 # @return SMESH.SMESH_Hypothesis
2710 def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
2711 study = smeshpyD.GetCurrentStudy()
2712 #to do: find component by smeshpyD object, not by its data type
2713 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2714 if scomp is not None:
2715 res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
2716 # Check if the root label of the hypotheses exists
2717 if res and hypRoot is not None:
2718 iter = study.NewChildIterator(hypRoot)
2719 # Check all published hypotheses
2721 hypo_so_i = iter.Value()
2722 attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
2723 if attr is not None:
2724 anIOR = attr.Value()
2725 hypo_o_i = salome.orb.string_to_object(anIOR)
2726 if hypo_o_i is not None:
2727 # Check if this is a hypothesis
2728 hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
2729 if hypo_i is not None:
2730 # Check if the hypothesis belongs to current engine
2731 if smeshpyD.GetObjectId(hypo_i) > 0:
2732 # Check if this is the required hypothesis
2733 if hypo_i.GetName() == hypname:
2735 if CompareMethod(hypo_i, args):
2749 ## Finds the algorithm in the study by its type name.
2750 # Finds only the algorithms, which have been created in smeshpyD engine.
2751 # @return SMESH.SMESH_Algo
2752 def FindAlgorithm (self, algoname, smeshpyD):
2753 study = smeshpyD.GetCurrentStudy()
2754 #to do: find component by smeshpyD object, not by its data type
2755 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2756 if scomp is not None:
2757 res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
2758 # Check if the root label of the algorithms exists
2759 if res and hypRoot is not None:
2760 iter = study.NewChildIterator(hypRoot)
2761 # Check all published algorithms
2763 algo_so_i = iter.Value()
2764 attr = algo_so_i.FindAttribute("AttributeIOR")[1]
2765 if attr is not None:
2766 anIOR = attr.Value()
2767 algo_o_i = salome.orb.string_to_object(anIOR)
2768 if algo_o_i is not None:
2769 # Check if this is an algorithm
2770 algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
2771 if algo_i is not None:
2772 # Checks if the algorithm belongs to the current engine
2773 if smeshpyD.GetObjectId(algo_i) > 0:
2774 # Check if this is the required algorithm
2775 if algo_i.GetName() == algoname:
2788 ## If the algorithm is global, returns 0; \n
2789 # else returns the submesh associated to this algorithm.
2790 def GetSubMesh(self):
2793 ## Returns the wrapped mesher.
2794 def GetAlgorithm(self):
2797 ## Gets the list of hypothesis that can be used with this algorithm
2798 def GetCompatibleHypothesis(self):
2801 mylist = self.algo.GetCompatibleHypothesis()
2804 ## Gets the name of the algorithm
2808 ## Sets the name to the algorithm
2809 def SetName(self, name):
2810 SetName(self.algo, name)
2812 ## Gets the id of the algorithm
2814 return self.algo.GetId()
2817 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
2819 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
2820 algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
2822 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
2824 self.Assign(algo, mesh, geom)
2828 def Assign(self, algo, mesh, geom):
2830 raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
2837 name = GetName(geom)
2839 name = mesh.geompyD.SubShapeName(geom, piece)
2840 mesh.geompyD.addToStudyInFather(piece, geom, name)
2841 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
2844 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
2845 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
2847 def CompareHyp (self, hyp, args):
2848 print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
2851 def CompareEqualHyp (self, hyp, args):
2855 def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
2856 UseExisting=0, CompareMethod=""):
2859 if CompareMethod == "": CompareMethod = self.CompareHyp
2860 hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
2863 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
2869 a = a + s + str(args[i])
2873 SetName(hypo, hyp + a)
2875 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
2876 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
2880 # Public class: Mesh_Segment
2881 # --------------------------
2883 ## Class to define a segment 1D algorithm for discretization
2886 # @ingroup l3_algos_basic
2887 class Mesh_Segment(Mesh_Algorithm):
2889 ## Private constructor.
2890 def __init__(self, mesh, geom=0):
2891 Mesh_Algorithm.__init__(self)
2892 self.Create(mesh, geom, "Regular_1D")
2894 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
2895 # @param l for the length of segments that cut an edge
2896 # @param UseExisting if ==true - searches for an existing hypothesis created with
2897 # the same parameters, else (default) - creates a new one
2898 # @param p precision, used for calculation of the number of segments.
2899 # The precision should be a positive, meaningful value within the range [0,1].
2900 # In general, the number of segments is calculated with the formula:
2901 # nb = ceil((edge_length / l) - p)
2902 # Function ceil rounds its argument to the higher integer.
2903 # So, p=0 means rounding of (edge_length / l) to the higher integer,
2904 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
2905 # p=1 means rounding of (edge_length / l) to the lower integer.
2906 # Default value is 1e-07.
2907 # @return an instance of StdMeshers_LocalLength hypothesis
2908 # @ingroup l3_hypos_1dhyps
2909 def LocalLength(self, l, UseExisting=0, p=1e-07):
2910 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
2911 CompareMethod=self.CompareLocalLength)
2917 ## Checks if the given "LocalLength" hypothesis has the same parameters as the given arguments
2918 def CompareLocalLength(self, hyp, args):
2919 if IsEqual(hyp.GetLength(), args[0]):
2920 return IsEqual(hyp.GetPrecision(), args[1])
2923 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
2924 # @param n for the number of segments that cut an edge
2925 # @param s for the scale factor (optional)
2926 # @param UseExisting if ==true - searches for an existing hypothesis created with
2927 # the same parameters, else (default) - create a new one
2928 # @return an instance of StdMeshers_NumberOfSegments hypothesis
2929 # @ingroup l3_hypos_1dhyps
2930 def NumberOfSegments(self, n, s=[], UseExisting=0):
2932 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
2933 CompareMethod=self.CompareNumberOfSegments)
2935 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
2936 CompareMethod=self.CompareNumberOfSegments)
2937 hyp.SetDistrType( 1 )
2938 hyp.SetScaleFactor(s)
2939 hyp.SetNumberOfSegments(n)
2943 ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
2944 def CompareNumberOfSegments(self, hyp, args):
2945 if hyp.GetNumberOfSegments() == args[0]:
2949 if hyp.GetDistrType() == 1:
2950 if IsEqual(hyp.GetScaleFactor(), args[1]):
2954 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
2955 # @param start defines the length of the first segment
2956 # @param end defines the length of the last segment
2957 # @param UseExisting if ==true - searches for an existing hypothesis created with
2958 # the same parameters, else (default) - creates a new one
2959 # @return an instance of StdMeshers_Arithmetic1D hypothesis
2960 # @ingroup l3_hypos_1dhyps
2961 def Arithmetic1D(self, start, end, UseExisting=0):
2962 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
2963 CompareMethod=self.CompareArithmetic1D)
2964 hyp.SetLength(start, 1)
2965 hyp.SetLength(end , 0)
2969 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as the given arguments
2970 def CompareArithmetic1D(self, hyp, args):
2971 if IsEqual(hyp.GetLength(1), args[0]):
2972 if IsEqual(hyp.GetLength(0), args[1]):
2976 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
2977 # @param start defines the length of the first segment
2978 # @param end defines the length of the last segment
2979 # @param UseExisting if ==true - searches for an existing hypothesis created with
2980 # the same parameters, else (default) - creates a new one
2981 # @return an instance of StdMeshers_StartEndLength hypothesis
2982 # @ingroup l3_hypos_1dhyps
2983 def StartEndLength(self, start, end, UseExisting=0):
2984 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
2985 CompareMethod=self.CompareStartEndLength)
2986 hyp.SetLength(start, 1)
2987 hyp.SetLength(end , 0)
2990 ## Check if the given "StartEndLength" hypothesis has the same parameters as the given arguments
2991 def CompareStartEndLength(self, hyp, args):
2992 if IsEqual(hyp.GetLength(1), args[0]):
2993 if IsEqual(hyp.GetLength(0), args[1]):
2997 ## Defines "Deflection1D" hypothesis
2998 # @param d for the deflection
2999 # @param UseExisting if ==true - searches for an existing hypothesis created with
3000 # the same parameters, else (default) - create a new one
3001 # @ingroup l3_hypos_1dhyps
3002 def Deflection1D(self, d, UseExisting=0):
3003 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
3004 CompareMethod=self.CompareDeflection1D)
3005 hyp.SetDeflection(d)
3008 ## Check if the given "Deflection1D" hypothesis has the same parameters as the given arguments
3009 def CompareDeflection1D(self, hyp, args):
3010 return IsEqual(hyp.GetDeflection(), args[0])
3012 ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
3013 # the opposite side in case of quadrangular faces
3014 # @ingroup l3_hypos_additi
3015 def Propagation(self):
3016 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3018 ## Defines "AutomaticLength" hypothesis
3019 # @param fineness for the fineness [0-1]
3020 # @param UseExisting if ==true - searches for an existing hypothesis created with the
3021 # same parameters, else (default) - create a new one
3022 # @ingroup l3_hypos_1dhyps
3023 def AutomaticLength(self, fineness=0, UseExisting=0):
3024 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
3025 CompareMethod=self.CompareAutomaticLength)
3026 hyp.SetFineness( fineness )
3029 ## Checks if the given "AutomaticLength" hypothesis has the same parameters as the given arguments
3030 def CompareAutomaticLength(self, hyp, args):
3031 return IsEqual(hyp.GetFineness(), args[0])
3033 ## Defines "SegmentLengthAroundVertex" hypothesis
3034 # @param length for the segment length
3035 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
3036 # Any other integer value means that the hypothesis will be set on the
3037 # whole 1D shape, where Mesh_Segment algorithm is assigned.
3038 # @param UseExisting if ==true - searches for an existing hypothesis created with
3039 # the same parameters, else (default) - creates a new one
3040 # @ingroup l3_algos_segmarv
3041 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
3043 store_geom = self.geom
3044 if type(vertex) is types.IntType:
3045 if vertex == 0 or vertex == 1:
3046 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
3054 if self.geom is None:
3055 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
3056 name = GetName(self.geom)
3058 piece = self.mesh.geom
3059 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
3060 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
3061 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
3063 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
3065 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
3066 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
3068 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
3069 CompareMethod=self.CompareLengthNearVertex)
3070 self.geom = store_geom
3071 hyp.SetLength( length )
3074 ## Checks if the given "LengthNearVertex" hypothesis has the same parameters as the given arguments
3075 # @ingroup l3_algos_segmarv
3076 def CompareLengthNearVertex(self, hyp, args):
3077 return IsEqual(hyp.GetLength(), args[0])
3079 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
3080 # If the 2D mesher sees that all boundary edges are quadratic,
3081 # it generates quadratic faces, else it generates linear faces using
3082 # medium nodes as if they are vertices.
3083 # The 3D mesher generates quadratic volumes only if all boundary faces
3084 # are quadratic, else it fails.
3086 # @ingroup l3_hypos_additi
3087 def QuadraticMesh(self):
3088 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3091 # Public class: Mesh_CompositeSegment
3092 # --------------------------
3094 ## Defines a segment 1D algorithm for discretization
3096 # @ingroup l3_algos_basic
3097 class Mesh_CompositeSegment(Mesh_Segment):
3099 ## Private constructor.
3100 def __init__(self, mesh, geom=0):
3101 self.Create(mesh, geom, "CompositeSegment_1D")
3104 # Public class: Mesh_Segment_Python
3105 # ---------------------------------
3107 ## Defines a segment 1D algorithm for discretization with python function
3109 # @ingroup l3_algos_basic
3110 class Mesh_Segment_Python(Mesh_Segment):
3112 ## Private constructor.
3113 def __init__(self, mesh, geom=0):
3114 import Python1dPlugin
3115 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
3117 ## Defines "PythonSplit1D" hypothesis
3118 # @param n for the number of segments that cut an edge
3119 # @param func for the python function that calculates the length of all segments
3120 # @param UseExisting if ==true - searches for the existing hypothesis created with
3121 # the same parameters, else (default) - creates a new one
3122 # @ingroup l3_hypos_1dhyps
3123 def PythonSplit1D(self, n, func, UseExisting=0):
3124 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
3125 UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
3126 hyp.SetNumberOfSegments(n)
3127 hyp.SetPythonLog10RatioFunction(func)
3130 ## Checks if the given "PythonSplit1D" hypothesis has the same parameters as the given arguments
3131 def ComparePythonSplit1D(self, hyp, args):
3132 #if hyp.GetNumberOfSegments() == args[0]:
3133 # if hyp.GetPythonLog10RatioFunction() == args[1]:
3137 # Public class: Mesh_Triangle
3138 # ---------------------------
3140 ## Defines a triangle 2D algorithm
3142 # @ingroup l3_algos_basic
3143 class Mesh_Triangle(Mesh_Algorithm):
3152 ## Private constructor.
3153 def __init__(self, mesh, algoType, geom=0):
3154 Mesh_Algorithm.__init__(self)
3156 self.algoType = algoType
3157 if algoType == MEFISTO:
3158 self.Create(mesh, geom, "MEFISTO_2D")
3160 elif algoType == BLSURF:
3162 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
3163 #self.SetPhysicalMesh() - PAL19680
3164 elif algoType == NETGEN:
3166 print "Warning: NETGENPlugin module unavailable"
3168 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3170 elif algoType == NETGEN_2D:
3172 print "Warning: NETGENPlugin module unavailable"
3174 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
3177 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
3178 # @param area for the maximum area of each triangle
3179 # @param UseExisting if ==true - searches for an existing hypothesis created with the
3180 # same parameters, else (default) - creates a new one
3182 # Only for algoType == MEFISTO || NETGEN_2D
3183 # @ingroup l3_hypos_2dhyps
3184 def MaxElementArea(self, area, UseExisting=0):
3185 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
3186 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
3187 CompareMethod=self.CompareMaxElementArea)
3188 hyp.SetMaxElementArea(area)
3190 elif self.algoType == NETGEN:
3191 print "Netgen 1D-2D algo doesn't support this hypothesis"
3194 ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
3195 def CompareMaxElementArea(self, hyp, args):
3196 return IsEqual(hyp.GetMaxElementArea(), args[0])
3198 ## Defines "LengthFromEdges" hypothesis to build triangles
3199 # based on the length of the edges taken from the wire
3201 # Only for algoType == MEFISTO || NETGEN_2D
3202 # @ingroup l3_hypos_2dhyps
3203 def LengthFromEdges(self):
3204 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
3205 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3207 elif self.algoType == NETGEN:
3208 print "Netgen 1D-2D algo doesn't support this hypothesis"
3211 ## Sets a way to define size of mesh elements to generate.
3212 # @param thePhysicalMesh is: DefaultSize or Custom.
3213 # @ingroup l3_hypos_blsurf
3214 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
3215 # Parameter of BLSURF algo
3216 self.Parameters().SetPhysicalMesh(thePhysicalMesh)
3218 ## Sets size of mesh elements to generate.
3219 # @ingroup l3_hypos_blsurf
3220 def SetPhySize(self, theVal):
3221 # Parameter of BLSURF algo
3222 self.Parameters().SetPhySize(theVal)
3224 ## Sets lower boundary of mesh element size (PhySize).
3225 # @ingroup l3_hypos_blsurf
3226 def SetPhyMin(self, theVal=-1):
3227 # Parameter of BLSURF algo
3228 self.Parameters().SetPhyMin(theVal)
3230 ## Sets upper boundary of mesh element size (PhySize).
3231 # @ingroup l3_hypos_blsurf
3232 def SetPhyMax(self, theVal=-1):
3233 # Parameter of BLSURF algo
3234 self.Parameters().SetPhyMax(theVal)
3236 ## Sets a way to define maximum angular deflection of mesh from CAD model.
3237 # @param theGeometricMesh is: DefaultGeom or Custom
3238 # @ingroup l3_hypos_blsurf
3239 def SetGeometricMesh(self, theGeometricMesh=0):
3240 # Parameter of BLSURF algo
3241 if self.Parameters().GetPhysicalMesh() == 0: theGeometricMesh = 1
3242 self.params.SetGeometricMesh(theGeometricMesh)
3244 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
3245 # @ingroup l3_hypos_blsurf
3246 def SetAngleMeshS(self, theVal=_angleMeshS):
3247 # Parameter of BLSURF algo
3248 if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
3249 self.params.SetAngleMeshS(theVal)
3251 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
3252 # @ingroup l3_hypos_blsurf
3253 def SetAngleMeshC(self, theVal=_angleMeshS):
3254 # Parameter of BLSURF algo
3255 if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
3256 self.params.SetAngleMeshC(theVal)
3258 ## Sets lower boundary of mesh element size computed to respect angular deflection.
3259 # @ingroup l3_hypos_blsurf
3260 def SetGeoMin(self, theVal=-1):
3261 # Parameter of BLSURF algo
3262 self.Parameters().SetGeoMin(theVal)
3264 ## Sets upper boundary of mesh element size computed to respect angular deflection.
3265 # @ingroup l3_hypos_blsurf
3266 def SetGeoMax(self, theVal=-1):
3267 # Parameter of BLSURF algo
3268 self.Parameters().SetGeoMax(theVal)
3270 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
3271 # @ingroup l3_hypos_blsurf
3272 def SetGradation(self, theVal=_gradation):
3273 # Parameter of BLSURF algo
3274 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
3275 self.params.SetGradation(theVal)
3277 ## Sets topology usage way.
3278 # @param way defines how mesh conformity is assured <ul>
3279 # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
3280 # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model</li></ul>
3281 # @ingroup l3_hypos_blsurf
3282 def SetTopology(self, way):
3283 # Parameter of BLSURF algo
3284 self.Parameters().SetTopology(way)
3286 ## To respect geometrical edges or not.
3287 # @ingroup l3_hypos_blsurf
3288 def SetDecimesh(self, toIgnoreEdges=False):
3289 # Parameter of BLSURF algo
3290 self.Parameters().SetDecimesh(toIgnoreEdges)
3292 ## Sets verbosity level in the range 0 to 100.
3293 # @ingroup l3_hypos_blsurf
3294 def SetVerbosity(self, level):
3295 # Parameter of BLSURF algo
3296 self.Parameters().SetVerbosity(level)
3298 ## Sets advanced option value.
3299 # @ingroup l3_hypos_blsurf
3300 def SetOptionValue(self, optionName, level):
3301 # Parameter of BLSURF algo
3302 self.Parameters().SetOptionValue(optionName,level)
3304 ## Sets QuadAllowed flag.
3305 # Only for algoType == NETGEN || NETGEN_2D || BLSURF
3306 # @ingroup l3_hypos_netgen l3_hypos_blsurf
3307 def SetQuadAllowed(self, toAllow=True):
3308 if self.algoType == NETGEN_2D:
3309 if toAllow: # add QuadranglePreference
3310 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
3311 else: # remove QuadranglePreference
3312 for hyp in self.mesh.GetHypothesisList( self.geom ):
3313 if hyp.GetName() == "QuadranglePreference":
3314 self.mesh.RemoveHypothesis( self.geom, hyp )
3319 if self.Parameters():
3320 self.params.SetQuadAllowed(toAllow)
3323 ## Defines "Netgen 2D Parameters" hypothesis
3325 # @ingroup l3_hypos_netgen
3326 def Parameters(self):
3327 # Only for algoType == NETGEN
3330 if self.algoType == NETGEN:
3331 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
3332 "libNETGENEngine.so", UseExisting=0)
3334 elif self.algoType == MEFISTO:
3335 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
3337 elif self.algoType == NETGEN_2D:
3338 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
3339 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
3341 elif self.algoType == BLSURF:
3342 self.params = self.Hypothesis("BLSURF_Parameters", [],
3343 "libBLSURFEngine.so", UseExisting=0)
3349 # Only for algoType == NETGEN
3350 # @ingroup l3_hypos_netgen
3351 def SetMaxSize(self, theSize):
3352 if self.Parameters():
3353 self.params.SetMaxSize(theSize)
3355 ## Sets SecondOrder flag
3357 # Only for algoType == NETGEN
3358 # @ingroup l3_hypos_netgen
3359 def SetSecondOrder(self, theVal):
3360 if self.Parameters():
3361 self.params.SetSecondOrder(theVal)
3363 ## Sets Optimize flag
3365 # Only for algoType == NETGEN
3366 # @ingroup l3_hypos_netgen
3367 def SetOptimize(self, theVal):
3368 if self.Parameters():
3369 self.params.SetOptimize(theVal)
3372 # @param theFineness is:
3373 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3375 # Only for algoType == NETGEN
3376 # @ingroup l3_hypos_netgen
3377 def SetFineness(self, theFineness):
3378 if self.Parameters():
3379 self.params.SetFineness(theFineness)
3383 # Only for algoType == NETGEN
3384 # @ingroup l3_hypos_netgen
3385 def SetGrowthRate(self, theRate):
3386 if self.Parameters():
3387 self.params.SetGrowthRate(theRate)
3389 ## Sets NbSegPerEdge
3391 # Only for algoType == NETGEN
3392 # @ingroup l3_hypos_netgen
3393 def SetNbSegPerEdge(self, theVal):
3394 if self.Parameters():
3395 self.params.SetNbSegPerEdge(theVal)
3397 ## Sets NbSegPerRadius
3399 # Only for algoType == NETGEN
3400 # @ingroup l3_hypos_netgen
3401 def SetNbSegPerRadius(self, theVal):
3402 if self.Parameters():
3403 self.params.SetNbSegPerRadius(theVal)
3408 # Public class: Mesh_Quadrangle
3409 # -----------------------------
3411 ## Defines a quadrangle 2D algorithm
3413 # @ingroup l3_algos_basic
3414 class Mesh_Quadrangle(Mesh_Algorithm):
3416 ## Private constructor.
3417 def __init__(self, mesh, geom=0):
3418 Mesh_Algorithm.__init__(self)
3419 self.Create(mesh, geom, "Quadrangle_2D")
3421 ## Defines "QuadranglePreference" hypothesis, forcing construction
3422 # of quadrangles if the number of nodes on the opposite edges is not the same
3423 # while the total number of nodes on edges is even
3425 # @ingroup l3_hypos_additi
3426 def QuadranglePreference(self):
3427 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
3428 CompareMethod=self.CompareEqualHyp)
3431 # Public class: Mesh_Tetrahedron
3432 # ------------------------------
3434 ## Defines a tetrahedron 3D algorithm
3436 # @ingroup l3_algos_basic
3437 class Mesh_Tetrahedron(Mesh_Algorithm):
3442 ## Private constructor.
3443 def __init__(self, mesh, algoType, geom=0):
3444 Mesh_Algorithm.__init__(self)
3446 if algoType == NETGEN:
3447 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
3450 elif algoType == FULL_NETGEN:
3452 print "Warning: NETGENPlugin module has not been imported."
3453 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3456 elif algoType == GHS3D:
3458 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
3461 self.algoType = algoType
3463 ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
3464 # @param vol for the maximum volume of each tetrahedron
3465 # @param UseExisting if ==true - searches for the existing hypothesis created with
3466 # the same parameters, else (default) - creates a new one
3467 # @ingroup l3_hypos_maxvol
3468 def MaxElementVolume(self, vol, UseExisting=0):
3469 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
3470 CompareMethod=self.CompareMaxElementVolume)
3471 hyp.SetMaxElementVolume(vol)
3474 ## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
3475 def CompareMaxElementVolume(self, hyp, args):
3476 return IsEqual(hyp.GetMaxElementVolume(), args[0])
3478 ## Defines "Netgen 3D Parameters" hypothesis
3479 # @ingroup l3_hypos_netgen
3480 def Parameters(self):
3483 if (self.algoType == FULL_NETGEN):
3484 self.params = self.Hypothesis("NETGEN_Parameters", [],
3485 "libNETGENEngine.so", UseExisting=0)
3487 if (self.algoType == GHS3D):
3488 self.params = self.Hypothesis("GHS3D_Parameters", [],
3489 "libGHS3DEngine.so", UseExisting=0)
3492 print "Algo doesn't support this hypothesis"
3496 # Parameter of FULL_NETGEN
3497 # @ingroup l3_hypos_netgen
3498 def SetMaxSize(self, theSize):
3499 self.Parameters().SetMaxSize(theSize)
3501 ## Sets SecondOrder flag
3502 # Parameter of FULL_NETGEN
3503 # @ingroup l3_hypos_netgen
3504 def SetSecondOrder(self, theVal):
3505 self.Parameters().SetSecondOrder(theVal)
3507 ## Sets Optimize flag
3508 # Parameter of FULL_NETGEN
3509 # @ingroup l3_hypos_netgen
3510 def SetOptimize(self, theVal):
3511 self.Parameters().SetOptimize(theVal)
3514 # @param theFineness is:
3515 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3516 # Parameter of FULL_NETGEN
3517 # @ingroup l3_hypos_netgen
3518 def SetFineness(self, theFineness):
3519 self.Parameters().SetFineness(theFineness)
3522 # Parameter of FULL_NETGEN
3523 # @ingroup l3_hypos_netgen
3524 def SetGrowthRate(self, theRate):
3525 self.Parameters().SetGrowthRate(theRate)
3527 ## Sets NbSegPerEdge
3528 # Parameter of FULL_NETGEN
3529 # @ingroup l3_hypos_netgen
3530 def SetNbSegPerEdge(self, theVal):
3531 self.Parameters().SetNbSegPerEdge(theVal)
3533 ## Sets NbSegPerRadius
3534 # Parameter of FULL_NETGEN
3535 # @ingroup l3_hypos_netgen
3536 def SetNbSegPerRadius(self, theVal):
3537 self.Parameters().SetNbSegPerRadius(theVal)
3539 ## To mesh "holes" in a solid or not. Default is to mesh.
3540 # @ingroup l3_hypos_ghs3dh
3541 def SetToMeshHoles(self, toMesh):
3542 # Parameter of GHS3D
3543 self.Parameters().SetToMeshHoles(toMesh)
3545 ## Set Optimization level:
3546 # None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization.
3547 # Default is Medium_Optimization
3548 # @ingroup l3_hypos_ghs3dh
3549 def SetOptimizationLevel(self, level):
3550 # Parameter of GHS3D
3551 self.Parameters().SetOptimizationLevel(level)
3553 ## Maximal size of memory to be used by the algorithm (in Megabytes).
3554 # @ingroup l3_hypos_ghs3dh
3555 def SetMaximumMemory(self, MB):
3556 # Advanced parameter of GHS3D
3557 self.Parameters().SetMaximumMemory(MB)
3559 ## Initial size of memory to be used by the algorithm (in Megabytes) in
3560 # automatic memory adjustment mode.
3561 # @ingroup l3_hypos_ghs3dh
3562 def SetInitialMemory(self, MB):
3563 # Advanced parameter of GHS3D
3564 self.Parameters().SetInitialMemory(MB)
3566 ## Path to working directory.
3567 # @ingroup l3_hypos_ghs3dh
3568 def SetWorkingDirectory(self, path):
3569 # Advanced parameter of GHS3D
3570 self.Parameters().SetWorkingDirectory(path)
3572 ## To keep working files or remove them. Log file remains in case of errors anyway.
3573 # @ingroup l3_hypos_ghs3dh
3574 def SetKeepFiles(self, toKeep):
3575 # Advanced parameter of GHS3D
3576 self.Parameters().SetKeepFiles(toKeep)
3578 ## To set verbose level [0-10]. <ul>
3579 #<li> 0 - no standard output,
3580 #<li> 2 - prints the data, quality statistics of the skin and final meshes and
3581 # indicates when the final mesh is being saved. In addition the software
3582 # gives indication regarding the CPU time.
3583 #<li>10 - same as 2 plus the main steps in the computation, quality statistics
3584 # histogram of the skin mesh, quality statistics histogram together with
3585 # the characteristics of the final mesh.</ul>
3586 # @ingroup l3_hypos_ghs3dh
3587 def SetVerboseLevel(self, level):
3588 # Advanced parameter of GHS3D
3589 self.Parameters().SetVerboseLevel(level)
3591 ## To create new nodes.
3592 # @ingroup l3_hypos_ghs3dh
3593 def SetToCreateNewNodes(self, toCreate):
3594 # Advanced parameter of GHS3D
3595 self.Parameters().SetToCreateNewNodes(toCreate)
3597 ## To use boundary recovery version which tries to create mesh on a very poor
3598 # quality surface mesh.
3599 # @ingroup l3_hypos_ghs3dh
3600 def SetToUseBoundaryRecoveryVersion(self, toUse):
3601 # Advanced parameter of GHS3D
3602 self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
3604 ## Sets command line option as text.
3605 # @ingroup l3_hypos_ghs3dh
3606 def SetTextOption(self, option):
3607 # Advanced parameter of GHS3D
3608 self.Parameters().SetTextOption(option)
3610 # Public class: Mesh_Hexahedron
3611 # ------------------------------
3613 ## Defines a hexahedron 3D algorithm
3615 # @ingroup l3_algos_basic
3616 class Mesh_Hexahedron(Mesh_Algorithm):
3621 ## Private constructor.
3622 def __init__(self, mesh, algoType=Hexa, geom=0):
3623 Mesh_Algorithm.__init__(self)
3625 self.algoType = algoType
3627 if algoType == Hexa:
3628 self.Create(mesh, geom, "Hexa_3D")
3631 elif algoType == Hexotic:
3632 import HexoticPlugin
3633 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
3636 ## Defines "MinMaxQuad" hypothesis to give three hexotic parameters
3637 # @ingroup l3_hypos_hexotic
3638 def MinMaxQuad(self, min=3, max=8, quad=True):
3639 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
3641 self.params.SetHexesMinLevel(min)
3642 self.params.SetHexesMaxLevel(max)
3643 self.params.SetHexoticQuadrangles(quad)
3646 # Deprecated, only for compatibility!
3647 # Public class: Mesh_Netgen
3648 # ------------------------------
3650 ## Defines a NETGEN-based 2D or 3D algorithm
3651 # that needs no discrete boundary (i.e. independent)
3653 # This class is deprecated, only for compatibility!
3656 # @ingroup l3_algos_basic
3657 class Mesh_Netgen(Mesh_Algorithm):
3661 ## Private constructor.
3662 def __init__(self, mesh, is3D, geom=0):
3663 Mesh_Algorithm.__init__(self)
3666 print "Warning: NETGENPlugin module has not been imported."
3670 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3674 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3677 ## Defines the hypothesis containing parameters of the algorithm
3678 def Parameters(self):
3680 hyp = self.Hypothesis("NETGEN_Parameters", [],
3681 "libNETGENEngine.so", UseExisting=0)
3683 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
3684 "libNETGENEngine.so", UseExisting=0)
3687 # Public class: Mesh_Projection1D
3688 # ------------------------------
3690 ## Defines a projection 1D algorithm
3691 # @ingroup l3_algos_proj
3693 class Mesh_Projection1D(Mesh_Algorithm):
3695 ## Private constructor.
3696 def __init__(self, mesh, geom=0):
3697 Mesh_Algorithm.__init__(self)
3698 self.Create(mesh, geom, "Projection_1D")
3700 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
3701 # a mesh pattern is taken, and, optionally, the association of vertices
3702 # between the source edge and a target edge (to which a hypothesis is assigned)
3703 # @param edge from which nodes distribution is taken
3704 # @param mesh from which nodes distribution is taken (optional)
3705 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
3706 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
3707 # to associate with \a srcV (optional)
3708 # @param UseExisting if ==true - searches for the existing hypothesis created with
3709 # the same parameters, else (default) - creates a new one
3710 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
3711 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
3713 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
3714 hyp.SetSourceEdge( edge )
3715 if not mesh is None and isinstance(mesh, Mesh):
3716 mesh = mesh.GetMesh()
3717 hyp.SetSourceMesh( mesh )
3718 hyp.SetVertexAssociation( srcV, tgtV )
3721 ## Checks if the given "SourceEdge" hypothesis has the same parameters as the given arguments
3722 #def CompareSourceEdge(self, hyp, args):
3723 # # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
3727 # Public class: Mesh_Projection2D
3728 # ------------------------------
3730 ## Defines a projection 2D algorithm
3731 # @ingroup l3_algos_proj
3733 class Mesh_Projection2D(Mesh_Algorithm):
3735 ## Private constructor.
3736 def __init__(self, mesh, geom=0):
3737 Mesh_Algorithm.__init__(self)
3738 self.Create(mesh, geom, "Projection_2D")
3740 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
3741 # a mesh pattern is taken, and, optionally, the association of vertices
3742 # between the source face and the target face (to which a hypothesis is assigned)
3743 # @param face from which the mesh pattern is taken
3744 # @param mesh from which the mesh pattern is taken (optional)
3745 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
3746 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
3747 # to associate with \a srcV1 (optional)
3748 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
3749 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
3750 # to associate with \a srcV2 (optional)
3751 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
3752 # the same parameters, else (default) - forces the creation a new one
3754 # Note: all association vertices must belong to one edge of a face
3755 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
3756 srcV2=None, tgtV2=None, UseExisting=0):
3757 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
3759 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
3760 hyp.SetSourceFace( face )
3761 if not mesh is None and isinstance(mesh, Mesh):
3762 mesh = mesh.GetMesh()
3763 hyp.SetSourceMesh( mesh )
3764 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3767 ## Checks if the given "SourceFace" hypothesis has the same parameters as the given arguments
3768 #def CompareSourceFace(self, hyp, args):
3769 # # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
3772 # Public class: Mesh_Projection3D
3773 # ------------------------------
3775 ## Defines a projection 3D algorithm
3776 # @ingroup l3_algos_proj
3778 class Mesh_Projection3D(Mesh_Algorithm):
3780 ## Private constructor.
3781 def __init__(self, mesh, geom=0):
3782 Mesh_Algorithm.__init__(self)
3783 self.Create(mesh, geom, "Projection_3D")
3785 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
3786 # the mesh pattern is taken, and, optionally, the association of vertices
3787 # between the source and the target solid (to which a hipothesis is assigned)
3788 # @param solid from where the mesh pattern is taken
3789 # @param mesh from where the mesh pattern is taken (optional)
3790 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
3791 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
3792 # to associate with \a srcV1 (optional)
3793 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
3794 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
3795 # to associate with \a srcV2 (optional)
3796 # @param UseExisting - if ==true - searches for the existing hypothesis created with
3797 # the same parameters, else (default) - creates a new one
3799 # Note: association vertices must belong to one edge of a solid
3800 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
3801 srcV2=0, tgtV2=0, UseExisting=0):
3802 hyp = self.Hypothesis("ProjectionSource3D",
3803 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
3805 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
3806 hyp.SetSource3DShape( solid )
3807 if not mesh is None and isinstance(mesh, Mesh):
3808 mesh = mesh.GetMesh()
3809 hyp.SetSourceMesh( mesh )
3810 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3813 ## Checks if the given "SourceShape3D" hypothesis has the same parameters as given arguments
3814 #def CompareSourceShape3D(self, hyp, args):
3815 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
3819 # Public class: Mesh_Prism
3820 # ------------------------
3822 ## Defines a 3D extrusion algorithm
3823 # @ingroup l3_algos_3dextr
3825 class Mesh_Prism3D(Mesh_Algorithm):
3827 ## Private constructor.
3828 def __init__(self, mesh, geom=0):
3829 Mesh_Algorithm.__init__(self)
3830 self.Create(mesh, geom, "Prism_3D")
3832 # Public class: Mesh_RadialPrism
3833 # -------------------------------
3835 ## Defines a Radial Prism 3D algorithm
3836 # @ingroup l3_algos_radialp
3838 class Mesh_RadialPrism3D(Mesh_Algorithm):
3840 ## Private constructor.
3841 def __init__(self, mesh, geom=0):
3842 Mesh_Algorithm.__init__(self)
3843 self.Create(mesh, geom, "RadialPrism_3D")
3845 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
3846 self.nbLayers = None
3848 ## Return 3D hypothesis holding the 1D one
3849 def Get3DHypothesis(self):
3850 return self.distribHyp
3852 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
3853 # hypothesis. Returns the created hypothesis
3854 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
3855 #print "OwnHypothesis",hypType
3856 if not self.nbLayers is None:
3857 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
3858 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
3859 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
3860 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
3861 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
3862 self.distribHyp.SetLayerDistribution( hyp )
3865 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
3866 # prisms to build between the inner and outer shells
3867 # @param n number of layers
3868 # @param UseExisting if ==true - searches for the existing hypothesis created with
3869 # the same parameters, else (default) - creates a new one
3870 def NumberOfLayers(self, n, UseExisting=0):
3871 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
3872 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
3873 CompareMethod=self.CompareNumberOfLayers)
3874 self.nbLayers.SetNumberOfLayers( n )
3875 return self.nbLayers
3877 ## Checks if the given "NumberOfLayers" hypothesis has the same parameters as the given arguments
3878 def CompareNumberOfLayers(self, hyp, args):
3879 return IsEqual(hyp.GetNumberOfLayers(), args[0])
3881 ## Defines "LocalLength" hypothesis, specifying the segment length
3882 # to build between the inner and the outer shells
3883 # @param l the length of segments
3884 # @param p the precision of rounding
3885 def LocalLength(self, l, p=1e-07):
3886 hyp = self.OwnHypothesis("LocalLength", [l,p])
3891 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
3892 # prisms to build between the inner and the outer shells.
3893 # @param n the number of layers
3894 # @param s the scale factor (optional)
3895 def NumberOfSegments(self, n, s=[]):
3897 hyp = self.OwnHypothesis("NumberOfSegments", [n])
3899 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
3900 hyp.SetDistrType( 1 )
3901 hyp.SetScaleFactor(s)
3902 hyp.SetNumberOfSegments(n)
3905 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
3906 # to build between the inner and the outer shells with a length that changes in arithmetic progression
3907 # @param start the length of the first segment
3908 # @param end the length of the last segment
3909 def Arithmetic1D(self, start, end ):
3910 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
3911 hyp.SetLength(start, 1)
3912 hyp.SetLength(end , 0)
3915 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
3916 # to build between the inner and the outer shells as geometric length increasing
3917 # @param start for the length of the first segment
3918 # @param end for the length of the last segment
3919 def StartEndLength(self, start, end):
3920 hyp = self.OwnHypothesis("StartEndLength", [start, end])
3921 hyp.SetLength(start, 1)
3922 hyp.SetLength(end , 0)
3925 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
3926 # to build between the inner and outer shells
3927 # @param fineness defines the quality of the mesh within the range [0-1]
3928 def AutomaticLength(self, fineness=0):
3929 hyp = self.OwnHypothesis("AutomaticLength")
3930 hyp.SetFineness( fineness )
3933 # Private class: Mesh_UseExisting
3934 # -------------------------------
3935 class Mesh_UseExisting(Mesh_Algorithm):
3937 def __init__(self, dim, mesh, geom=0):
3939 self.Create(mesh, geom, "UseExisting_1D")
3941 self.Create(mesh, geom, "UseExisting_2D")