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
30 # To get started, please, have a look at smeshDC::smeshDC documentation
31 # for general services of smesh package
32 # You can also find the smeshDC::smeshDC documentation by the first
33 # item in the Data Structures list on this page.
34 # See also the list of Data Structures and the list of Functions
35 # for other classes and methods of smesh python interface.
41 import SMESH # This is necessary for back compatibility
48 # import NETGENPlugin module if possible
67 NETGEN_1D2D3D = FULL_NETGEN
68 NETGEN_FULL = FULL_NETGEN
73 # MirrorType enumeration
74 POINT = SMESH_MeshEditor.POINT
75 AXIS = SMESH_MeshEditor.AXIS
76 PLANE = SMESH_MeshEditor.PLANE
78 # Smooth_Method enumeration
79 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
80 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
82 # Fineness enumeration (for NETGEN)
90 PrecisionConfusion = 1e-07
92 def IsEqual(val1, val2, tol=PrecisionConfusion):
93 if abs(val1 - val2) < tol:
101 ior = salome.orb.object_to_string(obj)
102 sobj = salome.myStudy.FindObjectIOR(ior)
106 attr = sobj.FindAttribute("AttributeName")[1]
109 ## Sets a name to the object
110 def SetName(obj, name):
111 ior = salome.orb.object_to_string(obj)
112 sobj = salome.myStudy.FindObjectIOR(ior)
114 attr = sobj.FindAttribute("AttributeName")[1]
117 ## Prints error message if a hypothesis was not assigned.
118 def TreatHypoStatus(status, hypName, geomName, isAlgo):
120 hypType = "algorithm"
122 hypType = "hypothesis"
124 if status == HYP_UNKNOWN_FATAL :
125 reason = "for unknown reason"
126 elif status == HYP_INCOMPATIBLE :
127 reason = "this hypothesis mismatches the algorithm"
128 elif status == HYP_NOTCONFORM :
129 reason = "a non-conform mesh would be built"
130 elif status == HYP_ALREADY_EXIST :
131 reason = hypType + " of the same dimension is already assigned to this shape"
132 elif status == HYP_BAD_DIM :
133 reason = hypType + " mismatches the shape"
134 elif status == HYP_CONCURENT :
135 reason = "there are concurrent hypotheses on sub-shapes"
136 elif status == HYP_BAD_SUBSHAPE :
137 reason = "the shape is neither the main one, nor its subshape, nor a valid group"
138 elif status == HYP_BAD_GEOMETRY:
139 reason = "geometry mismatches the expectation of the algorithm"
140 elif status == HYP_HIDDEN_ALGO:
141 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
142 elif status == HYP_HIDING_ALGO:
143 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
146 hypName = '"' + hypName + '"'
147 geomName= '"' + geomName+ '"'
148 if status < HYP_UNKNOWN_FATAL:
149 print hypName, "was assigned to", geomName,"but", reason
151 print hypName, "was not assigned to",geomName,":", reason
154 ## Converts an angle from degrees to radians
155 def DegreesToRadians(AngleInDegrees):
157 return AngleInDegrees * pi / 180.0
159 ## Methods of the package smesh.py provide general services of MESH component.
161 # All methods of this class are accessible directly from the smesh.py package.
162 # Use these methods to create an empty mesh, to import the mesh from file,
163 # and to create patterns and filtering criteria.
164 class smeshDC(SMESH._objref_SMESH_Gen):
166 ## Sets the current study and Geometry component
167 def init_smesh(self,theStudy,geompyD):
169 self.SetGeomEngine(geompyD)
170 self.SetCurrentStudy(theStudy)
172 ## Creates an empty Mesh. This mesh can have an underlying geometry.
173 # @param obj the Geometrical object on which the mesh is built. If not defined,
174 # the mesh will have no underlying geometry.
175 # @param name the name for the new mesh.
176 # @return an instance of Mesh class.
177 def Mesh(self, obj=0, name=0):
178 return Mesh(self,self.geompyD,obj,name)
180 ## Returns a long value from enumeration
181 # Should be used for SMESH.FunctorType enumeration
182 def EnumToLong(self,theItem):
185 ## Gets PointStruct from vertex
186 # @param theVertex a GEOM object(vertex)
187 # @return SMESH.PointStruct
188 def GetPointStruct(self,theVertex):
189 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
190 return PointStruct(x,y,z)
192 ## Gets DirStruct from vector
193 # @param theVector a GEOM object(vector)
194 # @return SMESH.DirStruct
195 def GetDirStruct(self,theVector):
196 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
197 if(len(vertices) != 2):
198 print "Error: vector object is incorrect."
200 p1 = self.geompyD.PointCoordinates(vertices[0])
201 p2 = self.geompyD.PointCoordinates(vertices[1])
202 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
203 dirst = DirStruct(pnt)
206 ## Makes DirStruct from a triplet
207 # @param x,y,z vector components
208 # @return SMESH.DirStruct
209 def MakeDirStruct(self,x,y,z):
210 pnt = PointStruct(x,y,z)
211 return DirStruct(pnt)
213 ## Get AxisStruct from object
214 # @param theObj a GEOM object (line or plane)
215 # @return SMESH.AxisStruct
216 def GetAxisStruct(self,theObj):
217 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
219 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
220 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
221 vertex1 = self.geompyD.PointCoordinates(vertex1)
222 vertex2 = self.geompyD.PointCoordinates(vertex2)
223 vertex3 = self.geompyD.PointCoordinates(vertex3)
224 vertex4 = self.geompyD.PointCoordinates(vertex4)
225 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
226 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
227 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] ]
228 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
230 elif len(edges) == 1:
231 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
232 p1 = self.geompyD.PointCoordinates( vertex1 )
233 p2 = self.geompyD.PointCoordinates( vertex2 )
234 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
238 # From SMESH_Gen interface:
239 # ------------------------
241 ## Sets the current mode
242 def SetEmbeddedMode( self,theMode ):
243 #self.SetEmbeddedMode(theMode)
244 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
246 ## Gets the current mode
247 def IsEmbeddedMode(self):
248 #return self.IsEmbeddedMode()
249 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
251 ## Sets the current study
252 def SetCurrentStudy( self, theStudy ):
253 #self.SetCurrentStudy(theStudy)
254 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
256 ## Gets the current study
257 def GetCurrentStudy(self):
258 #return self.GetCurrentStudy()
259 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
261 ## Creates a Mesh object importing data from the given UNV file
262 # @return an instance of Mesh class
263 def CreateMeshesFromUNV( self,theFileName ):
264 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
265 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
268 ## Creates a Mesh object(s) importing data from the given MED file
269 # @return a list of Mesh class instances
270 def CreateMeshesFromMED( self,theFileName ):
271 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
273 for iMesh in range(len(aSmeshMeshes)) :
274 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
275 aMeshes.append(aMesh)
276 return aMeshes, aStatus
278 ## Creates a Mesh object importing data from the given STL file
279 # @return an instance of Mesh class
280 def CreateMeshesFromSTL( self, theFileName ):
281 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
282 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
285 ## From SMESH_Gen interface
286 # @return the list of integer values
287 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
288 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
290 ## From SMESH_Gen interface. Creates a pattern
291 # @return an instance of SMESH_Pattern
292 def GetPattern(self):
293 return SMESH._objref_SMESH_Gen.GetPattern(self)
296 # Filtering. Auxiliary functions:
297 # ------------------------------
299 ## Creates an empty criterion
300 # @return SMESH.Filter.Criterion
301 def GetEmptyCriterion(self):
302 Type = self.EnumToLong(FT_Undefined)
303 Compare = self.EnumToLong(FT_Undefined)
307 UnaryOp = self.EnumToLong(FT_Undefined)
308 BinaryOp = self.EnumToLong(FT_Undefined)
311 Precision = -1 ##@1e-07
312 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
313 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
315 ## Creates a criterion by the given parameters
316 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
317 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
318 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
319 # @param Treshold the threshold value (range of ids as string, shape, numeric)
320 # @param UnaryOp FT_LogicalNOT or FT_Undefined
321 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
322 # FT_Undefined (must be for the last criterion of all criteria)
323 # @return SMESH.Filter.Criterion
324 def GetCriterion(self,elementType,
326 Compare = FT_EqualTo,
328 UnaryOp=FT_Undefined,
329 BinaryOp=FT_Undefined):
330 aCriterion = self.GetEmptyCriterion()
331 aCriterion.TypeOfElement = elementType
332 aCriterion.Type = self.EnumToLong(CritType)
336 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
337 aCriterion.Compare = self.EnumToLong(Compare)
338 elif Compare == "=" or Compare == "==":
339 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
341 aCriterion.Compare = self.EnumToLong(FT_LessThan)
343 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
345 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
348 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
349 FT_BelongToCylinder, FT_LyingOnGeom]:
350 # Checks the treshold
351 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
352 aCriterion.ThresholdStr = GetName(aTreshold)
353 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
355 print "Error: The treshold should be a shape."
357 elif CritType == FT_RangeOfIds:
358 # Checks the treshold
359 if isinstance(aTreshold, str):
360 aCriterion.ThresholdStr = aTreshold
362 print "Error: The treshold should be a string."
364 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
365 # At this point the treshold is unnecessary
366 if aTreshold == FT_LogicalNOT:
367 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
368 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
369 aCriterion.BinaryOp = aTreshold
373 aTreshold = float(aTreshold)
374 aCriterion.Threshold = aTreshold
376 print "Error: The treshold should be a number."
379 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
380 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
382 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
383 aCriterion.BinaryOp = self.EnumToLong(Treshold)
385 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
386 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
388 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
389 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
393 ## Creates a filter with the given parameters
394 # @param elementType the type of elements in the group
395 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
396 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
397 # @param Treshold the threshold value (range of id ids as string, shape, numeric)
398 # @param UnaryOp FT_LogicalNOT or FT_Undefined
399 # @return SMESH_Filter
400 def GetFilter(self,elementType,
401 CritType=FT_Undefined,
404 UnaryOp=FT_Undefined):
405 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
406 aFilterMgr = self.CreateFilterManager()
407 aFilter = aFilterMgr.CreateFilter()
409 aCriteria.append(aCriterion)
410 aFilter.SetCriteria(aCriteria)
413 ## Creates a numerical functor by its type
414 # @param theCriterion FT_...; functor type
415 # @return SMESH_NumericalFunctor
416 def GetFunctor(self,theCriterion):
417 aFilterMgr = self.CreateFilterManager()
418 if theCriterion == FT_AspectRatio:
419 return aFilterMgr.CreateAspectRatio()
420 elif theCriterion == FT_AspectRatio3D:
421 return aFilterMgr.CreateAspectRatio3D()
422 elif theCriterion == FT_Warping:
423 return aFilterMgr.CreateWarping()
424 elif theCriterion == FT_MinimumAngle:
425 return aFilterMgr.CreateMinimumAngle()
426 elif theCriterion == FT_Taper:
427 return aFilterMgr.CreateTaper()
428 elif theCriterion == FT_Skew:
429 return aFilterMgr.CreateSkew()
430 elif theCriterion == FT_Area:
431 return aFilterMgr.CreateArea()
432 elif theCriterion == FT_Volume3D:
433 return aFilterMgr.CreateVolume3D()
434 elif theCriterion == FT_MultiConnection:
435 return aFilterMgr.CreateMultiConnection()
436 elif theCriterion == FT_MultiConnection2D:
437 return aFilterMgr.CreateMultiConnection2D()
438 elif theCriterion == FT_Length:
439 return aFilterMgr.CreateLength()
440 elif theCriterion == FT_Length2D:
441 return aFilterMgr.CreateLength2D()
443 print "Error: given parameter is not numerucal functor type."
446 #Registering the new proxy for SMESH_Gen
447 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
453 ## This class allows defining and managing a mesh.
454 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
455 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
456 # new nodes and elements and by changing the existing entities), to get information
457 # about a mesh and to export a mesh into different formats.
466 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
467 # sets the GUI name of this mesh to \a name.
468 # @param obj Shape to be meshed or SMESH_Mesh object
469 # @param name Study name of the mesh
470 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
471 self.smeshpyD=smeshpyD
476 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
478 self.mesh = self.smeshpyD.CreateMesh(self.geom)
479 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
482 self.mesh = self.smeshpyD.CreateEmptyMesh()
484 SetName(self.mesh, name)
486 SetName(self.mesh, GetName(obj))
488 self.editor = self.mesh.GetMeshEditor()
490 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
491 # @param theMesh a SMESH_Mesh object
492 def SetMesh(self, theMesh):
494 self.geom = self.mesh.GetShapeToMesh()
496 ## Returns the mesh, that is an instance of SMESH_Mesh interface
497 # @return a SMESH_Mesh object
501 ## Gets the name of the mesh
502 # @return the name of the mesh as a string
504 name = GetName(self.GetMesh())
507 ## Sets a name to the mesh
508 # @param name a new name of the mesh
509 def SetName(self, name):
510 SetName(self.GetMesh(), name)
512 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
513 # The subMesh object gives access to the IDs of nodes and elements.
514 # @param theSubObject a geometrical object (shape)
515 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
516 def GetSubMesh(self, theSubObject, name):
517 submesh = self.mesh.GetSubMesh(theSubObject, name)
520 ## Returns the shape associated to the mesh
521 # @return a GEOM_Object
525 ## Associates the given shape to the mesh (entails the recreation of the mesh)
526 # @param geom the shape to be meshed (GEOM_Object)
527 def SetShape(self, geom):
528 self.mesh = self.smeshpyD.CreateMesh(geom)
530 ## Returns true if the hypotheses are defined well
531 # @param theSubObject a subshape of a mesh shape
532 # @return True or False
533 def IsReadyToCompute(self, theSubObject):
534 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
536 ## Returns errors of hypotheses definition.
537 # The list of errors is empty if everything is OK.
538 # @param theSubObject a subshape of a mesh shape
539 # @return a list of errors
540 def GetAlgoState(self, theSubObject):
541 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
543 ## Returns a geometrical object on which the given element was built.
544 # The returned geometrical object, if not nil, is either found in the
545 # study or published by this method with the given name
546 # @param theElementID the id of the mesh element
547 # @param theGeomName the user-defined name of the geometrical object
548 # @return GEOM::GEOM_Object instance
549 def GetGeometryByMeshElement(self, theElementID, theGeomName):
550 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
552 ## Returns the mesh dimension depending on the dimension of the underlying shape
553 # @return mesh dimension as an integer value [0,3]
554 def MeshDimension(self):
555 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
556 if len( shells ) > 0 :
558 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
560 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
566 ## Creates a segment discretization 1D algorithm.
567 # If the optional \a algo parameter is not set, this algorithm is REGULAR.
568 # \n If the optional \a geom parameter is not set, this algorithm is global.
569 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
570 # @param algo the type of the required algorithm. Possible values are:
572 # - smesh.PYTHON for discretization via a python function,
573 # - smesh.COMPOSITE for meshing a set of edges on one face side as a whole.
574 # @param geom If defined is the subshape to be meshed
575 # @return an instance of Mesh_Segment or Mesh_Segment_Python, or Mesh_CompositeSegment class
576 def Segment(self, algo=REGULAR, geom=0):
577 ## if Segment(geom) is called by mistake
578 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
579 algo, geom = geom, algo
580 if not algo: algo = REGULAR
583 return Mesh_Segment(self, geom)
585 return Mesh_Segment_Python(self, geom)
586 elif algo == COMPOSITE:
587 return Mesh_CompositeSegment(self, geom)
589 return Mesh_Segment(self, geom)
591 ## Enables creation of nodes and segments usable by 2D algoritms.
592 # The added nodes and segments must be bound to edges and vertices by
593 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
594 # If the optional \a geom parameter is not set, this algorithm is global.
595 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
596 # @param geom the subshape to be manually meshed
597 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
598 def UseExistingSegments(self, geom=0):
599 algo = Mesh_UseExisting(1,self,geom)
600 return algo.GetAlgorithm()
602 ## Enables creation of nodes and faces usable by 3D algoritms.
603 # The added nodes and faces must be bound to geom faces by SetNodeOnFace()
604 # and SetMeshElementOnShape()
605 # If the optional \a geom parameter is not set, this algorithm is global.
606 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
607 # @param geom the subshape to be manually meshed
608 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
609 def UseExistingFaces(self, geom=0):
610 algo = Mesh_UseExisting(2,self,geom)
611 return algo.GetAlgorithm()
613 ## Creates a triangle 2D algorithm for faces.
614 # If the optional \a geom parameter is not set, this algorithm is global.
615 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
616 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D || smesh.BLSURF
617 # @param geom If defined, the subshape to be meshed (GEOM_Object)
618 # @return an instance of Mesh_Triangle algorithm
619 def Triangle(self, algo=MEFISTO, geom=0):
620 ## if Triangle(geom) is called by mistake
621 if (isinstance(algo, geompyDC.GEOM._objref_GEOM_Object)):
625 return Mesh_Triangle(self, algo, geom)
627 ## Creates a quadrangle 2D algorithm for faces.
628 # If the optional \a geom parameter is not set, this algorithm is global.
629 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
630 # @param geom If defined, the subshape to be meshed (GEOM_Object)
631 # @return an instance of Mesh_Quadrangle algorithm
632 def Quadrangle(self, geom=0):
633 return Mesh_Quadrangle(self, geom)
635 ## Creates a tetrahedron 3D algorithm for solids.
636 # The parameter \a algo permits to choose the algorithm: NETGEN or GHS3D
637 # If the optional \a geom parameter is not set, this algorithm is global.
638 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
639 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
640 # @param geom If defined, the subshape to be meshed (GEOM_Object)
641 # @return an instance of Mesh_Tetrahedron algorithm
642 def Tetrahedron(self, algo=NETGEN, geom=0):
643 ## if Tetrahedron(geom) is called by mistake
644 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
645 algo, geom = geom, algo
646 if not algo: algo = NETGEN
648 return Mesh_Tetrahedron(self, algo, geom)
650 ## Creates a hexahedron 3D algorithm for solids.
651 # If the optional \a geom parameter is not set, this algorithm is global.
652 # \n Otherwise, this algorithm defines a submesh based on \a geom subshape.
653 # @param algo possible values are: smesh.Hexa, smesh.Hexotic
654 # @param geom If defined, the subshape to be meshed (GEOM_Object)
655 # @return an instance of Mesh_Hexahedron algorithm
656 def Hexahedron(self, algo=Hexa, geom=0):
657 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
658 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
659 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
660 elif geom == 0: algo, geom = Hexa, algo
661 return Mesh_Hexahedron(self, algo, geom)
663 ## Deprecated, used only for compatibility!
664 # @return an instance of Mesh_Netgen algorithm
665 def Netgen(self, is3D, geom=0):
666 return Mesh_Netgen(self, is3D, geom)
668 ## Creates a projection 1D algorithm for edges.
669 # If the optional \a geom parameter is not set, this algorithm is global.
670 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
671 # @param geom If defined, the subshape to be meshed
672 # @return an instance of Mesh_Projection1D algorithm
673 def Projection1D(self, geom=0):
674 return Mesh_Projection1D(self, geom)
676 ## Creates a projection 2D algorithm for faces.
677 # If the optional \a geom parameter is not set, this algorithm is global.
678 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
679 # @param geom If defined, the subshape to be meshed
680 # @return an instance of Mesh_Projection2D algorithm
681 def Projection2D(self, geom=0):
682 return Mesh_Projection2D(self, geom)
684 ## Creates a projection 3D algorithm for solids.
685 # If the optional \a geom parameter is not set, this algorithm is global.
686 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
687 # @param geom If defined, the subshape to be meshed
688 # @return an instance of Mesh_Projection3D algorithm
689 def Projection3D(self, geom=0):
690 return Mesh_Projection3D(self, geom)
692 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
693 # If the optional \a geom parameter is not set, this algorithm is global.
694 # Otherwise, this algorithm defines a submesh based on \a geom subshape.
695 # @param geom If defined, the subshape to be meshed
696 # @return an instance of Mesh_Prism3D or Mesh_RadialPrism3D algorithm
697 def Prism(self, geom=0):
701 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
702 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
703 if nbSolids == 0 or nbSolids == nbShells:
704 return Mesh_Prism3D(self, geom)
705 return Mesh_RadialPrism3D(self, geom)
707 ## Computes the mesh and returns the status of the computation
708 # @return True or False
709 def Compute(self, geom=0):
710 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
712 print "Compute impossible: mesh is not constructed on geom shape."
718 ok = self.smeshpyD.Compute(self.mesh, geom)
719 except SALOME.SALOME_Exception, ex:
720 print "Mesh computation failed, exception caught:"
721 print " ", ex.details.text
724 print "Mesh computation failed, exception caught:"
725 traceback.print_exc()
727 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
738 reason = '%s %sD algorithm is missing' % (glob, dim)
739 elif err.state == HYP_MISSING:
740 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
741 % (glob, dim, name, dim))
742 elif err.state == HYP_NOTCONFORM:
743 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
744 elif err.state == HYP_BAD_PARAMETER:
745 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
746 % ( glob, dim, name ))
747 elif err.state == HYP_BAD_GEOMETRY:
748 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
749 'geometry' % ( glob, dim, name ))
751 reason = "For unknown reason."+\
752 " Revise Mesh.Compute() implementation in smeshDC.py!"
760 print '"' + GetName(self.mesh) + '"',"has not been computed:"
763 print '"' + GetName(self.mesh) + '"',"has not been computed."
766 if salome.sg.hasDesktop():
767 smeshgui = salome.ImportComponentGUI("SMESH")
768 smeshgui.Init(salome.myStudyId)
769 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
770 salome.sg.updateObjBrowser(1)
774 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
775 # The parameter \a fineness [0,-1] defines mesh fineness
776 # @return True or False
777 def AutomaticTetrahedralization(self, fineness=0):
778 dim = self.MeshDimension()
780 self.RemoveGlobalHypotheses()
781 self.Segment().AutomaticLength(fineness)
783 self.Triangle().LengthFromEdges()
786 self.Tetrahedron(NETGEN)
788 return self.Compute()
790 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
791 # The parameter \a fineness [0,-1] defines mesh fineness
792 # @return True or False
793 def AutomaticHexahedralization(self, fineness=0):
794 dim = self.MeshDimension()
795 # assign the hypotheses
796 self.RemoveGlobalHypotheses()
797 self.Segment().AutomaticLength(fineness)
804 return self.Compute()
806 ## Assigns a hypothesis
807 # @param hyp a hypothesis to assign
808 # @param geom a subhape of mesh geometry
809 # @return SMESH.Hypothesis_Status
810 def AddHypothesis(self, hyp, geom=0):
811 if isinstance( hyp, Mesh_Algorithm ):
812 hyp = hyp.GetAlgorithm()
817 status = self.mesh.AddHypothesis(geom, hyp)
818 isAlgo = hyp._narrow( SMESH_Algo )
819 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
822 ## Unassigns a hypothesis
823 # @param hyp a hypothesis to unassign
824 # @param geom a subshape of mesh geometry
825 # @return SMESH.Hypothesis_Status
826 def RemoveHypothesis(self, hyp, geom=0):
827 if isinstance( hyp, Mesh_Algorithm ):
828 hyp = hyp.GetAlgorithm()
833 status = self.mesh.RemoveHypothesis(geom, hyp)
836 ## Gets the list of hypotheses added on a geometry
837 # @param geom a subshape of mesh geometry
838 # @return the sequence of SMESH_Hypothesis
839 def GetHypothesisList(self, geom):
840 return self.mesh.GetHypothesisList( geom )
842 ## Removes all global hypotheses
843 def RemoveGlobalHypotheses(self):
844 current_hyps = self.mesh.GetHypothesisList( self.geom )
845 for hyp in current_hyps:
846 self.mesh.RemoveHypothesis( self.geom, hyp )
850 ## Creates a mesh group based on the geometric object \a grp
851 # and gives a \a name, \n if this parameter is not defined
852 # the name is the same as the geometric group name \n
853 # Note: Works like GroupOnGeom().
854 # @param grp a geometric group, a vertex, an edge, a face or a solid
855 # @param name the name of the mesh group
856 # @return SMESH_GroupOnGeom
857 def Group(self, grp, name=""):
858 return self.GroupOnGeom(grp, name)
860 ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
861 # Exports the mesh in a file in MED format and chooses the \a version of MED format
862 # @param f the file name
863 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
864 def ExportToMED(self, f, version, opt=0):
865 self.mesh.ExportToMED(f, opt, version)
867 ## Exports the mesh in a file in MED format
868 # @param f is the file name
869 # @param auto_groups boolean parameter for creating/not creating
870 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
871 # the typical use is auto_groups=false.
872 # @param version MED format version(MED_V2_1 or MED_V2_2)
873 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
874 self.mesh.ExportToMED(f, auto_groups, version)
876 ## Exports the mesh in a file in DAT format
877 # @param f the file name
878 def ExportDAT(self, f):
879 self.mesh.ExportDAT(f)
881 ## Exports the mesh in a file in UNV format
882 # @param f the file name
883 def ExportUNV(self, f):
884 self.mesh.ExportUNV(f)
886 ## Export the mesh in a file in STL format
887 # @param f the file name
888 # @param ascii defines the file encoding
889 def ExportSTL(self, f, ascii=1):
890 self.mesh.ExportSTL(f, ascii)
893 # Operations with groups:
894 # ----------------------
896 ## Creates an empty mesh group
897 # @param elementType the type of elements in the group
898 # @param name the name of the mesh group
899 # @return SMESH_Group
900 def CreateEmptyGroup(self, elementType, name):
901 return self.mesh.CreateGroup(elementType, name)
903 ## Creates a mesh group based on the geometrical object \a grp
904 # and gives a \a name, \n if this parameter is not defined
905 # the name is the same as the geometrical group name
906 # @param grp a geometrical group, a vertex, an edge, a face or a solid
907 # @param name the name of the mesh group
908 # @return SMESH_GroupOnGeom
909 def GroupOnGeom(self, grp, name="", typ=None):
914 tgeo = str(grp.GetShapeType())
921 elif tgeo == "SOLID":
923 elif tgeo == "SHELL":
925 elif tgeo == "COMPOUND":
926 if len( self.geompyD.GetObjectIDs( grp )) == 0:
927 print "Mesh.Group: empty geometric group", GetName( grp )
929 tgeo = self.geompyD.GetType(grp)
930 if tgeo == geompyDC.ShapeType["VERTEX"]:
932 elif tgeo == geompyDC.ShapeType["EDGE"]:
934 elif tgeo == geompyDC.ShapeType["FACE"]:
936 elif tgeo == geompyDC.ShapeType["SOLID"]:
940 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
943 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
945 ## Creates a mesh group by the given ids of elements
946 # @param groupName the name of the mesh group
947 # @param elementType the type of elements in the group
948 # @param elemIDs the list of ids
949 # @return SMESH_Group
950 def MakeGroupByIds(self, groupName, elementType, elemIDs):
951 group = self.mesh.CreateGroup(elementType, groupName)
955 ## Creates a mesh group by the given conditions
956 # @param groupName the name of the mesh group
957 # @param elementType the type of elements in the group
958 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
959 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
960 # @param Treshold the threshold value (range of id ids as string, shape, numeric)
961 # @param UnaryOp FT_LogicalNOT or FT_Undefined
962 # @return SMESH_Group
966 CritType=FT_Undefined,
969 UnaryOp=FT_Undefined):
970 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
971 group = self.MakeGroupByCriterion(groupName, aCriterion)
974 ## Creates a mesh group by the given criterion
975 # @param groupName the name of the mesh group
976 # @param Criterion the instance of Criterion class
977 # @return SMESH_Group
978 def MakeGroupByCriterion(self, groupName, Criterion):
979 aFilterMgr = self.smeshpyD.CreateFilterManager()
980 aFilter = aFilterMgr.CreateFilter()
982 aCriteria.append(Criterion)
983 aFilter.SetCriteria(aCriteria)
984 group = self.MakeGroupByFilter(groupName, aFilter)
987 ## Creates a mesh group by the given criteria (list of criteria)
988 # @param groupName the name of the mesh group
989 # @param Criteria the list of criteria
990 # @return SMESH_Group
991 def MakeGroupByCriteria(self, groupName, theCriteria):
992 aFilterMgr = self.smeshpyD.CreateFilterManager()
993 aFilter = aFilterMgr.CreateFilter()
994 aFilter.SetCriteria(theCriteria)
995 group = self.MakeGroupByFilter(groupName, aFilter)
998 ## Creates a mesh group by the given filter
999 # @param groupName the name of the mesh group
1000 # @param Criterion the instance of Filter class
1001 # @return SMESH_Group
1002 def MakeGroupByFilter(self, groupName, theFilter):
1003 anIds = theFilter.GetElementsId(self.mesh)
1004 anElemType = theFilter.GetElementType()
1005 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1008 ## Passes mesh elements through the given filter and return IDs of fitting elements
1009 # @param theFilter SMESH_Filter
1010 # @return a list of ids
1011 def GetIdsFromFilter(self, theFilter):
1012 return theFilter.GetElementsId(self.mesh)
1014 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
1015 # Returns a list of special structures (borders).
1016 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
1017 def GetFreeBorders(self):
1018 aFilterMgr = self.smeshpyD.CreateFilterManager()
1019 aPredicate = aFilterMgr.CreateFreeEdges()
1020 aPredicate.SetMesh(self.mesh)
1021 aBorders = aPredicate.GetBorders()
1025 def RemoveGroup(self, group):
1026 self.mesh.RemoveGroup(group)
1028 ## Removes a group with its contents
1029 def RemoveGroupWithContents(self, group):
1030 self.mesh.RemoveGroupWithContents(group)
1032 ## Gets the list of groups existing in the mesh
1033 # @return a sequence of SMESH_GroupBase
1034 def GetGroups(self):
1035 return self.mesh.GetGroups()
1037 ## Gets the number of groups existing in the mesh
1038 # @return the quantity of groups as an integer value
1040 return self.mesh.NbGroups()
1042 ## Gets the list of names of groups existing in the mesh
1043 # @return list of strings
1044 def GetGroupNames(self):
1045 groups = self.GetGroups()
1047 for group in groups:
1048 names.append(group.GetName())
1051 ## Produces a union of two groups
1052 # A new group is created. All mesh elements that are
1053 # present in the initial groups are added to the new one
1054 # @return an instance of SMESH_Group
1055 def UnionGroups(self, group1, group2, name):
1056 return self.mesh.UnionGroups(group1, group2, name)
1058 ## Prodices an intersection of two groups
1059 # A new group is created. All mesh elements that are common
1060 # for the two initial groups are added to the new one.
1061 # @return an instance of SMESH_Group
1062 def IntersectGroups(self, group1, group2, name):
1063 return self.mesh.IntersectGroups(group1, group2, name)
1065 ## Produces a cut of two groups
1066 # A new group is created. All mesh elements that are present in
1067 # the main group but are not present in the tool group are added to the new one
1068 # @return an instance of SMESH_Group
1069 def CutGroups(self, mainGroup, toolGroup, name):
1070 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1073 # Get some info about mesh:
1074 # ------------------------
1076 ## Returns the log of nodes and elements added or removed
1077 # since the previous clear of the log.
1078 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1079 # @return list of log_block structures:
1084 def GetLog(self, clearAfterGet):
1085 return self.mesh.GetLog(clearAfterGet)
1087 ## Clears the log of nodes and elements added or removed since the previous
1088 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1090 self.mesh.ClearLog()
1092 ## Toggles auto color mode on the object.
1093 # @param theAutoColor the flag which toggles auto color mode.
1094 def SetAutoColor(self, theAutoColor):
1095 self.mesh.SetAutoColor(theAutoColor)
1097 ## Gets flag of object auto color mode.
1098 # @return True or False
1099 def GetAutoColor(self):
1100 return self.mesh.GetAutoColor()
1102 ## Gets the internal ID
1103 # @return integer value, which is the internal Id of the mesh
1105 return self.mesh.GetId()
1108 # @return integer value, which is the study Id of the mesh
1109 def GetStudyId(self):
1110 return self.mesh.GetStudyId()
1112 ## Checks the group names for duplications.
1113 # Consider the maximum group name length stored in MED file.
1114 # @return True or False
1115 def HasDuplicatedGroupNamesMED(self):
1116 return self.mesh.HasDuplicatedGroupNamesMED()
1118 ## Obtains the mesh editor tool
1119 # @return an instance of SMESH_MeshEditor
1120 def GetMeshEditor(self):
1121 return self.mesh.GetMeshEditor()
1124 # @return an instance of SALOME_MED::MESH
1125 def GetMEDMesh(self):
1126 return self.mesh.GetMEDMesh()
1129 # Get informations about mesh contents:
1130 # ------------------------------------
1132 ## Returns the number of nodes in the mesh
1133 # @return an integer value
1135 return self.mesh.NbNodes()
1137 ## Returns the number of elements in the mesh
1138 # @return an integer value
1139 def NbElements(self):
1140 return self.mesh.NbElements()
1142 ## Returns the number of edges in the mesh
1143 # @return an integer value
1145 return self.mesh.NbEdges()
1147 ## Returns the number of edges with the given order in the mesh
1148 # @param elementOrder the order of elements:
1149 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1150 # @return an integer value
1151 def NbEdgesOfOrder(self, elementOrder):
1152 return self.mesh.NbEdgesOfOrder(elementOrder)
1154 ## Returns the number of faces in the mesh
1155 # @return an integer value
1157 return self.mesh.NbFaces()
1159 ## Returns the number of faces with the given order in the mesh
1160 # @param elementOrder the order of elements:
1161 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1162 # @return an integer value
1163 def NbFacesOfOrder(self, elementOrder):
1164 return self.mesh.NbFacesOfOrder(elementOrder)
1166 ## Returns the number of triangles in the mesh
1167 # @return an integer value
1168 def NbTriangles(self):
1169 return self.mesh.NbTriangles()
1171 ## Returns the number of triangles with the given order in the mesh
1172 # @param elementOrder is the order of elements:
1173 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1174 # @return an integer value
1175 def NbTrianglesOfOrder(self, elementOrder):
1176 return self.mesh.NbTrianglesOfOrder(elementOrder)
1178 ## Returns the number of quadrangles in the mesh
1179 # @return an integer value
1180 def NbQuadrangles(self):
1181 return self.mesh.NbQuadrangles()
1183 ## Returns the number of quadrangles with the given order in the mesh
1184 # @param elementOrder the order of elements:
1185 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1186 # @return an integer value
1187 def NbQuadranglesOfOrder(self, elementOrder):
1188 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1190 ## Returns the number of polygons in the mesh
1191 # @return an integer value
1192 def NbPolygons(self):
1193 return self.mesh.NbPolygons()
1195 ## Returns the number of volumes in the mesh
1196 # @return an integer value
1197 def NbVolumes(self):
1198 return self.mesh.NbVolumes()
1200 ## Returns the number of volumes with the given order in the mesh
1201 # @param elementOrder the order of elements:
1202 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1203 # @return an integer value
1204 def NbVolumesOfOrder(self, elementOrder):
1205 return self.mesh.NbVolumesOfOrder(elementOrder)
1207 ## Returns the number of tetrahedrons in the mesh
1208 # @return an integer value
1210 return self.mesh.NbTetras()
1212 ## Returns the number of tetrahedrons with the given order in the mesh
1213 # @param elementOrder the order of elements:
1214 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1215 # @return an integer value
1216 def NbTetrasOfOrder(self, elementOrder):
1217 return self.mesh.NbTetrasOfOrder(elementOrder)
1219 ## Returns the number of hexahedrons in the mesh
1220 # @return an integer value
1222 return self.mesh.NbHexas()
1224 ## Returns the number of hexahedrons with the given order in the mesh
1225 # @param elementOrder the order of elements:
1226 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1227 # @return an integer value
1228 def NbHexasOfOrder(self, elementOrder):
1229 return self.mesh.NbHexasOfOrder(elementOrder)
1231 ## Returns the number of pyramids in the mesh
1232 # @return an integer value
1233 def NbPyramids(self):
1234 return self.mesh.NbPyramids()
1236 ## Returns the number of pyramids with the given order in the mesh
1237 # @param elementOrder the order of elements:
1238 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1239 # @return an integer value
1240 def NbPyramidsOfOrder(self, elementOrder):
1241 return self.mesh.NbPyramidsOfOrder(elementOrder)
1243 ## Returns the number of prisms in the mesh
1244 # @return an integer value
1246 return self.mesh.NbPrisms()
1248 ## Returns the number of prisms with the given order in the mesh
1249 # @param elementOrder the order of elements:
1250 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1251 # @return an integer value
1252 def NbPrismsOfOrder(self, elementOrder):
1253 return self.mesh.NbPrismsOfOrder(elementOrder)
1255 ## Returns the number of polyhedrons in the mesh
1256 # @return an integer value
1257 def NbPolyhedrons(self):
1258 return self.mesh.NbPolyhedrons()
1260 ## Returns the number of submeshes in the mesh
1261 # @return an integer value
1262 def NbSubMesh(self):
1263 return self.mesh.NbSubMesh()
1265 ## Returns the list of mesh elements IDs
1266 # @return the list of integer values
1267 def GetElementsId(self):
1268 return self.mesh.GetElementsId()
1270 ## Returns the list of IDs of mesh elements with the given type
1271 # @param elementType the required type of elements
1272 # @return list of integer values
1273 def GetElementsByType(self, elementType):
1274 return self.mesh.GetElementsByType(elementType)
1276 ## Returns the list of mesh nodes IDs
1277 # @return the list of integer values
1278 def GetNodesId(self):
1279 return self.mesh.GetNodesId()
1281 # Get the information about mesh elements:
1282 # ------------------------------------
1284 ## Returns the type of mesh element
1285 # @return the value from SMESH::ElementType enumeration
1286 def GetElementType(self, id, iselem):
1287 return self.mesh.GetElementType(id, iselem)
1289 ## Returns the list of submesh elements IDs
1290 # @param Shape a geom object(subshape) IOR
1291 # Shape must be the subshape of a ShapeToMesh()
1292 # @return the list of integer values
1293 def GetSubMeshElementsId(self, Shape):
1294 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1295 ShapeID = Shape.GetSubShapeIndices()[0]
1298 return self.mesh.GetSubMeshElementsId(ShapeID)
1300 ## Returns the list of submesh nodes IDs
1301 # @param Shape a geom object(subshape) IOR
1302 # Shape must be the subshape of a ShapeToMesh()
1303 # @return the list of integer values
1304 def GetSubMeshNodesId(self, Shape, all):
1305 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1306 ShapeID = Shape.GetSubShapeIndices()[0]
1309 return self.mesh.GetSubMeshNodesId(ShapeID, all)
1311 ## Returns the list of IDs of submesh elements with the given type
1312 # @param Shape a geom object(subshape) IOR
1313 # Shape must be a subshape of a ShapeToMesh()
1314 # @return the list of integer values
1315 def GetSubMeshElementType(self, Shape):
1316 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1317 ShapeID = Shape.GetSubShapeIndices()[0]
1320 return self.mesh.GetSubMeshElementType(ShapeID)
1322 ## Gets the mesh description
1323 # @return string value
1325 return self.mesh.Dump()
1328 # Get the information about nodes and elements of a mesh by its IDs:
1329 # -----------------------------------------------------------
1331 ## Gets XYZ coordinates of a node
1332 # \n If there is no nodes for the given ID - returns an empty list
1333 # @return a list of double precision values
1334 def GetNodeXYZ(self, id):
1335 return self.mesh.GetNodeXYZ(id)
1337 ## Returns list of IDs of inverse elements for the given node
1338 # \n If there is no node for the given ID - returns an empty list
1339 # @return a list of integer values
1340 def GetNodeInverseElements(self, id):
1341 return self.mesh.GetNodeInverseElements(id)
1343 ## @brief Returns the position of a node on the shape
1344 # @return SMESH::NodePosition
1345 def GetNodePosition(self,NodeID):
1346 return self.mesh.GetNodePosition(NodeID)
1348 ## If the given element is a node, returns the ID of shape
1349 # \n If there is no node for the given ID - returns -1
1350 # @return an integer value
1351 def GetShapeID(self, id):
1352 return self.mesh.GetShapeID(id)
1354 ## Returns the ID of the result shape after
1355 # FindShape() from SMESH_MeshEditor for the given element
1356 # \n If there is no element for the given ID - returns -1
1357 # @return an integer value
1358 def GetShapeIDForElem(self,id):
1359 return self.mesh.GetShapeIDForElem(id)
1361 ## Returns the number of nodes for the given element
1362 # \n If there is no element for the given ID - returns -1
1363 # @return an integer value
1364 def GetElemNbNodes(self, id):
1365 return self.mesh.GetElemNbNodes(id)
1367 ## Returns the node ID the given index for the given element
1368 # \n If there is no element for the given ID - returns -1
1369 # \n If there is no node for the given index - returns -2
1370 # @return an integer value
1371 def GetElemNode(self, id, index):
1372 return self.mesh.GetElemNode(id, index)
1374 ## Returns the IDs of nodes of the given element
1375 # @return a list of integer values
1376 def GetElemNodes(self, id):
1377 return self.mesh.GetElemNodes(id)
1379 ## Returns true if the given node is the medium node in the given quadratic element
1380 def IsMediumNode(self, elementID, nodeID):
1381 return self.mesh.IsMediumNode(elementID, nodeID)
1383 ## Returns true if the given node is the medium node in one of quadratic elements
1384 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1385 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1387 ## Returns the number of edges for the given element
1388 def ElemNbEdges(self, id):
1389 return self.mesh.ElemNbEdges(id)
1391 ## Returns the number of faces for the given element
1392 def ElemNbFaces(self, id):
1393 return self.mesh.ElemNbFaces(id)
1395 ## Returns true if the given element is a polygon
1396 def IsPoly(self, id):
1397 return self.mesh.IsPoly(id)
1399 ## Returns true if the given element is quadratic
1400 def IsQuadratic(self, id):
1401 return self.mesh.IsQuadratic(id)
1403 ## Returns XYZ coordinates of the barycenter of the given element
1404 # \n If there is no element for the given ID - returns an empty list
1405 # @return a list of three double values
1406 def BaryCenter(self, id):
1407 return self.mesh.BaryCenter(id)
1410 # Mesh edition (SMESH_MeshEditor functionality):
1411 # ---------------------------------------------
1413 ## Removes the elements from the mesh by ids
1414 # @param IDsOfElements is a list of ids of elements to remove
1415 # @return True or False
1416 def RemoveElements(self, IDsOfElements):
1417 return self.editor.RemoveElements(IDsOfElements)
1419 ## Removes nodes from mesh by ids
1420 # @param IDsOfNodes is a list of ids of nodes to remove
1421 # @return True or False
1422 def RemoveNodes(self, IDsOfNodes):
1423 return self.editor.RemoveNodes(IDsOfNodes)
1425 ## Add a node to the mesh by coordinates
1426 # @return Id of the new node
1427 def AddNode(self, x, y, z):
1428 return self.editor.AddNode( x, y, z)
1431 ## Creates a linear or quadratic edge (this is determined
1432 # by the number of given nodes).
1433 # @param IdsOfNodes the list of node IDs for creation of the element.
1434 # The order of nodes in this list should correspond to the description
1435 # of MED. \n This description is located by the following link:
1436 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1437 # @return the Id of the new edge
1438 def AddEdge(self, IDsOfNodes):
1439 return self.editor.AddEdge(IDsOfNodes)
1441 ## Creates a linear or quadratic face (this is determined
1442 # by the number of given nodes).
1443 # @param IdsOfNodes the list of node IDs for creation of the element.
1444 # The order of nodes in this list should correspond to the description
1445 # of MED. \n This description is located by the following link:
1446 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1447 # @return the Id of the new face
1448 def AddFace(self, IDsOfNodes):
1449 return self.editor.AddFace(IDsOfNodes)
1451 ## Adds a polygonal face to the mesh by the list of node IDs
1452 # @return the Id of the new face
1453 def AddPolygonalFace(self, IdsOfNodes):
1454 return self.editor.AddPolygonalFace(IdsOfNodes)
1456 ## Creates both simple and quadratic volume (this is determined
1457 # by the number of given nodes).
1458 # @param IdsOfNodes the list of node IDs for creation of the element.
1459 # The order of nodes in this list should correspond to the description
1460 # of MED. \n This description is located by the following link:
1461 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1462 # @return the Id of the new volumic element
1463 def AddVolume(self, IDsOfNodes):
1464 return self.editor.AddVolume(IDsOfNodes)
1466 ## Creates a volume of many faces, giving nodes for each face.
1467 # @param IdsOfNodes the list of node IDs for volume creation face by face.
1468 # @param Quantities the list of integer values, Quantities[i]
1469 # gives the quantity of nodes in face number i.
1470 # @return the Id of the new volumic element
1471 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1472 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1474 ## Creates a volume of many faces, giving the IDs of the existing faces.
1475 # @param IdsOfFaces the list of face IDs for volume creation.
1477 # Note: The created volume will refer only to the nodes
1478 # of the given faces, not to the faces themselves.
1479 # @return the Id of the new volumic element
1480 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1481 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1484 ## @brief Binds a node to a vertex
1485 # @param NodeID a node ID
1486 # @param Vertex a vertex or vertex ID
1487 # @return True if succeed else raises an exception
1488 def SetNodeOnVertex(self, NodeID, Vertex):
1489 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
1490 VertexID = Vertex.GetSubShapeIndices()[0]
1494 self.editor.SetNodeOnVertex(NodeID, VertexID)
1495 except SALOME.SALOME_Exception, inst:
1496 raise ValueError, inst.details.text
1500 ## @brief Stores the node position on an edge
1501 # @param NodeID a node ID
1502 # @param Edge an edge or edge ID
1503 # @param paramOnEdge a parameter on the edge where the node is located
1504 # @return True if succeed else raises an exception
1505 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
1506 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
1507 EdgeID = Edge.GetSubShapeIndices()[0]
1511 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
1512 except SALOME.SALOME_Exception, inst:
1513 raise ValueError, inst.details.text
1516 ## @brief Stores node position on a face
1517 # @param NodeID a node ID
1518 # @param Face a face or face ID
1519 # @param u U parameter on the face where the node is located
1520 # @param v V parameter on the face where the node is located
1521 # @return True if succeed else raises an exception
1522 def SetNodeOnFace(self, NodeID, Face, u, v):
1523 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
1524 FaceID = Face.GetSubShapeIndices()[0]
1528 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
1529 except SALOME.SALOME_Exception, inst:
1530 raise ValueError, inst.details.text
1533 ## @brief Binds a node to a solid
1534 # @param NodeID a node ID
1535 # @param Solid a solid or solid ID
1536 # @return True if succeed else raises an exception
1537 def SetNodeInVolume(self, NodeID, Solid):
1538 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
1539 SolidID = Solid.GetSubShapeIndices()[0]
1543 self.editor.SetNodeInVolume(NodeID, SolidID)
1544 except SALOME.SALOME_Exception, inst:
1545 raise ValueError, inst.details.text
1548 ## @brief Bind an element to a shape
1549 # @param ElementID an element ID
1550 # @param Shape a shape or shape ID
1551 # @return True if succeed else raises an exception
1552 def SetMeshElementOnShape(self, ElementID, Shape):
1553 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1554 ShapeID = Shape.GetSubShapeIndices()[0]
1558 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
1559 except SALOME.SALOME_Exception, inst:
1560 raise ValueError, inst.details.text
1564 ## Moves the node with the given id
1565 # @param NodeID the id of the node
1566 # @param x a new X coordinate
1567 # @param y a new Y coordinate
1568 # @param z a new Z coordinate
1569 # @return True if succeed else False
1570 def MoveNode(self, NodeID, x, y, z):
1571 return self.editor.MoveNode(NodeID, x, y, z)
1573 ## Finds the node closest to a point
1574 # @param x the X coordinate of a point
1575 # @param y the Y coordinate of a point
1576 # @param z the Z coordinate of a point
1577 # @return the ID of a node
1578 def FindNodeClosestTo(self, x, y, z):
1579 preview = self.mesh.GetMeshEditPreviewer()
1580 return preview.MoveClosestNodeToPoint(x, y, z, -1)
1582 ## Finds the node closest to a point and moves it to a point location
1583 # @param x the X coordinate of a point
1584 # @param y the Y coordinate of a point
1585 # @param z the Z coordinate of a point
1586 # @return the ID of a moved node
1587 def MeshToPassThroughAPoint(self, x, y, z):
1588 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1590 ## Replaces two neighbour triangles sharing Node1-Node2 link
1591 # with the triangles built on the same 4 nodes but having other common link.
1592 # @param NodeID1 the ID of the first node
1593 # @param NodeID2 the ID of the second node
1594 # @return false if proper faces were not found
1595 def InverseDiag(self, NodeID1, NodeID2):
1596 return self.editor.InverseDiag(NodeID1, NodeID2)
1598 ## Replaces two neighbour triangles sharing Node1-Node2 link
1599 # with a quadrangle built on the same 4 nodes.
1600 # @param NodeID1 the ID of the first node
1601 # @param NodeID2 the ID of the second node
1602 # @return false if proper faces were not found
1603 def DeleteDiag(self, NodeID1, NodeID2):
1604 return self.editor.DeleteDiag(NodeID1, NodeID2)
1606 ## Reorients elements by ids
1607 # @param IDsOfElements if undefined reorients all mesh elements
1608 # @return True if succeed else False
1609 def Reorient(self, IDsOfElements=None):
1610 if IDsOfElements == None:
1611 IDsOfElements = self.GetElementsId()
1612 return self.editor.Reorient(IDsOfElements)
1614 ## Reorients all elements of the object
1615 # @param theObject mesh, submesh or group
1616 # @return True if succeed else False
1617 def ReorientObject(self, theObject):
1618 if ( isinstance( theObject, Mesh )):
1619 theObject = theObject.GetMesh()
1620 return self.editor.ReorientObject(theObject)
1622 ## Fuses the neighbouring triangles into quadrangles.
1623 # @param IDsOfElements The triangles to be fused,
1624 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1625 # @param MaxAngle is the maximum angle between element normals at which the fusion
1626 # is still performed; theMaxAngle is mesured in radians.
1627 # @return TRUE in case of success, FALSE otherwise.
1628 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1629 if IDsOfElements == []:
1630 IDsOfElements = self.GetElementsId()
1631 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1633 ## Fuses the neighbouring triangles of the object into quadrangles
1634 # @param theObject is mesh, submesh or group
1635 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1636 # @param MaxAngle a max angle between element normals at which the fusion
1637 # is still performed; theMaxAngle is mesured in radians.
1638 # @return TRUE in case of success, FALSE otherwise.
1639 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1640 if ( isinstance( theObject, Mesh )):
1641 theObject = theObject.GetMesh()
1642 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1644 ## Splits quadrangles into triangles.
1645 # @param IDsOfElements the faces to be splitted.
1646 # @param theCriterion FT_...; used to choose a diagonal for splitting.
1647 # @return TRUE in case of success, FALSE otherwise.
1648 def QuadToTri (self, IDsOfElements, theCriterion):
1649 if IDsOfElements == []:
1650 IDsOfElements = self.GetElementsId()
1651 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
1653 ## Splits quadrangles into triangles.
1654 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
1655 # @param theCriterion FT_...; used to choose a diagonal for splitting.
1656 # @return TRUE in case of success, FALSE otherwise.
1657 def QuadToTriObject (self, theObject, theCriterion):
1658 if ( isinstance( theObject, Mesh )):
1659 theObject = theObject.GetMesh()
1660 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
1662 ## Splits quadrangles into triangles.
1663 # @param theElems the faces to be splitted
1664 # @param the13Diag is used to choose a diagonal for splitting.
1665 # @return TRUE in case of success, FALSE otherwise.
1666 def SplitQuad (self, IDsOfElements, Diag13):
1667 if IDsOfElements == []:
1668 IDsOfElements = self.GetElementsId()
1669 return self.editor.SplitQuad(IDsOfElements, Diag13)
1671 ## Splits quadrangles into triangles.
1672 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
1673 # @return TRUE in case of success, FALSE otherwise.
1674 def SplitQuadObject (self, theObject, Diag13):
1675 if ( isinstance( theObject, Mesh )):
1676 theObject = theObject.GetMesh()
1677 return self.editor.SplitQuadObject(theObject, Diag13)
1679 ## Finds a better splitting of the given quadrangle.
1680 # @param IDOfQuad the ID of the quadrangle to be splitted.
1681 # @param theCriterion FT_...; a criterion to choose a diagonal for splitting.
1682 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1683 # diagonal is better, 0 if error occurs.
1684 def BestSplit (self, IDOfQuad, theCriterion):
1685 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
1687 ## Splits quadrangle faces near triangular facets of volumes
1689 def SplitQuadsNearTriangularFacets(self):
1690 faces_array = self.GetElementsByType(SMESH.FACE)
1691 for face_id in faces_array:
1692 if self.GetElemNbNodes(face_id) == 4: # quadrangle
1693 quad_nodes = self.mesh.GetElemNodes(face_id)
1694 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1695 isVolumeFound = False
1696 for node1_elem in node1_elems:
1697 if not isVolumeFound:
1698 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1699 nb_nodes = self.GetElemNbNodes(node1_elem)
1700 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1701 volume_elem = node1_elem
1702 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1703 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1704 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1705 isVolumeFound = True
1706 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1707 self.SplitQuad([face_id], False) # diagonal 2-4
1708 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1709 isVolumeFound = True
1710 self.SplitQuad([face_id], True) # diagonal 1-3
1711 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1712 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1713 isVolumeFound = True
1714 self.SplitQuad([face_id], True) # diagonal 1-3
1716 ## @brief Splits hexahedrons into tetrahedrons.
1718 # This operation uses pattern mapping functionality for splitting.
1719 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
1720 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
1721 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
1722 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1723 # key-point will be mapped into <theNode001>-th node of each volume.
1724 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
1725 # @return TRUE in case of success, FALSE otherwise.
1726 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
1727 # Pattern: 5.---------.6
1732 # (0,0,1) 4.---------.7 * |
1739 # (0,0,0) 0.---------.3
1740 pattern_tetra = "!!! Nb of points: \n 8 \n\
1750 !!! Indices of points of 6 tetras: \n\
1758 pattern = self.smeshpyD.GetPattern()
1759 isDone = pattern.LoadFromFile(pattern_tetra)
1761 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1764 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1765 isDone = pattern.MakeMesh(self.mesh, False, False)
1766 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1768 # split quafrangle faces near triangular facets of volumes
1769 self.SplitQuadsNearTriangularFacets()
1773 ## @brief Split hexahedrons into prisms.
1775 # Uses the pattern mapping functionality for splitting.
1776 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
1777 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
1778 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
1779 # will be mapped into the <theNode000>-th node of each volume, keypoint (0,0,1)
1780 # will be mapped into the <theNode001>-th node of each volume.
1781 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
1782 # @return TRUE in case of success, FALSE otherwise.
1783 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
1784 # Pattern: 5.---------.6
1789 # (0,0,1) 4.---------.7 |
1796 # (0,0,0) 0.---------.3
1797 pattern_prism = "!!! Nb of points: \n 8 \n\
1807 !!! Indices of points of 2 prisms: \n\
1811 pattern = self.smeshpyD.GetPattern()
1812 isDone = pattern.LoadFromFile(pattern_prism)
1814 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1817 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1818 isDone = pattern.MakeMesh(self.mesh, False, False)
1819 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1821 # Splits quafrangle faces near triangular facets of volumes
1822 self.SplitQuadsNearTriangularFacets()
1826 ## Smoothes elements
1827 # @param IDsOfElements the list if ids of elements to smooth
1828 # @param IDsOfFixedNodes the list of ids of fixed nodes.
1829 # Note that nodes built on edges and boundary nodes are always fixed.
1830 # @param MaxNbOfIterations the maximum number of iterations
1831 # @param MaxAspectRatio varies in range [1.0, inf]
1832 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1833 # @return TRUE in case of success, FALSE otherwise.
1834 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1835 MaxNbOfIterations, MaxAspectRatio, Method):
1836 if IDsOfElements == []:
1837 IDsOfElements = self.GetElementsId()
1838 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1839 MaxNbOfIterations, MaxAspectRatio, Method)
1841 ## Smoothes elements which belong to the given object
1842 # @param theObject the object to smooth
1843 # @param IDsOfFixedNodes the list of ids of fixed nodes.
1844 # Note that nodes built on edges and boundary nodes are always fixed.
1845 # @param MaxNbOfIterations the maximum number of iterations
1846 # @param MaxAspectRatio varies in range [1.0, inf]
1847 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1848 # @return TRUE in case of success, FALSE otherwise.
1849 def SmoothObject(self, theObject, IDsOfFixedNodes,
1850 MaxNbOfIterations, MaxxAspectRatio, Method):
1851 if ( isinstance( theObject, Mesh )):
1852 theObject = theObject.GetMesh()
1853 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1854 MaxNbOfIterations, MaxxAspectRatio, Method)
1856 ## Parametrically smoothes the given elements
1857 # @param IDsOfElements the list if ids of elements to smooth
1858 # @param IDsOfFixedNodes the list of ids of fixed nodes.
1859 # Note that nodes built on edges and boundary nodes are always fixed.
1860 # @param MaxNbOfIterations the maximum number of iterations
1861 # @param MaxAspectRatio varies in range [1.0, inf]
1862 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1863 # @return TRUE in case of success, FALSE otherwise.
1864 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
1865 MaxNbOfIterations, MaxAspectRatio, Method):
1866 if IDsOfElements == []:
1867 IDsOfElements = self.GetElementsId()
1868 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1869 MaxNbOfIterations, MaxAspectRatio, Method)
1871 ## Parametrically smoothes the elements which belong to the given object
1872 # @param theObject the object to smooth
1873 # @param IDsOfFixedNodes the list of ids of fixed nodes.
1874 # Note that nodes built on edges and boundary nodes are always fixed.
1875 # @param MaxNbOfIterations the maximum number of iterations
1876 # @param MaxAspectRatio varies in range [1.0, inf]
1877 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1878 # @return TRUE in case of success, FALSE otherwise.
1879 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
1880 MaxNbOfIterations, MaxAspectRatio, Method):
1881 if ( isinstance( theObject, Mesh )):
1882 theObject = theObject.GetMesh()
1883 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
1884 MaxNbOfIterations, MaxAspectRatio, Method)
1886 ## Converts the mesh to quadratic, deletes old elements, replacing
1887 # them with quadratic with the same id.
1888 def ConvertToQuadratic(self, theForce3d):
1889 self.editor.ConvertToQuadratic(theForce3d)
1891 ## Converts the mesh from quadratic to ordinary,
1892 # deletes old quadratic elements, \n replacing
1893 # them with ordinary mesh elements with the same id.
1894 # @return TRUE in case of success, FALSE otherwise.
1895 def ConvertFromQuadratic(self):
1896 return self.editor.ConvertFromQuadratic()
1898 ## Renumber mesh nodes
1899 def RenumberNodes(self):
1900 self.editor.RenumberNodes()
1902 ## Renumber mesh elements
1903 def RenumberElements(self):
1904 self.editor.RenumberElements()
1906 ## Generates new elements by rotation of the elements around the axis
1907 # @param IDsOfElements the list of ids of elements to sweep
1908 # @param Axix the axis of rotation, AxisStruct or line(geom object)
1909 # @param AngleInRadians the angle of Rotation
1910 # @param NbOfStep the number of steps
1911 # @param Tolerance tolerance
1912 # @param MakeGroups forces the generation of new groups from existing ones
1913 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
1914 # of all steps, else - size of each step
1915 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1916 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance,
1917 MakeGroups=False, TotalAngle=False):
1918 if IDsOfElements == []:
1919 IDsOfElements = self.GetElementsId()
1920 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1921 Axix = self.smeshpyD.GetAxisStruct(Axix)
1922 if TotalAngle and NbOfSteps:
1923 AngleInRadians /= NbOfSteps
1925 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
1926 AngleInRadians, NbOfSteps, Tolerance)
1927 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
1930 ## Generates new elements by rotation of the elements of object around the axis
1931 # @param theObject object which elements should be sweeped
1932 # @param Axix the axis of rotation, AxisStruct or line(geom object)
1933 # @param AngleInRadians the angle of Rotation
1934 # @param NbOfSteps number of steps
1935 # @param Tolerance tolerance
1936 # @param MakeGroups forces the generation of new groups from existing ones
1937 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
1938 # of all steps, else - size of each step
1939 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1940 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance,
1941 MakeGroups=False, TotalAngle=False):
1942 if ( isinstance( theObject, Mesh )):
1943 theObject = theObject.GetMesh()
1944 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1945 Axix = self.smeshpyD.GetAxisStruct(Axix)
1946 if TotalAngle and NbOfSteps:
1947 AngleInRadians /= NbOfSteps
1949 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
1950 NbOfSteps, Tolerance)
1951 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
1954 ## Generates new elements by extrusion of the elements with given ids
1955 # @param IDsOfElements the list of elements ids for extrusion
1956 # @param StepVector vector, defining the direction and value of extrusion
1957 # @param NbOfSteps the number of steps
1958 # @param MakeGroups forces the generation of new groups from existing ones
1959 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1960 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
1961 if IDsOfElements == []:
1962 IDsOfElements = self.GetElementsId()
1963 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1964 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1966 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
1967 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
1970 ## Generates new elements by extrusion of the elements with given ids
1971 # @param IDsOfElements is ids of elements
1972 # @param StepVector vector, defining the direction and value of extrusion
1973 # @param NbOfSteps the number of steps
1974 # @param ExtrFlags sets flags for extrusion
1975 # @param SewTolerance uses for comparing locations of nodes if flag
1976 # EXTRUSION_FLAG_SEW is set
1977 # @param MakeGroups forces the generation of new groups from existing ones
1978 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1979 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
1980 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1981 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1983 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
1984 ExtrFlags, SewTolerance)
1985 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
1986 ExtrFlags, SewTolerance)
1989 ## Generates new elements by extrusion of the elements which belong to the object
1990 # @param theObject the object which elements should be processed
1991 # @param StepVector vector, defining the direction and value of extrusion
1992 # @param NbOfSteps the number of steps
1993 # @param MakeGroups forces the generation of new groups from existing ones
1994 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1995 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
1996 if ( isinstance( theObject, Mesh )):
1997 theObject = theObject.GetMesh()
1998 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1999 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2001 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2002 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2005 ## Generates new elements by extrusion of the elements which belong to the object
2006 # @param theObject object which elements should be processed
2007 # @param StepVector vector, defining the direction and value of extrusion
2008 # @param NbOfSteps the number of steps
2009 # @param MakeGroups to generate new groups from existing ones
2010 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2011 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2012 if ( isinstance( theObject, Mesh )):
2013 theObject = theObject.GetMesh()
2014 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2015 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2017 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2018 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2021 ## Generates new elements by extrusion of the elements which belong to the object
2022 # @param theObject object which elements should be processed
2023 # @param StepVector vector, defining the direction and value of extrusion
2024 # @param NbOfSteps the number of steps
2025 # @param MakeGroups forces the generation of new groups from existing ones
2026 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2027 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2028 if ( isinstance( theObject, Mesh )):
2029 theObject = theObject.GetMesh()
2030 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2031 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2033 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2034 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2037 ## Generates new elements by extrusion of the given elements
2038 # The path of extrusion must be a meshed edge.
2039 # @param IDsOfElements ids of elements
2040 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2041 # @param PathShape shape(edge) defines the sub-mesh for the path
2042 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2043 # @param HasAngles allows the shape to be rotated around the path
2044 # to get the resulting mesh in a helical fashion
2045 # @param Angles list of angles
2046 # @param HasRefPoint allows using the reference point
2047 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2048 # The User can specify any point as the Reference Point.
2049 # @param MakeGroups forces the generation of new groups from existing ones
2050 # @param LinearVariation forces the computation of rotation angles as linear
2051 # variation of the given Angles along path steps
2052 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2053 # only SMESH::Extrusion_Error otherwise
2054 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2055 HasAngles, Angles, HasRefPoint, RefPoint,
2056 MakeGroups=False, LinearVariation=False):
2057 if IDsOfElements == []:
2058 IDsOfElements = self.GetElementsId()
2059 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2060 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2062 if ( isinstance( PathMesh, Mesh )):
2063 PathMesh = PathMesh.GetMesh()
2064 if HasAngles and Angles and LinearVariation:
2065 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2068 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
2069 PathShape, NodeStart, HasAngles,
2070 Angles, HasRefPoint, RefPoint)
2071 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
2072 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2074 ## Generates new elements by extrusion of the elements which belong to the object
2075 # The path of extrusion must be a meshed edge.
2076 # @param IDsOfElements is ids of elements
2077 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
2078 # @param PathShape shape(edge) defines the sub-mesh for the path
2079 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
2080 # @param HasAngles allows the shape to be rotated around the path
2081 # to get the resulting mesh in a helical fashion
2082 # @param Angles list of angles
2083 # @param HasRefPoint allows using the reference point
2084 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
2085 # The User can specify any point as the Reference Point.
2086 # @param MakeGroups forces the generation of new groups from existing ones
2087 # @param LinearVariation forces the computation of rotation angles as linear
2088 # variation of the given Angles along path steps
2089 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2090 # only SMESH::Extrusion_Error otherwise
2091 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2092 HasAngles, Angles, HasRefPoint, RefPoint,
2093 MakeGroups=False, LinearVariation=False):
2094 if ( isinstance( theObject, Mesh )):
2095 theObject = theObject.GetMesh()
2096 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2097 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2098 if ( isinstance( PathMesh, Mesh )):
2099 PathMesh = PathMesh.GetMesh()
2100 if HasAngles and Angles and LinearVariation:
2101 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2104 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
2105 PathShape, NodeStart, HasAngles,
2106 Angles, HasRefPoint, RefPoint)
2107 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
2108 NodeStart, HasAngles, Angles, HasRefPoint,
2111 ## Creates a symmetrical copy of mesh elements
2112 # @param IDsOfElements list of elements ids
2113 # @param Mirror is AxisStruct or geom object(point, line, plane)
2114 # @param theMirrorType is POINT, AXIS or PLANE
2115 # If the Mirror is a geom object this parameter is unnecessary
2116 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
2117 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2118 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2119 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2120 if IDsOfElements == []:
2121 IDsOfElements = self.GetElementsId()
2122 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2123 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2124 if Copy and MakeGroups:
2125 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2126 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2129 ## Creates a new mesh by a symmetrical copy of mesh elements
2130 # @param IDsOfElements the list of elements ids
2131 # @param Mirror is AxisStruct or geom object (point, line, plane)
2132 # @param theMirrorType is POINT, AXIS or PLANE
2133 # If the Mirror is a geom object this parameter is unnecessary
2134 # @param MakeGroups to generate new groups from existing ones
2135 # @param NewMeshName a name of the new mesh to create
2136 # @return instance of Mesh class
2137 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
2138 if IDsOfElements == []:
2139 IDsOfElements = self.GetElementsId()
2140 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2141 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2142 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
2143 MakeGroups, NewMeshName)
2144 return Mesh(self.smeshpyD,self.geompyD,mesh)
2146 ## Creates a symmetrical copy of the object
2147 # @param theObject mesh, submesh or group
2148 # @param Mirror AxisStruct or geom object (point, line, plane)
2149 # @param theMirrorType is POINT, AXIS or PLANE
2150 # If the Mirror is a geom object this parameter is unnecessary
2151 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
2152 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2153 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2154 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2155 if ( isinstance( theObject, Mesh )):
2156 theObject = theObject.GetMesh()
2157 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2158 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2159 if Copy and MakeGroups:
2160 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2161 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2164 ## Creates a new mesh by a symmetrical copy of the object
2165 # @param theObject mesh, submesh or group
2166 # @param Mirror AxisStruct or geom object (point, line, plane)
2167 # @param theMirrorType POINT, AXIS or PLANE
2168 # If the Mirror is a geom object this parameter is unnecessary
2169 # @param MakeGroups forces the generation of new groups from existing ones
2170 # @param NewMeshName the name of the new mesh to create
2171 # @return instance of Mesh class
2172 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
2173 if ( isinstance( theObject, Mesh )):
2174 theObject = theObject.GetMesh()
2175 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2176 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2177 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
2178 MakeGroups, NewMeshName)
2179 return Mesh( self.smeshpyD,self.geompyD,mesh )
2181 ## Translates the elements
2182 # @param IDsOfElements list of elements ids
2183 # @param Vector the direction of translation (DirStruct or vector)
2184 # @param Copy allows copying the translated elements
2185 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2186 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2187 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2188 if IDsOfElements == []:
2189 IDsOfElements = self.GetElementsId()
2190 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2191 Vector = self.smeshpyD.GetDirStruct(Vector)
2192 if Copy and MakeGroups:
2193 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2194 self.editor.Translate(IDsOfElements, Vector, Copy)
2197 ## Creates a new mesh of translated elements
2198 # @param IDsOfElements list of elements ids
2199 # @param Vector the direction of translation (DirStruct or vector)
2200 # @param MakeGroups forces the generation of new groups from existing ones
2201 # @param NewMeshName the name of the newly created mesh
2202 # @return instance of Mesh class
2203 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
2204 if IDsOfElements == []:
2205 IDsOfElements = self.GetElementsId()
2206 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2207 Vector = self.smeshpyD.GetDirStruct(Vector)
2208 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
2209 return Mesh ( self.smeshpyD, self.geompyD, mesh )
2211 ## Translates the object
2212 # @param theObject the object to translate (mesh, submesh, or group)
2213 # @param Vector direction of translation (DirStruct or geom vector)
2214 # @param Copy allows copying the translated elements
2215 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2216 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2217 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2218 if ( isinstance( theObject, Mesh )):
2219 theObject = theObject.GetMesh()
2220 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2221 Vector = self.smeshpyD.GetDirStruct(Vector)
2222 if Copy and MakeGroups:
2223 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2224 self.editor.TranslateObject(theObject, Vector, Copy)
2227 ## Creates a new mesh from the translated object
2228 # @param theObject the object to translate (mesh, submesh, or group)
2229 # @param Vector the direction of translation (DirStruct or geom vector)
2230 # @param MakeGroups forces the generation of new groups from existing ones
2231 # @param NewMeshName the name of the newly created mesh
2232 # @return instance of Mesh class
2233 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
2234 if (isinstance(theObject, Mesh)):
2235 theObject = theObject.GetMesh()
2236 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
2237 Vector = self.smeshpyD.GetDirStruct(Vector)
2238 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
2239 return Mesh( self.smeshpyD, self.geompyD, mesh )
2241 ## Rotates the elements
2242 # @param IDsOfElements list of elements ids
2243 # @param Axis the axis of rotation (AxisStruct or geom line)
2244 # @param AngleInRadians the angle of rotation (in radians)
2245 # @param Copy allows copying the rotated elements
2246 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2247 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2248 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2249 if IDsOfElements == []:
2250 IDsOfElements = self.GetElementsId()
2251 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2252 Axis = self.smeshpyD.GetAxisStruct(Axis)
2253 if Copy and MakeGroups:
2254 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2255 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2258 ## Creates a new mesh of rotated elements
2259 # @param IDsOfElements list of element ids
2260 # @param Axis the axis of rotation (AxisStruct or geom line)
2261 # @param AngleInRadians the angle of rotation (in radians)
2262 # @param MakeGroups forces the generation of new groups from existing ones
2263 # @param NewMeshName the name of the newly created mesh
2264 # @return instance of Mesh class
2265 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
2266 if IDsOfElements == []:
2267 IDsOfElements = self.GetElementsId()
2268 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2269 Axis = self.smeshpyD.GetAxisStruct(Axis)
2270 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
2271 MakeGroups, NewMeshName)
2272 return Mesh( self.smeshpyD, self.geompyD, mesh )
2274 ## Rotates the object
2275 # @param theObject the object to rotate( mesh, submesh, or group)
2276 # @param Axis the axis of rotation (AxisStruct or geom line)
2277 # @param AngleInRadians the angle of rotation (in radians)
2278 # @param Copy allows copying the rotated elements
2279 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
2280 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2281 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2282 if (isinstance(theObject, Mesh)):
2283 theObject = theObject.GetMesh()
2284 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2285 Axis = self.smeshpyD.GetAxisStruct(Axis)
2286 if Copy and MakeGroups:
2287 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2288 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2291 ## Creates a new mesh from the rotated object
2292 # @param theObject the object to rotate (mesh, submesh, or group)
2293 # @param Axis the axis of rotation (AxisStruct or geom line)
2294 # @param AngleInRadians the angle of rotation (in radians)
2295 # @param MakeGroups forces the generation of new groups from existing ones
2296 # @param NewMeshName the name of the newly created mesh
2297 # @return instance of Mesh class
2298 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
2299 if (isinstance( theObject, Mesh )):
2300 theObject = theObject.GetMesh()
2301 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2302 Axis = self.smeshpyD.GetAxisStruct(Axis)
2303 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
2304 MakeGroups, NewMeshName)
2305 return Mesh( self.smeshpyD, self.geompyD, mesh )
2307 ## Finds groups of ajacent nodes within Tolerance.
2308 # @param Tolerance the value of tolerance
2309 # @return the list of groups of nodes
2310 def FindCoincidentNodes (self, Tolerance):
2311 return self.editor.FindCoincidentNodes(Tolerance)
2313 ## Finds groups of ajacent nodes within Tolerance.
2314 # @param Tolerance the value of tolerance
2315 # @param SubMeshOrGroup SubMesh or Group
2316 # @return the list of groups of nodes
2317 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2318 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2321 # @param GroupsOfNodes the list of groups of nodes
2322 def MergeNodes (self, GroupsOfNodes):
2323 self.editor.MergeNodes(GroupsOfNodes)
2325 ## Finds the elements built on the same nodes.
2326 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2327 # @return a list of groups of equal elements
2328 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2329 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2331 ## Merges elements in each given group.
2332 # @param GroupsOfElementsID groups of elements for merging
2333 def MergeElements(self, GroupsOfElementsID):
2334 self.editor.MergeElements(GroupsOfElementsID)
2336 ## Leaves one element and removes all other elements built on the same nodes.
2337 def MergeEqualElements(self):
2338 self.editor.MergeEqualElements()
2340 ## Sews free borders
2341 # @return SMESH::Sew_Error
2342 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2343 FirstNodeID2, SecondNodeID2, LastNodeID2,
2344 CreatePolygons, CreatePolyedrs):
2345 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2346 FirstNodeID2, SecondNodeID2, LastNodeID2,
2347 CreatePolygons, CreatePolyedrs)
2349 ## Sews conform free borders
2350 # @return SMESH::Sew_Error
2351 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2352 FirstNodeID2, SecondNodeID2):
2353 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2354 FirstNodeID2, SecondNodeID2)
2356 ## Sews border to side
2357 # @return SMESH::Sew_Error
2358 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2359 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2360 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2361 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2363 ## Sews two sides of a mesh. The nodes belonging to Side1 are
2364 # merged with the nodes of elements of Side2.
2365 # The number of elements in theSide1 and in theSide2 must be
2366 # equal and they should have similar nodal connectivity.
2367 # The nodes to merge should belong to side borders and
2368 # the first node should be linked to the second.
2369 # @return SMESH::Sew_Error
2370 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2371 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2372 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2373 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2374 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2375 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2377 ## Sets new nodes for the given element.
2378 # @param ide the element id
2379 # @param newIDs nodes ids
2380 # @return If the number of nodes does not correspond to the type of element - returns false
2381 def ChangeElemNodes(self, ide, newIDs):
2382 return self.editor.ChangeElemNodes(ide, newIDs)
2384 ## If during the last operation of MeshEditor some nodes were
2385 # created, this method returns the list of their IDs, \n
2386 # if new nodes were not created - returns empty list
2387 # @return the list of integer values (can be empty)
2388 def GetLastCreatedNodes(self):
2389 return self.editor.GetLastCreatedNodes()
2391 ## If during the last operation of MeshEditor some elements were
2392 # created this method returns the list of their IDs, \n
2393 # if new elements were not created - returns empty list
2394 # @return the list of integer values (can be empty)
2395 def GetLastCreatedElems(self):
2396 return self.editor.GetLastCreatedElems()
2398 ## The mother class to define algorithm, it is not recommended to use it directly.
2401 class Mesh_Algorithm:
2402 # @class Mesh_Algorithm
2403 # @brief Class Mesh_Algorithm
2405 #def __init__(self,smesh):
2413 ## Finds a hypothesis in the study by its type name and parameters.
2414 # Finds only the hypotheses created in smeshpyD engine.
2415 # @return SMESH.SMESH_Hypothesis
2416 def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
2417 study = smeshpyD.GetCurrentStudy()
2418 #to do: find component by smeshpyD object, not by its data type
2419 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2420 if scomp is not None:
2421 res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
2422 # Check if the root label of the hypotheses exists
2423 if res and hypRoot is not None:
2424 iter = study.NewChildIterator(hypRoot)
2425 # Check all published hypotheses
2427 hypo_so_i = iter.Value()
2428 attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
2429 if attr is not None:
2430 anIOR = attr.Value()
2431 hypo_o_i = salome.orb.string_to_object(anIOR)
2432 if hypo_o_i is not None:
2433 # Check if this is a hypothesis
2434 hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
2435 if hypo_i is not None:
2436 # Check if the hypothesis belongs to current engine
2437 if smeshpyD.GetObjectId(hypo_i) > 0:
2438 # Check if this is the required hypothesis
2439 if hypo_i.GetName() == hypname:
2441 if CompareMethod(hypo_i, args):
2455 ## Finds the algorithm in the study by its type name.
2456 # Finds only the algorithms, which have been created in smeshpyD engine.
2457 # @return SMESH.SMESH_Algo
2458 def FindAlgorithm (self, algoname, smeshpyD):
2459 study = smeshpyD.GetCurrentStudy()
2460 #to do: find component by smeshpyD object, not by its data type
2461 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2462 if scomp is not None:
2463 res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
2464 # Check if the root label of the algorithms exists
2465 if res and hypRoot is not None:
2466 iter = study.NewChildIterator(hypRoot)
2467 # Check all published algorithms
2469 algo_so_i = iter.Value()
2470 attr = algo_so_i.FindAttribute("AttributeIOR")[1]
2471 if attr is not None:
2472 anIOR = attr.Value()
2473 algo_o_i = salome.orb.string_to_object(anIOR)
2474 if algo_o_i is not None:
2475 # Check if this is an algorithm
2476 algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
2477 if algo_i is not None:
2478 # Checks if the algorithm belongs to the current engine
2479 if smeshpyD.GetObjectId(algo_i) > 0:
2480 # Check if this is the required algorithm
2481 if algo_i.GetName() == algoname:
2494 ## If the algorithm is global, returns 0; \n
2495 # else returns the submesh associated to this algorithm.
2496 def GetSubMesh(self):
2499 ## Returns the wrapped mesher.
2500 def GetAlgorithm(self):
2503 ## Gets the list of hypothesis that can be used with this algorithm
2504 def GetCompatibleHypothesis(self):
2507 mylist = self.algo.GetCompatibleHypothesis()
2510 ## Gets the name of the algorithm
2514 ## Sets the name to the algorithm
2515 def SetName(self, name):
2516 SetName(self.algo, name)
2518 ## Gets the id of the algorithm
2520 return self.algo.GetId()
2523 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
2525 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
2526 algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
2528 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
2530 self.Assign(algo, mesh, geom)
2534 def Assign(self, algo, mesh, geom):
2536 raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
2543 name = GetName(geom)
2545 name = mesh.geompyD.SubShapeName(geom, piece)
2546 mesh.geompyD.addToStudyInFather(piece, geom, name)
2547 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
2550 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
2551 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
2553 def CompareHyp (self, hyp, args):
2554 print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
2557 def CompareEqualHyp (self, hyp, args):
2561 def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
2562 UseExisting=0, CompareMethod=""):
2565 if CompareMethod == "": CompareMethod = self.CompareHyp
2566 hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
2569 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
2575 a = a + s + str(args[i])
2579 SetName(hypo, hyp + a)
2581 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
2582 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
2586 # Public class: Mesh_Segment
2587 # --------------------------
2589 ## Class to define a segment 1D algorithm for discretization
2592 class Mesh_Segment(Mesh_Algorithm):
2594 ## Private constructor.
2595 def __init__(self, mesh, geom=0):
2596 Mesh_Algorithm.__init__(self)
2597 self.Create(mesh, geom, "Regular_1D")
2599 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
2600 # @param l for the length of segments that cut an edge
2601 # @param UseExisting if ==true - searches for an existing hypothesis created with
2602 # the same parameters, else (default) - creates a new one
2603 # @param p precision, used for calculation of the number of segments.
2604 # The precision should be a positive, meaningful value within the range [0,1].
2605 # In general, the number of segments is calculated with the formula:
2606 # nb = ceil((edge_length / l) - p)
2607 # Function ceil rounds its argument to the higher integer.
2608 # So, p=0 means rounding of (edge_length / l) to the higher integer,
2609 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
2610 # p=1 means rounding of (edge_length / l) to the lower integer.
2611 # Default value is 1e-07.
2612 # @return an instance of StdMeshers_LocalLength hypothesis
2613 def LocalLength(self, l, UseExisting=0, p=1e-07):
2614 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
2615 CompareMethod=self.CompareLocalLength)
2621 ## Checks if the given "LocalLength" hypothesis has the same parameters as the given arguments
2622 def CompareLocalLength(self, hyp, args):
2623 if IsEqual(hyp.GetLength(), args[0]):
2624 return IsEqual(hyp.GetPrecision(), args[1])
2627 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
2628 # @param n for the number of segments that cut an edge
2629 # @param s for the scale factor (optional)
2630 # @param UseExisting if ==true - searches for an existing hypothesis created with
2631 # the same parameters, else (default) - create a new one
2632 # @return an instance of StdMeshers_NumberOfSegments hypothesis
2633 def NumberOfSegments(self, n, s=[], UseExisting=0):
2635 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
2636 CompareMethod=self.CompareNumberOfSegments)
2638 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
2639 CompareMethod=self.CompareNumberOfSegments)
2640 hyp.SetDistrType( 1 )
2641 hyp.SetScaleFactor(s)
2642 hyp.SetNumberOfSegments(n)
2646 ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
2647 def CompareNumberOfSegments(self, hyp, args):
2648 if hyp.GetNumberOfSegments() == args[0]:
2652 if hyp.GetDistrType() == 1:
2653 if IsEqual(hyp.GetScaleFactor(), args[1]):
2657 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
2658 # @param start defines the length of the first segment
2659 # @param end defines the length of the last segment
2660 # @param UseExisting if ==true - searches for an existing hypothesis created with
2661 # the same parameters, else (default) - creates a new one
2662 # @return an instance of StdMeshers_Arithmetic1D hypothesis
2663 def Arithmetic1D(self, start, end, UseExisting=0):
2664 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
2665 CompareMethod=self.CompareArithmetic1D)
2666 hyp.SetLength(start, 1)
2667 hyp.SetLength(end , 0)
2671 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as the given arguments
2672 def CompareArithmetic1D(self, hyp, args):
2673 if IsEqual(hyp.GetLength(1), args[0]):
2674 if IsEqual(hyp.GetLength(0), args[1]):
2678 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
2679 # @param start defines the length of the first segment
2680 # @param end defines the length of the last segment
2681 # @param UseExisting if ==true - searches for an existing hypothesis created with
2682 # the same parameters, else (default) - creates a new one
2683 # @return an instance of StdMeshers_StartEndLength hypothesis
2684 def StartEndLength(self, start, end, UseExisting=0):
2685 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
2686 CompareMethod=self.CompareStartEndLength)
2687 hyp.SetLength(start, 1)
2688 hyp.SetLength(end , 0)
2691 ## Check if the given "StartEndLength" hypothesis has the same parameters as the given arguments
2692 def CompareStartEndLength(self, hyp, args):
2693 if IsEqual(hyp.GetLength(1), args[0]):
2694 if IsEqual(hyp.GetLength(0), args[1]):
2698 ## Defines "Deflection1D" hypothesis
2699 # @param d for the deflection
2700 # @param UseExisting if ==true - searches for an existing hypothesis created with
2701 # the same parameters, else (default) - create a new one
2702 def Deflection1D(self, d, UseExisting=0):
2703 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
2704 CompareMethod=self.CompareDeflection1D)
2705 hyp.SetDeflection(d)
2708 ## Check if the given "Deflection1D" hypothesis has the same parameters as the given arguments
2709 def CompareDeflection1D(self, hyp, args):
2710 return IsEqual(hyp.GetDeflection(), args[0])
2712 ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
2713 # the opposite side in case of quadrangular faces
2714 def Propagation(self):
2715 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2717 ## Defines "AutomaticLength" hypothesis
2718 # @param fineness for the fineness [0-1]
2719 # @param UseExisting if ==true - searches for an existing hypothesis created with the
2720 # same parameters, else (default) - create a new one
2721 def AutomaticLength(self, fineness=0, UseExisting=0):
2722 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
2723 CompareMethod=self.CompareAutomaticLength)
2724 hyp.SetFineness( fineness )
2727 ## Checks if the given "AutomaticLength" hypothesis has the same parameters as the given arguments
2728 def CompareAutomaticLength(self, hyp, args):
2729 return IsEqual(hyp.GetFineness(), args[0])
2731 ## Defines "SegmentLengthAroundVertex" hypothesis
2732 # @param length for the segment length
2733 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
2734 # Any other integer value means that the hypothesis will be set on the
2735 # whole 1D shape, where Mesh_Segment algorithm is assigned.
2736 # @param UseExisting if ==true - searches for an existing hypothesis created with
2737 # the same parameters, else (default) - creates a new one
2738 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
2740 store_geom = self.geom
2741 if type(vertex) is types.IntType:
2742 if vertex == 0 or vertex == 1:
2743 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
2751 if self.geom is None:
2752 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
2753 name = GetName(self.geom)
2755 piece = self.mesh.geom
2756 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
2757 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
2758 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
2760 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
2762 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
2763 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
2765 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
2766 CompareMethod=self.CompareLengthNearVertex)
2767 self.geom = store_geom
2768 hyp.SetLength( length )
2771 ## Checks if the given "LengthNearVertex" hypothesis has the same parameters as the given arguments
2772 def CompareLengthNearVertex(self, hyp, args):
2773 return IsEqual(hyp.GetLength(), args[0])
2775 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
2776 # If the 2D mesher sees that all boundary edges are quadratic,
2777 # it generates quadratic faces, else it generates linear faces using
2778 # medium nodes as if they are vertices.
2779 # The 3D mesher generates quadratic volumes only if all boundary faces
2780 # are quadratic, else it fails.
2781 def QuadraticMesh(self):
2782 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2785 # Public class: Mesh_CompositeSegment
2786 # --------------------------
2788 ## Defines a segment 1D algorithm for discretization
2790 class Mesh_CompositeSegment(Mesh_Segment):
2792 ## Private constructor.
2793 def __init__(self, mesh, geom=0):
2794 self.Create(mesh, geom, "CompositeSegment_1D")
2797 # Public class: Mesh_Segment_Python
2798 # ---------------------------------
2800 ## Defines a segment 1D algorithm for discretization with python function
2802 class Mesh_Segment_Python(Mesh_Segment):
2804 ## Private constructor.
2805 def __init__(self, mesh, geom=0):
2806 import Python1dPlugin
2807 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
2809 ## Defines "PythonSplit1D" hypothesis
2810 # @param n for the number of segments that cut an edge
2811 # @param func for the python function that calculates the length of all segments
2812 # @param UseExisting if ==true - searches for the existing hypothesis created with
2813 # the same parameters, else (default) - creates a new one
2814 def PythonSplit1D(self, n, func, UseExisting=0):
2815 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
2816 UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
2817 hyp.SetNumberOfSegments(n)
2818 hyp.SetPythonLog10RatioFunction(func)
2821 ## Checks if the given "PythonSplit1D" hypothesis has the same parameters as the given arguments
2822 def ComparePythonSplit1D(self, hyp, args):
2823 #if hyp.GetNumberOfSegments() == args[0]:
2824 # if hyp.GetPythonLog10RatioFunction() == args[1]:
2828 # Public class: Mesh_Triangle
2829 # ---------------------------
2831 ## Defines a triangle 2D algorithm
2833 class Mesh_Triangle(Mesh_Algorithm):
2842 ## Private constructor.
2843 def __init__(self, mesh, algoType, geom=0):
2844 Mesh_Algorithm.__init__(self)
2846 self.algoType = algoType
2847 if algoType == MEFISTO:
2848 self.Create(mesh, geom, "MEFISTO_2D")
2850 elif algoType == BLSURF:
2852 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
2853 self.SetPhysicalMesh()
2854 elif algoType == NETGEN:
2856 print "Warning: NETGENPlugin module unavailable"
2858 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
2860 elif algoType == NETGEN_2D:
2862 print "Warning: NETGENPlugin module unavailable"
2864 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
2867 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
2868 # @param area for the maximum area of each triangle
2869 # @param UseExisting if ==true - searches for an existing hypothesis created with the
2870 # same parameters, else (default) - creates a new one
2872 # Only for algoType == MEFISTO || NETGEN_2D
2873 def MaxElementArea(self, area, UseExisting=0):
2874 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2875 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
2876 CompareMethod=self.CompareMaxElementArea)
2877 hyp.SetMaxElementArea(area)
2879 elif self.algoType == NETGEN:
2880 print "Netgen 1D-2D algo doesn't support this hypothesis"
2883 ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
2884 def CompareMaxElementArea(self, hyp, args):
2885 return IsEqual(hyp.GetMaxElementArea(), args[0])
2887 ## Defines "LengthFromEdges" hypothesis to build triangles
2888 # based on the length of the edges taken from the wire
2890 # Only for algoType == MEFISTO || NETGEN_2D
2891 def LengthFromEdges(self):
2892 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2893 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2895 elif self.algoType == NETGEN:
2896 print "Netgen 1D-2D algo doesn't support this hypothesis"
2899 ## Sets PhysicalMesh
2900 # @param thePhysicalMesh is:
2901 # DefaultSize or Custom
2902 def SetPhysicalMesh(self, thePhysicalMesh=1):
2903 if self.params == 0:
2905 self.params.SetPhysicalMesh(thePhysicalMesh)
2907 ## Sets PhySize flag
2908 def SetPhySize(self, theVal):
2909 if self.params == 0:
2911 self.params.SetPhySize(theVal)
2913 ## Sets GeometricMesh
2914 # @param theGeometricMesh is:
2915 # DefaultGeom or Custom
2916 def SetGeometricMesh(self, theGeometricMesh=0):
2917 if self.params == 0:
2919 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
2920 self.params.SetGeometricMesh(theGeometricMesh)
2922 ## Sets AngleMeshS flag
2923 def SetAngleMeshS(self, theVal=_angleMeshS):
2924 if self.params == 0:
2926 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
2927 self.params.SetAngleMeshS(theVal)
2929 ## Sets Gradation flag
2930 def SetGradation(self, theVal=_gradation):
2931 if self.params == 0:
2933 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
2934 self.params.SetGradation(theVal)
2936 ## Sets QuadAllowed flag
2938 # Only for algoType == NETGEN || NETGEN_2D
2939 def SetQuadAllowed(self, toAllow=True):
2940 if self.algoType == NETGEN_2D:
2941 if toAllow: # add QuadranglePreference
2942 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2943 else: # remove QuadranglePreference
2944 for hyp in self.mesh.GetHypothesisList( self.geom ):
2945 if hyp.GetName() == "QuadranglePreference":
2946 self.mesh.RemoveHypothesis( self.geom, hyp )
2951 if self.params == 0:
2954 self.params.SetQuadAllowed(toAllow)
2957 ## Defines "Netgen 2D Parameters" hypothesis
2959 # Only for algoType == NETGEN
2960 def Parameters(self):
2961 if self.algoType == NETGEN:
2962 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
2963 "libNETGENEngine.so", UseExisting=0)
2965 elif self.algoType == MEFISTO:
2966 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
2968 elif self.algoType == NETGEN_2D:
2969 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
2970 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
2972 elif self.algoType == BLSURF:
2973 self.params = self.Hypothesis("BLSURF_Parameters", [],
2974 "libBLSURFEngine.so", UseExisting=0)
2980 # Only for algoType == NETGEN
2981 def SetMaxSize(self, theSize):
2982 if self.params == 0:
2984 if self.params is not None:
2985 self.params.SetMaxSize(theSize)
2987 ## Sets SecondOrder flag
2989 # Only for algoType == NETGEN
2990 def SetSecondOrder(self, theVal):
2991 if self.params == 0:
2993 if self.params is not None:
2994 self.params.SetSecondOrder(theVal)
2996 ## Sets Optimize flag
2998 # Only for algoType == NETGEN
2999 def SetOptimize(self, theVal):
3000 if self.params == 0:
3002 if self.params is not None:
3003 self.params.SetOptimize(theVal)
3006 # @param theFineness is:
3007 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3009 # Only for algoType == NETGEN
3010 def SetFineness(self, theFineness):
3011 if self.params == 0:
3013 if self.params is not None:
3014 self.params.SetFineness(theFineness)
3018 # Only for algoType == NETGEN
3019 def SetGrowthRate(self, theRate):
3020 if self.params == 0:
3022 if self.params is not None:
3023 self.params.SetGrowthRate(theRate)
3025 ## Sets NbSegPerEdge
3027 # Only for algoType == NETGEN
3028 def SetNbSegPerEdge(self, theVal):
3029 if self.params == 0:
3031 if self.params is not None:
3032 self.params.SetNbSegPerEdge(theVal)
3034 ## Sets NbSegPerRadius
3036 # Only for algoType == NETGEN
3037 def SetNbSegPerRadius(self, theVal):
3038 if self.params == 0:
3040 if self.params is not None:
3041 self.params.SetNbSegPerRadius(theVal)
3043 ## Sets Decimesh flag
3044 def SetDecimesh(self, toAllow=False):
3045 if self.params == 0:
3047 self.params.SetDecimesh(toAllow)
3052 # Public class: Mesh_Quadrangle
3053 # -----------------------------
3055 ## Defines a quadrangle 2D algorithm
3057 class Mesh_Quadrangle(Mesh_Algorithm):
3059 ## Private constructor.
3060 def __init__(self, mesh, geom=0):
3061 Mesh_Algorithm.__init__(self)
3062 self.Create(mesh, geom, "Quadrangle_2D")
3064 ## Defines "QuadranglePreference" hypothesis, forcing construction
3065 # of quadrangles if the number of nodes on the opposite edges is not the same
3066 # while the total number of nodes on edges is even
3067 def QuadranglePreference(self):
3068 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
3069 CompareMethod=self.CompareEqualHyp)
3072 # Public class: Mesh_Tetrahedron
3073 # ------------------------------
3075 ## Defines a tetrahedron 3D algorithm
3077 class Mesh_Tetrahedron(Mesh_Algorithm):
3082 ## Private constructor.
3083 def __init__(self, mesh, algoType, geom=0):
3084 Mesh_Algorithm.__init__(self)
3086 if algoType == NETGEN:
3087 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
3090 elif algoType == GHS3D:
3092 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
3095 elif algoType == FULL_NETGEN:
3097 print "Warning: NETGENPlugin module has not been imported."
3098 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3101 self.algoType = algoType
3103 ## Defines "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedron
3104 # @param vol for the maximum volume of each tetrahedron
3105 # @param UseExisting if ==true - searches for the existing hypothesis created with
3106 # the same parameters, else (default) - creates a new one
3107 def MaxElementVolume(self, vol, UseExisting=0):
3108 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
3109 CompareMethod=self.CompareMaxElementVolume)
3110 hyp.SetMaxElementVolume(vol)
3113 ## Checks if the given "MaxElementVolume" hypothesis has the same parameters as the given arguments
3114 def CompareMaxElementVolume(self, hyp, args):
3115 return IsEqual(hyp.GetMaxElementVolume(), args[0])
3117 ## Defines "Netgen 3D Parameters" hypothesis
3118 def Parameters(self):
3119 if (self.algoType == FULL_NETGEN):
3120 self.params = self.Hypothesis("NETGEN_Parameters", [],
3121 "libNETGENEngine.so", UseExisting=0)
3124 print "Algo doesn't support this hypothesis"
3128 def SetMaxSize(self, theSize):
3129 if self.params == 0:
3131 self.params.SetMaxSize(theSize)
3133 ## Sets SecondOrder flag
3134 def SetSecondOrder(self, theVal):
3135 if self.params == 0:
3137 self.params.SetSecondOrder(theVal)
3139 ## Sets Optimize flag
3140 def SetOptimize(self, theVal):
3141 if self.params == 0:
3143 self.params.SetOptimize(theVal)
3146 # @param theFineness is:
3147 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3148 def SetFineness(self, theFineness):
3149 if self.params == 0:
3151 self.params.SetFineness(theFineness)
3154 def SetGrowthRate(self, theRate):
3155 if self.params == 0:
3157 self.params.SetGrowthRate(theRate)
3159 ## Sets NbSegPerEdge
3160 def SetNbSegPerEdge(self, theVal):
3161 if self.params == 0:
3163 self.params.SetNbSegPerEdge(theVal)
3165 ## Sets NbSegPerRadius
3166 def SetNbSegPerRadius(self, theVal):
3167 if self.params == 0:
3169 self.params.SetNbSegPerRadius(theVal)
3171 # Public class: Mesh_Hexahedron
3172 # ------------------------------
3174 ## Defines a hexahedron 3D algorithm
3176 class Mesh_Hexahedron(Mesh_Algorithm):
3181 ## Private constructor.
3182 def __init__(self, mesh, algoType=Hexa, geom=0):
3183 Mesh_Algorithm.__init__(self)
3185 self.algoType = algoType
3187 if algoType == Hexa:
3188 self.Create(mesh, geom, "Hexa_3D")
3191 elif algoType == Hexotic:
3192 import HexoticPlugin
3193 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
3196 ## Defines "MinMaxQuad" hypothesis to give three hexotic parameters
3197 def MinMaxQuad(self, min=3, max=8, quad=True):
3198 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
3200 self.params.SetHexesMinLevel(min)
3201 self.params.SetHexesMaxLevel(max)
3202 self.params.SetHexoticQuadrangles(quad)
3205 # Deprecated, only for compatibility!
3206 # Public class: Mesh_Netgen
3207 # ------------------------------
3209 ## Defines a NETGEN-based 2D or 3D algorithm
3210 # that needs no discrete boundary (i.e. independent)
3212 # This class is deprecated, only for compatibility!
3215 class Mesh_Netgen(Mesh_Algorithm):
3219 ## Private constructor.
3220 def __init__(self, mesh, is3D, geom=0):
3221 Mesh_Algorithm.__init__(self)
3224 print "Warning: NETGENPlugin module has not been imported."
3228 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3232 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3235 ## Defines the hypothesis containing parameters of the algorithm
3236 def Parameters(self):
3238 hyp = self.Hypothesis("NETGEN_Parameters", [],
3239 "libNETGENEngine.so", UseExisting=0)
3241 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
3242 "libNETGENEngine.so", UseExisting=0)
3245 # Public class: Mesh_Projection1D
3246 # ------------------------------
3248 ## Defines a projection 1D algorithm
3250 class Mesh_Projection1D(Mesh_Algorithm):
3252 ## Private constructor.
3253 def __init__(self, mesh, geom=0):
3254 Mesh_Algorithm.__init__(self)
3255 self.Create(mesh, geom, "Projection_1D")
3257 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
3258 # a mesh pattern is taken, and, optionally, the association of vertices
3259 # between the source edge and a target edge (to which a hypothesis is assigned)
3260 # @param edge from which nodes distribution is taken
3261 # @param mesh from which nodes distribution is taken (optional)
3262 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
3263 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
3264 # to associate with \a srcV (optional)
3265 # @param UseExisting if ==true - searches for the existing hypothesis created with
3266 # the same parameters, else (default) - creates a new one
3267 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
3268 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
3270 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
3271 hyp.SetSourceEdge( edge )
3272 if not mesh is None and isinstance(mesh, Mesh):
3273 mesh = mesh.GetMesh()
3274 hyp.SetSourceMesh( mesh )
3275 hyp.SetVertexAssociation( srcV, tgtV )
3278 ## Checks if the given "SourceEdge" hypothesis has the same parameters as the given arguments
3279 #def CompareSourceEdge(self, hyp, args):
3280 # # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
3284 # Public class: Mesh_Projection2D
3285 # ------------------------------
3287 ## Defines a projection 2D algorithm
3289 class Mesh_Projection2D(Mesh_Algorithm):
3291 ## Private constructor.
3292 def __init__(self, mesh, geom=0):
3293 Mesh_Algorithm.__init__(self)
3294 self.Create(mesh, geom, "Projection_2D")
3296 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
3297 # a mesh pattern is taken, and, optionally, the association of vertices
3298 # between the source face and the target face (to which a hypothesis is assigned)
3299 # @param face from which the mesh pattern is taken
3300 # @param mesh from which the mesh pattern is taken (optional)
3301 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
3302 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
3303 # to associate with \a srcV1 (optional)
3304 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
3305 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
3306 # to associate with \a srcV2 (optional)
3307 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
3308 # the same parameters, else (default) - forces the creation a new one
3310 # Note: all association vertices must belong to one edge of a face
3311 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
3312 srcV2=None, tgtV2=None, UseExisting=0):
3313 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
3315 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
3316 hyp.SetSourceFace( face )
3317 if not mesh is None and isinstance(mesh, Mesh):
3318 mesh = mesh.GetMesh()
3319 hyp.SetSourceMesh( mesh )
3320 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3323 ## Checks if the given "SourceFace" hypothesis has the same parameters as the given arguments
3324 #def CompareSourceFace(self, hyp, args):
3325 # # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
3328 # Public class: Mesh_Projection3D
3329 # ------------------------------
3331 ## Defines a projection 3D algorithm
3333 class Mesh_Projection3D(Mesh_Algorithm):
3335 ## Private constructor.
3336 def __init__(self, mesh, geom=0):
3337 Mesh_Algorithm.__init__(self)
3338 self.Create(mesh, geom, "Projection_3D")
3340 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
3341 # the mesh pattern is taken, and, optionally, the association of vertices
3342 # between the source and the target solid (to which a hipothesis is assigned)
3343 # @param solid from where the mesh pattern is taken
3344 # @param mesh from where the mesh pattern is taken (optional)
3345 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
3346 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
3347 # to associate with \a srcV1 (optional)
3348 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
3349 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
3350 # to associate with \a srcV2 (optional)
3351 # @param UseExisting - if ==true - searches for the existing hypothesis created with
3352 # the same parameters, else (default) - creates a new one
3354 # Note: association vertices must belong to one edge of a solid
3355 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
3356 srcV2=0, tgtV2=0, UseExisting=0):
3357 hyp = self.Hypothesis("ProjectionSource3D",
3358 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
3360 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
3361 hyp.SetSource3DShape( solid )
3362 if not mesh is None and isinstance(mesh, Mesh):
3363 mesh = mesh.GetMesh()
3364 hyp.SetSourceMesh( mesh )
3365 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3368 ## Checks if the given "SourceShape3D" hypothesis has the same parameters as given arguments
3369 #def CompareSourceShape3D(self, hyp, args):
3370 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
3374 # Public class: Mesh_Prism
3375 # ------------------------
3377 ## Defines a 3D extrusion algorithm
3379 class Mesh_Prism3D(Mesh_Algorithm):
3381 ## Private constructor.
3382 def __init__(self, mesh, geom=0):
3383 Mesh_Algorithm.__init__(self)
3384 self.Create(mesh, geom, "Prism_3D")
3386 # Public class: Mesh_RadialPrism
3387 # -------------------------------
3389 ## Defines a Radial Prism 3D algorithm
3391 class Mesh_RadialPrism3D(Mesh_Algorithm):
3393 ## Private constructor.
3394 def __init__(self, mesh, geom=0):
3395 Mesh_Algorithm.__init__(self)
3396 self.Create(mesh, geom, "RadialPrism_3D")
3398 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
3399 self.nbLayers = None
3401 ## Return 3D hypothesis holding the 1D one
3402 def Get3DHypothesis(self):
3403 return self.distribHyp
3405 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
3406 # hypothesis. Returns the created hypothesis
3407 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
3408 #print "OwnHypothesis",hypType
3409 if not self.nbLayers is None:
3410 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
3411 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
3412 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
3413 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
3414 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
3415 self.distribHyp.SetLayerDistribution( hyp )
3418 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
3419 # prisms to build between the inner and outer shells
3420 # @param UseExisting if ==true - searches for the existing hypothesis created with
3421 # the same parameters, else (default) - creates a new one
3422 def NumberOfLayers(self, n, UseExisting=0):
3423 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
3424 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
3425 CompareMethod=self.CompareNumberOfLayers)
3426 self.nbLayers.SetNumberOfLayers( n )
3427 return self.nbLayers
3429 ## Checks if the given "NumberOfLayers" hypothesis has the same parameters as the given arguments
3430 def CompareNumberOfLayers(self, hyp, args):
3431 return IsEqual(hyp.GetNumberOfLayers(), args[0])
3433 ## Defines "LocalLength" hypothesis, specifying the segment length
3434 # to build between the inner and the outer shells
3435 # @param l the length of segments
3436 # @param p the precision of rounding
3437 def LocalLength(self, l, p=1e-07):
3438 hyp = self.OwnHypothesis("LocalLength", [l,p])
3443 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
3444 # prisms to build between the inner and the outer shells.
3445 # @param n the number of layers
3446 # @param s the scale factor (optional)
3447 def NumberOfSegments(self, n, s=[]):
3449 hyp = self.OwnHypothesis("NumberOfSegments", [n])
3451 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
3452 hyp.SetDistrType( 1 )
3453 hyp.SetScaleFactor(s)
3454 hyp.SetNumberOfSegments(n)
3457 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
3458 # to build between the inner and the outer shells with a length that changes in arithmetic progression
3459 # @param start the length of the first segment
3460 # @param end the length of the last segment
3461 def Arithmetic1D(self, start, end ):
3462 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
3463 hyp.SetLength(start, 1)
3464 hyp.SetLength(end , 0)
3467 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
3468 # to build between the inner and the outer shells as geometric length increasing
3469 # @param start for the length of the first segment
3470 # @param end for the length of the last segment
3471 def StartEndLength(self, start, end):
3472 hyp = self.OwnHypothesis("StartEndLength", [start, end])
3473 hyp.SetLength(start, 1)
3474 hyp.SetLength(end , 0)
3477 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
3478 # to build between the inner and outer shells
3479 # @param fineness defines the quality of the mesh within the range [0-1]
3480 def AutomaticLength(self, fineness=0):
3481 hyp = self.OwnHypothesis("AutomaticLength")
3482 hyp.SetFineness( fineness )
3485 # Private class: Mesh_UseExisting
3486 # -------------------------------
3487 class Mesh_UseExisting(Mesh_Algorithm):
3489 def __init__(self, dim, mesh, geom=0):
3491 self.Create(mesh, geom, "UseExisting_1D")
3493 self.Create(mesh, geom, "UseExisting_2D")