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 look at smeshDC::smeshDC documentation for general services of smesh package.
31 # You can find the smeshDC::smeshDC documentation also by the first
32 # item in the Data Structures list on this page.
33 # See also the list of Data Structures and the list of Functions
34 # for other classes and methods of smesh python interface.
40 import SMESH # necessary for back compatibility
47 # import NETGENPlugin module if possible
66 NETGEN_1D2D3D = FULL_NETGEN
67 NETGEN_FULL = FULL_NETGEN
72 # MirrorType enumeration
73 POINT = SMESH_MeshEditor.POINT
74 AXIS = SMESH_MeshEditor.AXIS
75 PLANE = SMESH_MeshEditor.PLANE
77 # Smooth_Method enumeration
78 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
79 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
81 # Fineness enumeration(for NETGEN)
89 PrecisionConfusion = 1e-07
91 def IsEqual(val1, val2, tol=PrecisionConfusion):
92 if abs(val1 - val2) < tol:
100 ior = salome.orb.object_to_string(obj)
101 sobj = salome.myStudy.FindObjectIOR(ior)
105 attr = sobj.FindAttribute("AttributeName")[1]
108 ## Sets name to object
109 def SetName(obj, name):
110 ior = salome.orb.object_to_string(obj)
111 sobj = salome.myStudy.FindObjectIOR(ior)
113 attr = sobj.FindAttribute("AttributeName")[1]
116 ## Print error message if a hypothesis was not assigned.
117 def TreatHypoStatus(status, hypName, geomName, isAlgo):
119 hypType = "algorithm"
121 hypType = "hypothesis"
123 if status == HYP_UNKNOWN_FATAL :
124 reason = "for unknown reason"
125 elif status == HYP_INCOMPATIBLE :
126 reason = "this hypothesis mismatches algorithm"
127 elif status == HYP_NOTCONFORM :
128 reason = "not conform mesh would be built"
129 elif status == HYP_ALREADY_EXIST :
130 reason = hypType + " of the same dimension already assigned to this shape"
131 elif status == HYP_BAD_DIM :
132 reason = hypType + " mismatches shape"
133 elif status == HYP_CONCURENT :
134 reason = "there are concurrent hypotheses on sub-shapes"
135 elif status == HYP_BAD_SUBSHAPE :
136 reason = "shape is neither the main one, nor its subshape, nor a valid group"
137 elif status == HYP_BAD_GEOMETRY:
138 reason = "geometry mismatches algorithm's expectation"
139 elif status == HYP_HIDDEN_ALGO:
140 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
141 elif status == HYP_HIDING_ALGO:
142 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
145 hypName = '"' + hypName + '"'
146 geomName= '"' + geomName+ '"'
147 if status < HYP_UNKNOWN_FATAL:
148 print hypName, "was assigned to", geomName,"but", reason
150 print hypName, "was not assigned to",geomName,":", reason
153 ## Convert angle in degrees to radians
154 def DegreesToRadians(AngleInDegrees):
156 return AngleInDegrees * pi / 180.0
158 ## Methods of package smesh.py: general services of MESH component.
160 # This class has been designed to provide general services of the 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 mesh from a file,
163 # and also to create patterns and filtering criteria.
164 class smeshDC(SMESH._objref_SMESH_Gen):
166 ## To set current study and Geometry component
167 def init_smesh(self,theStudy,geompyD):
169 self.SetGeomEngine(geompyD)
170 self.SetCurrentStudy(theStudy)
172 ## Create an empty Mesh. This mesh can have underlying geometry.
173 # @param obj Geometrical object to build the mesh on. If not defined,
174 # the mesh will not have underlying geometry.
175 # @param name A name for the new mesh.
176 # @return instance of Mesh class.
177 def Mesh(self, obj=0, name=0):
178 return Mesh(self,self.geompyD,obj,name)
180 ## Returns long value from enumeration
181 # To be used for SMESH.FunctorType enumeration
182 def EnumToLong(self,theItem):
185 ## Get PointStruct from vertex
186 # @param theVertex is 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 ## Get DirStruct from vector
193 # @param theVector is 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 ## Make DirStruct from a triplet
207 # @param x,y,z are 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 is 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 ## Set the current mode
242 def SetEmbeddedMode( self,theMode ):
243 #self.SetEmbeddedMode(theMode)
244 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
246 ## Get the current mode
247 def IsEmbeddedMode(self):
248 #return self.IsEmbeddedMode()
249 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
251 ## Set the current study
252 def SetCurrentStudy( self, theStudy ):
253 #self.SetCurrentStudy(theStudy)
254 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
256 ## Get the current study
257 def GetCurrentStudy(self):
258 #return self.GetCurrentStudy()
259 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
261 ## Create Mesh object importing data from 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 ## Create Mesh object(s) importing data from 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 ## Create Mesh object importing data from 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 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 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 given parameters
316 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
317 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
318 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
319 # @param Treshold is threshold value (range of ids as string, shape, numeric)
320 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
321 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
322 # FT_Undefined(must be for the last criterion in 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]:
351 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
352 aCriterion.ThresholdStr = GetName(aTreshold)
353 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
355 print "Error: Treshold should be a shape."
357 elif CritType == FT_RangeOfIds:
359 if isinstance(aTreshold, str):
360 aCriterion.ThresholdStr = aTreshold
362 print "Error: Treshold should be a string."
364 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
365 # Here we do not need treshold
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: 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 filter by given parameters of criterion
394 # @param elementType is the type of elements in the group
395 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
396 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
397 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
398 # @param UnaryOp is 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 numerical functor by its type
414 # @param theCrierion is 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 #Register the new proxy for SMESH_Gen
447 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
453 ## Class to define a mesh
455 # This class allows to define and manage a mesh.
456 # It has a set of methods to build a mesh on the given geometry, including definition of sub-meshes.
457 # Also it has methods to define groups of mesh elements, to modify a mesh (by addition of
458 # new nodes and elements and by changind of existing entities), to take information
459 # about a mesh and to export a mesh into different formats.
468 # Creates mesh on the shape \a obj (or the empty mesh if obj is equal to 0),
469 # sets GUI name of this mesh to \a name.
470 # @param obj Shape to be meshed or SMESH_Mesh object
471 # @param name Study name of the mesh
472 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
473 self.smeshpyD=smeshpyD
478 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
480 self.mesh = self.smeshpyD.CreateMesh(self.geom)
481 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
484 self.mesh = self.smeshpyD.CreateEmptyMesh()
486 SetName(self.mesh, name)
488 SetName(self.mesh, GetName(obj))
490 self.editor = self.mesh.GetMeshEditor()
492 ## Method that inits the Mesh object from instance of SMESH_Mesh interface
493 # @param theMesh is SMESH_Mesh object
494 def SetMesh(self, theMesh):
496 self.geom = self.mesh.GetShapeToMesh()
498 ## Method that returns the mesh, that is instance of SMESH_Mesh interface
499 # @return SMESH_Mesh object
504 # @return name of the mesh as a string
506 name = GetName(self.GetMesh())
510 # @param name a new name for the mesh
511 def SetName(self, name):
512 SetName(self.GetMesh(), name)
514 ## Get the subMesh object associated to \a theSubObject geometrical object.
515 # The subMesh object gives access to nodes and elements IDs.
516 # @param theSubObject A geometrical object (shape)
517 # @return object of type SMESH_SubMesh, representing part of mesh, which lays on the given shape
518 def GetSubMesh(self, theSubObject, name):
519 submesh = self.mesh.GetSubMesh(theSubObject, name)
522 ## Method that returns the shape associated to the mesh
523 # @return GEOM_Object
527 ## Method that associates given shape to the mesh(entails the mesh recreation)
528 # @param geom shape to be meshed (GEOM_Object)
529 def SetShape(self, geom):
530 self.mesh = self.smeshpyD.CreateMesh(geom)
532 ## Return true if hypotheses are defined well
533 # @param theSubObject subshape of a mesh shape
534 # @return True or False
535 def IsReadyToCompute(self, theSubObject):
536 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
538 ## Return errors of hypotheses definition.
539 # Errors list is empty if everything is OK.
540 # @param theSubObject subshape of a mesh shape
541 # @return a list of errors
542 def GetAlgoState(self, theSubObject):
543 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
545 ## Return geometrical object the given element is built on.
546 # The returned geometrical object, if not nil, is either found in the
547 # study or is published by this method with the given name
548 # @param theElementID an id of the mesh element
549 # @param theGeomName user defined name of geometrical object
550 # @return GEOM::GEOM_Object instance
551 def GetGeometryByMeshElement(self, theElementID, theGeomName):
552 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
554 ## Returns mesh dimension depending on that of the underlying shape
555 # @return mesh dimension as an integer value [0,3]
556 def MeshDimension(self):
557 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
558 if len( shells ) > 0 :
560 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
562 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
568 ## Creates a segment discretization 1D algorithm.
569 # If the optional \a algo parameter is not set, this algorithm is REGULAR.
570 # \n If the optional \a geom parameter is not set, this algorithm is global.
571 # Otherwise, this algorithm define a submesh based on \a geom subshape.
572 # @param algo type of desired algorithm. Possible values are:
574 # - smesh.PYTHON for discretization via python function,
575 # - smesh.COMPOSITE for meshing a set of edges on one face side as a whole.
576 # @param geom If defined, subshape to be meshed
577 # @return instance of Mesh_Segment or Mesh_Segment_Python, or Mesh_CompositeSegment class
578 def Segment(self, algo=REGULAR, geom=0):
579 ## if Segment(geom) is called by mistake
580 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
581 algo, geom = geom, algo
582 if not algo: algo = REGULAR
585 return Mesh_Segment(self, geom)
587 return Mesh_Segment_Python(self, geom)
588 elif algo == COMPOSITE:
589 return Mesh_CompositeSegment(self, geom)
591 return Mesh_Segment(self, geom)
593 ## Enable creation of nodes and segments usable by 2D algoritms.
594 # Added nodes and segments must be bound to edges and vertices by
595 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
596 # If the optional \a geom parameter is not sets, this algorithm is global.
597 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
598 # @param geom subshape to be manually meshed
599 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
600 def UseExistingSegments(self, geom=0):
601 algo = Mesh_UseExisting(1,self,geom)
602 return algo.GetAlgorithm()
604 ## Enable creation of nodes and faces usable by 3D algoritms.
605 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
606 # and SetMeshElementOnShape()
607 # If the optional \a geom parameter is not sets, this algorithm is global.
608 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
609 # @param geom subshape to be manually meshed
610 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
611 def UseExistingFaces(self, geom=0):
612 algo = Mesh_UseExisting(2,self,geom)
613 return algo.GetAlgorithm()
615 ## Creates a triangle 2D algorithm for faces.
616 # If the optional \a geom parameter is not sets, this algorithm is global.
617 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
618 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D || smesh.BLSURF
619 # @param geom If defined, subshape to be meshed (GEOM_Object)
620 # @return an instance of Mesh_Triangle algorithm
621 def Triangle(self, algo=MEFISTO, geom=0):
622 ## if Triangle(geom) is called by mistake
623 if (isinstance(algo, geompyDC.GEOM._objref_GEOM_Object)):
627 return Mesh_Triangle(self, algo, geom)
629 ## Creates a quadrangle 2D algorithm for faces.
630 # If the optional \a geom parameter is not sets, this algorithm is global.
631 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
632 # @param geom If defined, subshape to be meshed (GEOM_Object)
633 # @return an instance of Mesh_Quadrangle algorithm
634 def Quadrangle(self, geom=0):
635 return Mesh_Quadrangle(self, geom)
637 ## Creates a tetrahedron 3D algorithm for solids.
638 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
639 # If the optional \a geom parameter is not sets, this algorithm is global.
640 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
641 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
642 # @param geom If defined, subshape to be meshed (GEOM_Object)
643 # @return an instance of Mesh_Tetrahedron algorithm
644 def Tetrahedron(self, algo=NETGEN, geom=0):
645 ## if Tetrahedron(geom) is called by mistake
646 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
647 algo, geom = geom, algo
648 if not algo: algo = NETGEN
650 return Mesh_Tetrahedron(self, algo, geom)
652 ## Creates a hexahedron 3D algorithm for solids.
653 # If the optional \a geom parameter is not sets, this algorithm is global.
654 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
655 # @param algo possible values are: smesh.Hexa, smesh.Hexotic
656 # @param geom If defined, subshape to be meshed (GEOM_Object)
657 # @return an instance of Mesh_Hexahedron algorithm
658 def Hexahedron(self, algo=Hexa, geom=0):
659 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
660 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
661 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
662 elif geom == 0: algo, geom = Hexa, algo
663 return Mesh_Hexahedron(self, algo, geom)
665 ## Deprecated, only for compatibility!
666 # @return an instance of Mesh_Netgen algorithm
667 def Netgen(self, is3D, geom=0):
668 return Mesh_Netgen(self, is3D, geom)
670 ## Creates a projection 1D algorithm for edges.
671 # If the optional \a geom parameter is not sets, this algorithm is global.
672 # Otherwise, this algorithm define a submesh based on \a geom subshape.
673 # @param geom If defined, subshape to be meshed
674 # @return an instance of Mesh_Projection1D algorithm
675 def Projection1D(self, geom=0):
676 return Mesh_Projection1D(self, geom)
678 ## Creates a projection 2D algorithm for faces.
679 # If the optional \a geom parameter is not sets, this algorithm is global.
680 # Otherwise, this algorithm define a submesh based on \a geom subshape.
681 # @param geom If defined, subshape to be meshed
682 # @return an instance of Mesh_Projection2D algorithm
683 def Projection2D(self, geom=0):
684 return Mesh_Projection2D(self, geom)
686 ## Creates a projection 3D algorithm for solids.
687 # If the optional \a geom parameter is not sets, this algorithm is global.
688 # Otherwise, this algorithm define a submesh based on \a geom subshape.
689 # @param geom If defined, subshape to be meshed
690 # @return an instance of Mesh_Projection3D algorithm
691 def Projection3D(self, geom=0):
692 return Mesh_Projection3D(self, geom)
694 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
695 # If the optional \a geom parameter is not sets, this algorithm is global.
696 # Otherwise, this algorithm define a submesh based on \a geom subshape.
697 # @param geom If defined, subshape to be meshed
698 # @return an instance of Mesh_Prism3D or Mesh_RadialPrism3D algorithm
699 def Prism(self, geom=0):
703 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
704 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
705 if nbSolids == 0 or nbSolids == nbShells:
706 return Mesh_Prism3D(self, geom)
707 return Mesh_RadialPrism3D(self, geom)
709 ## Compute the mesh and return the status of the computation
710 # @return True or False
711 def Compute(self, geom=0):
712 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
714 print "Compute impossible: mesh is not constructed on geom shape."
720 ok = self.smeshpyD.Compute(self.mesh, geom)
721 except SALOME.SALOME_Exception, ex:
722 print "Mesh computation failed, exception caught:"
723 print " ", ex.details.text
726 print "Mesh computation failed, exception caught:"
727 traceback.print_exc()
729 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
740 reason = '%s %sD algorithm is missing' % (glob, dim)
741 elif err.state == HYP_MISSING:
742 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
743 % (glob, dim, name, dim))
744 elif err.state == HYP_NOTCONFORM:
745 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
746 elif err.state == HYP_BAD_PARAMETER:
747 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
748 % ( glob, dim, name ))
749 elif err.state == HYP_BAD_GEOMETRY:
750 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
751 'its expectation' % ( glob, dim, name ))
753 reason = "For unknown reason."+\
754 " Revise Mesh.Compute() implementation in smeshDC.py!"
762 print '"' + GetName(self.mesh) + '"',"has not been computed:"
765 print '"' + GetName(self.mesh) + '"',"has not been computed."
768 if salome.sg.hasDesktop():
769 smeshgui = salome.ImportComponentGUI("SMESH")
770 smeshgui.Init(salome.myStudyId)
771 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
772 salome.sg.updateObjBrowser(1)
776 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
777 # The parameter \a fineness [0,-1] defines mesh fineness
778 # @return True or False
779 def AutomaticTetrahedralization(self, fineness=0):
780 dim = self.MeshDimension()
782 self.RemoveGlobalHypotheses()
783 self.Segment().AutomaticLength(fineness)
785 self.Triangle().LengthFromEdges()
788 self.Tetrahedron(NETGEN)
790 return self.Compute()
792 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
793 # The parameter \a fineness [0,-1] defines mesh fineness
794 # @return True or False
795 def AutomaticHexahedralization(self, fineness=0):
796 dim = self.MeshDimension()
798 self.RemoveGlobalHypotheses()
799 self.Segment().AutomaticLength(fineness)
806 return self.Compute()
809 # @param hyp is a hypothesis to assign
810 # @param geom is subhape of mesh geometry
811 # @return SMESH.Hypothesis_Status
812 def AddHypothesis(self, hyp, geom=0):
813 if isinstance( hyp, Mesh_Algorithm ):
814 hyp = hyp.GetAlgorithm()
819 status = self.mesh.AddHypothesis(geom, hyp)
820 isAlgo = hyp._narrow( SMESH_Algo )
821 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
824 ## Unassign hypothesis
825 # @param hyp is a hypothesis to unassign
826 # @param geom is subhape of mesh geometry
827 # @return SMESH.Hypothesis_Status
828 def RemoveHypothesis(self, hyp, geom=0):
829 if isinstance( hyp, Mesh_Algorithm ):
830 hyp = hyp.GetAlgorithm()
835 status = self.mesh.RemoveHypothesis(geom, hyp)
838 ## Get the list of hypothesis added on a geom
839 # @param geom is subhape of mesh geometry
840 # @return sequence of SMESH_Hypothesis
841 def GetHypothesisList(self, geom):
842 return self.mesh.GetHypothesisList( geom )
844 ## Removes all global hypotheses
845 def RemoveGlobalHypotheses(self):
846 current_hyps = self.mesh.GetHypothesisList( self.geom )
847 for hyp in current_hyps:
848 self.mesh.RemoveHypothesis( self.geom, hyp )
852 ## Create a mesh group based on geometric object \a grp
853 # and give a \a name, \n if this parameter is not defined
854 # the name is the same as the geometric group name \n
855 # Note: Works like GroupOnGeom().
856 # @param grp is a geometric group, a vertex, an edge, a face or a solid
857 # @param name is the name of the mesh group
858 # @return SMESH_GroupOnGeom
859 def Group(self, grp, name=""):
860 return self.GroupOnGeom(grp, name)
862 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
863 # Export the mesh in a file with the MED format and choice the \a version of MED format
864 # @param f is the file name
865 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
866 def ExportToMED(self, f, version, opt=0):
867 self.mesh.ExportToMED(f, opt, version)
869 ## Export the mesh in a file with the MED format
870 # @param f is the file name
871 # @param auto_groups boolean parameter for creating/not creating
872 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
873 # the typical use is auto_groups=false.
874 # @param version MED format version(MED_V2_1 or MED_V2_2)
875 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
876 self.mesh.ExportToMED(f, auto_groups, version)
878 ## Export the mesh in a file with the DAT format
879 # @param f is the file name
880 def ExportDAT(self, f):
881 self.mesh.ExportDAT(f)
883 ## Export the mesh in a file with the UNV format
884 # @param f is the file name
885 def ExportUNV(self, f):
886 self.mesh.ExportUNV(f)
888 ## Export the mesh in a file with the STL format
889 # @param f is the file name
890 # @param ascii defined the kind of file contents
891 def ExportSTL(self, f, ascii=1):
892 self.mesh.ExportSTL(f, ascii)
895 # Operations with groups:
896 # ----------------------
898 ## Creates an empty mesh group
899 # @param elementType is the type of elements in the group
900 # @param name is the name of the mesh group
901 # @return SMESH_Group
902 def CreateEmptyGroup(self, elementType, name):
903 return self.mesh.CreateGroup(elementType, name)
905 ## Creates a mesh group based on geometric object \a grp
906 # and give a \a name, \n if this parameter is not defined
907 # the name is the same as the geometric group name
908 # @param grp is a geometric group, a vertex, an edge, a face or a solid
909 # @param name is the name of the mesh group
910 # @return SMESH_GroupOnGeom
911 def GroupOnGeom(self, grp, name="", typ=None):
916 tgeo = str(grp.GetShapeType())
923 elif tgeo == "SOLID":
925 elif tgeo == "SHELL":
927 elif tgeo == "COMPOUND":
928 if len( self.geompyD.GetObjectIDs( grp )) == 0:
929 print "Mesh.Group: empty geometric group", GetName( grp )
931 tgeo = self.geompyD.GetType(grp)
932 if tgeo == geompyDC.ShapeType["VERTEX"]:
934 elif tgeo == geompyDC.ShapeType["EDGE"]:
936 elif tgeo == geompyDC.ShapeType["FACE"]:
938 elif tgeo == geompyDC.ShapeType["SOLID"]:
942 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
945 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
947 ## Create a mesh group by the given ids of elements
948 # @param groupName is the name of the mesh group
949 # @param elementType is the type of elements in the group
950 # @param elemIDs is the list of ids
951 # @return SMESH_Group
952 def MakeGroupByIds(self, groupName, elementType, elemIDs):
953 group = self.mesh.CreateGroup(elementType, groupName)
957 ## Create a mesh group by the given conditions
958 # @param groupName is the name of the mesh group
959 # @param elementType is the type of elements in the group
960 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
961 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
962 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
963 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
964 # @return SMESH_Group
968 CritType=FT_Undefined,
971 UnaryOp=FT_Undefined):
972 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
973 group = self.MakeGroupByCriterion(groupName, aCriterion)
976 ## Create a mesh group by the given criterion
977 # @param groupName is the name of the mesh group
978 # @param Criterion is the instance of Criterion class
979 # @return SMESH_Group
980 def MakeGroupByCriterion(self, groupName, Criterion):
981 aFilterMgr = self.smeshpyD.CreateFilterManager()
982 aFilter = aFilterMgr.CreateFilter()
984 aCriteria.append(Criterion)
985 aFilter.SetCriteria(aCriteria)
986 group = self.MakeGroupByFilter(groupName, aFilter)
989 ## Create a mesh group by the given criteria(list of criterions)
990 # @param groupName is the name of the mesh group
991 # @param Criteria is the list of criterions
992 # @return SMESH_Group
993 def MakeGroupByCriteria(self, groupName, theCriteria):
994 aFilterMgr = self.smeshpyD.CreateFilterManager()
995 aFilter = aFilterMgr.CreateFilter()
996 aFilter.SetCriteria(theCriteria)
997 group = self.MakeGroupByFilter(groupName, aFilter)
1000 ## Create a mesh group by the given filter
1001 # @param groupName is the name of the mesh group
1002 # @param Criterion is the instance of Filter class
1003 # @return SMESH_Group
1004 def MakeGroupByFilter(self, groupName, theFilter):
1005 anIds = theFilter.GetElementsId(self.mesh)
1006 anElemType = theFilter.GetElementType()
1007 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1010 ## Pass mesh elements through the given filter and return ids
1011 # @param theFilter is SMESH_Filter
1012 # @return list of ids
1013 def GetIdsFromFilter(self, theFilter):
1014 return theFilter.GetElementsId(self.mesh)
1016 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1017 # Returns list of special structures(borders).
1018 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1019 def GetFreeBorders(self):
1020 aFilterMgr = self.smeshpyD.CreateFilterManager()
1021 aPredicate = aFilterMgr.CreateFreeEdges()
1022 aPredicate.SetMesh(self.mesh)
1023 aBorders = aPredicate.GetBorders()
1027 def RemoveGroup(self, group):
1028 self.mesh.RemoveGroup(group)
1030 ## Remove group with its contents
1031 def RemoveGroupWithContents(self, group):
1032 self.mesh.RemoveGroupWithContents(group)
1034 ## Get the list of groups existing in the mesh
1035 # @return sequence of SMESH_GroupBase
1036 def GetGroups(self):
1037 return self.mesh.GetGroups()
1039 ## Get number of groups existing in the mesh
1040 # @return quantity of groups as an integer value
1042 return self.mesh.NbGroups()
1044 ## Get the list of names of groups existing in the mesh
1045 # @return list of strings
1046 def GetGroupNames(self):
1047 groups = self.GetGroups()
1049 for group in groups:
1050 names.append(group.GetName())
1053 ## Union of two groups
1054 # New group is created. All mesh elements that are
1055 # present in initial groups are added to the new one
1056 # @return an instance of SMESH_Group
1057 def UnionGroups(self, group1, group2, name):
1058 return self.mesh.UnionGroups(group1, group2, name)
1060 ## Intersection of two groups
1061 # New group is created. All mesh elements that are
1062 # present in both initial groups are added to the new one.
1063 # @return an instance of SMESH_Group
1064 def IntersectGroups(self, group1, group2, name):
1065 return self.mesh.IntersectGroups(group1, group2, name)
1067 ## Cut of two groups
1068 # New group is created. All mesh elements that are present in
1069 # main group but do not present in tool group are added to the new one
1070 # @return an instance of SMESH_Group
1071 def CutGroups(self, mainGroup, toolGroup, name):
1072 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1075 # Get some info about mesh:
1076 # ------------------------
1078 ## Get the log of nodes and elements added or removed since previous
1080 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1081 # @return list of log_block structures:
1086 def GetLog(self, clearAfterGet):
1087 return self.mesh.GetLog(clearAfterGet)
1089 ## Clear the log of nodes and elements added or removed since previous
1090 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1092 self.mesh.ClearLog()
1094 ## Toggle auto color mode on the object.
1095 # @param theAutoColor flag which toggles auto color mode.
1096 def SetAutoColor(self, theAutoColor):
1097 self.mesh.SetAutoColor(theAutoColor)
1099 ## Get flag of object auto color mode.
1100 # @return True or False
1101 def GetAutoColor(self):
1102 return self.mesh.GetAutoColor()
1104 ## Get the internal Id
1105 # @return integer value, which is the internal Id of the mesh
1107 return self.mesh.GetId()
1110 # @return integer value, which is the study Id of the mesh
1111 def GetStudyId(self):
1112 return self.mesh.GetStudyId()
1114 ## Check group names for duplications.
1115 # Consider maximum group name length stored in MED file.
1116 # @return True or False
1117 def HasDuplicatedGroupNamesMED(self):
1118 return self.mesh.HasDuplicatedGroupNamesMED()
1120 ## Obtain mesh editor tool
1121 # @return an instance of SMESH_MeshEditor
1122 def GetMeshEditor(self):
1123 return self.mesh.GetMeshEditor()
1126 # @return an instance of SALOME_MED::MESH
1127 def GetMEDMesh(self):
1128 return self.mesh.GetMEDMesh()
1131 # Get informations about mesh contents:
1132 # ------------------------------------
1134 ## Returns number of nodes in mesh
1135 # @return an integer value
1137 return self.mesh.NbNodes()
1139 ## Returns number of elements in mesh
1140 # @return an integer value
1141 def NbElements(self):
1142 return self.mesh.NbElements()
1144 ## Returns number of edges in mesh
1145 # @return an integer value
1147 return self.mesh.NbEdges()
1149 ## Returns number of edges with given order in mesh
1150 # @param elementOrder is order of elements:
1151 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1152 # @return an integer value
1153 def NbEdgesOfOrder(self, elementOrder):
1154 return self.mesh.NbEdgesOfOrder(elementOrder)
1156 ## Returns number of faces in mesh
1157 # @return an integer value
1159 return self.mesh.NbFaces()
1161 ## Returns number of faces with given order in mesh
1162 # @param elementOrder is order of elements:
1163 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1164 # @return an integer value
1165 def NbFacesOfOrder(self, elementOrder):
1166 return self.mesh.NbFacesOfOrder(elementOrder)
1168 ## Returns number of triangles in mesh
1169 # @return an integer value
1170 def NbTriangles(self):
1171 return self.mesh.NbTriangles()
1173 ## Returns number of triangles with given order in mesh
1174 # @param elementOrder is order of elements:
1175 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1176 # @return an integer value
1177 def NbTrianglesOfOrder(self, elementOrder):
1178 return self.mesh.NbTrianglesOfOrder(elementOrder)
1180 ## Returns number of quadrangles in mesh
1181 # @return an integer value
1182 def NbQuadrangles(self):
1183 return self.mesh.NbQuadrangles()
1185 ## Returns number of quadrangles with given order in mesh
1186 # @param elementOrder is order of elements:
1187 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1188 # @return an integer value
1189 def NbQuadranglesOfOrder(self, elementOrder):
1190 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1192 ## Returns number of polygons in mesh
1193 # @return an integer value
1194 def NbPolygons(self):
1195 return self.mesh.NbPolygons()
1197 ## Returns number of volumes in mesh
1198 # @return an integer value
1199 def NbVolumes(self):
1200 return self.mesh.NbVolumes()
1202 ## Returns number of volumes with given order in mesh
1203 # @param elementOrder is order of elements:
1204 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1205 # @return an integer value
1206 def NbVolumesOfOrder(self, elementOrder):
1207 return self.mesh.NbVolumesOfOrder(elementOrder)
1209 ## Returns number of tetrahedrons in mesh
1210 # @return an integer value
1212 return self.mesh.NbTetras()
1214 ## Returns number of tetrahedrons with given order in mesh
1215 # @param elementOrder is order of elements:
1216 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1217 # @return an integer value
1218 def NbTetrasOfOrder(self, elementOrder):
1219 return self.mesh.NbTetrasOfOrder(elementOrder)
1221 ## Returns number of hexahedrons in mesh
1222 # @return an integer value
1224 return self.mesh.NbHexas()
1226 ## Returns number of hexahedrons with given order in mesh
1227 # @param elementOrder is order of elements:
1228 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1229 # @return an integer value
1230 def NbHexasOfOrder(self, elementOrder):
1231 return self.mesh.NbHexasOfOrder(elementOrder)
1233 ## Returns number of pyramids in mesh
1234 # @return an integer value
1235 def NbPyramids(self):
1236 return self.mesh.NbPyramids()
1238 ## Returns number of pyramids with given order in mesh
1239 # @param elementOrder is order of elements:
1240 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1241 # @return an integer value
1242 def NbPyramidsOfOrder(self, elementOrder):
1243 return self.mesh.NbPyramidsOfOrder(elementOrder)
1245 ## Returns number of prisms in mesh
1246 # @return an integer value
1248 return self.mesh.NbPrisms()
1250 ## Returns number of prisms with given order in mesh
1251 # @param elementOrder is order of elements:
1252 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1253 # @return an integer value
1254 def NbPrismsOfOrder(self, elementOrder):
1255 return self.mesh.NbPrismsOfOrder(elementOrder)
1257 ## Returns number of polyhedrons in mesh
1258 # @return an integer value
1259 def NbPolyhedrons(self):
1260 return self.mesh.NbPolyhedrons()
1262 ## Returns number of submeshes in mesh
1263 # @return an integer value
1264 def NbSubMesh(self):
1265 return self.mesh.NbSubMesh()
1267 ## Returns list of mesh elements ids
1268 # @return list of integer values
1269 def GetElementsId(self):
1270 return self.mesh.GetElementsId()
1272 ## Returns list of ids of mesh elements with given type
1273 # @param elementType is required type of elements
1274 # @return list of integer values
1275 def GetElementsByType(self, elementType):
1276 return self.mesh.GetElementsByType(elementType)
1278 ## Returns list of mesh nodes ids
1279 # @return list of integer values
1280 def GetNodesId(self):
1281 return self.mesh.GetNodesId()
1283 # Get informations about mesh elements:
1284 # ------------------------------------
1286 ## Returns type of mesh element
1287 # @return value from SMESH::ElementType enumeration
1288 def GetElementType(self, id, iselem):
1289 return self.mesh.GetElementType(id, iselem)
1291 ## Returns list of submesh elements ids
1292 # @param Shape is geom object(subshape) IOR
1293 # Shape must be subshape of a ShapeToMesh()
1294 # @return list of integer values
1295 def GetSubMeshElementsId(self, Shape):
1296 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1297 ShapeID = Shape.GetSubShapeIndices()[0]
1300 return self.mesh.GetSubMeshElementsId(ShapeID)
1302 ## Returns list of submesh nodes ids
1303 # @param Shape is geom object(subshape) IOR
1304 # Shape must be subshape of a ShapeToMesh()
1305 # @return list of integer values
1306 def GetSubMeshNodesId(self, Shape, all):
1307 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1308 ShapeID = Shape.GetSubShapeIndices()[0]
1311 return self.mesh.GetSubMeshNodesId(ShapeID, all)
1313 ## Returns list of ids of submesh elements with given type
1314 # @param Shape is geom object(subshape) IOR
1315 # Shape must be subshape of a ShapeToMesh()
1316 # @return list of integer values
1317 def GetSubMeshElementType(self, Shape):
1318 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1319 ShapeID = Shape.GetSubShapeIndices()[0]
1322 return self.mesh.GetSubMeshElementType(ShapeID)
1324 ## Get mesh description
1325 # @return string value
1327 return self.mesh.Dump()
1330 # Get information about nodes and elements of mesh by its ids:
1331 # -----------------------------------------------------------
1333 ## Get XYZ coordinates of node
1334 # \n If there is not node for given ID - returns empty list
1335 # @return a list of double precision values
1336 def GetNodeXYZ(self, id):
1337 return self.mesh.GetNodeXYZ(id)
1339 ## For given node returns list of IDs of inverse elements
1340 # \n If there is not node for given ID - returns empty list
1341 # @return list of integer values
1342 def GetNodeInverseElements(self, id):
1343 return self.mesh.GetNodeInverseElements(id)
1345 ## @brief Return position of a node on shape
1346 # @return SMESH::NodePosition
1347 def GetNodePosition(self,NodeID):
1348 return self.mesh.GetNodePosition(NodeID)
1350 ## If given element is node returns IDs of shape from position
1351 # \n If there is not node for given ID - returns -1
1352 # @return integer value
1353 def GetShapeID(self, id):
1354 return self.mesh.GetShapeID(id)
1356 ## For given element returns ID of result shape after
1357 # FindShape() from SMESH_MeshEditor
1358 # \n If there is not element for given ID - returns -1
1359 # @return integer value
1360 def GetShapeIDForElem(self,id):
1361 return self.mesh.GetShapeIDForElem(id)
1363 ## Returns number of nodes for given element
1364 # \n If there is not element for given ID - returns -1
1365 # @return integer value
1366 def GetElemNbNodes(self, id):
1367 return self.mesh.GetElemNbNodes(id)
1369 ## Returns ID of node by given index for given element
1370 # \n If there is not element for given ID - returns -1
1371 # \n If there is not node for given index - returns -2
1372 # @return integer value
1373 def GetElemNode(self, id, index):
1374 return self.mesh.GetElemNode(id, index)
1376 ## Returns IDs of nodes of given element
1377 # @return list of integer values
1378 def GetElemNodes(self, id):
1379 return self.mesh.GetElemNodes(id)
1381 ## Returns true if given node is medium node in given quadratic element
1382 def IsMediumNode(self, elementID, nodeID):
1383 return self.mesh.IsMediumNode(elementID, nodeID)
1385 ## Returns true if given node is medium node in one of quadratic elements
1386 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1387 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1389 ## Returns number of edges for given element
1390 def ElemNbEdges(self, id):
1391 return self.mesh.ElemNbEdges(id)
1393 ## Returns number of faces for given element
1394 def ElemNbFaces(self, id):
1395 return self.mesh.ElemNbFaces(id)
1397 ## Returns true if given element is polygon
1398 def IsPoly(self, id):
1399 return self.mesh.IsPoly(id)
1401 ## Returns true if given element is quadratic
1402 def IsQuadratic(self, id):
1403 return self.mesh.IsQuadratic(id)
1405 ## Returns XYZ coordinates of bary center for given element
1406 # \n If there is not element for given ID - returns empty list
1407 # @return a list of three double values
1408 def BaryCenter(self, id):
1409 return self.mesh.BaryCenter(id)
1412 # Mesh edition (SMESH_MeshEditor functionality):
1413 # ---------------------------------------------
1415 ## Removes elements from mesh by ids
1416 # @param IDsOfElements is list of ids of elements to remove
1417 # @return True or False
1418 def RemoveElements(self, IDsOfElements):
1419 return self.editor.RemoveElements(IDsOfElements)
1421 ## Removes nodes from mesh by ids
1422 # @param IDsOfNodes is list of ids of nodes to remove
1423 # @return True or False
1424 def RemoveNodes(self, IDsOfNodes):
1425 return self.editor.RemoveNodes(IDsOfNodes)
1427 ## Add node to mesh by coordinates
1428 # @return Id of the new node
1429 def AddNode(self, x, y, z):
1430 return self.editor.AddNode( x, y, z)
1433 ## Create edge either linear or quadratic (this is determined
1434 # by number of given nodes).
1435 # @param IdsOfNodes List of node IDs for creation of element.
1436 # Needed order of nodes in this list corresponds to description
1437 # of MED. \n This description is located by the following link:
1438 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1439 # @return Id of the new edge
1440 def AddEdge(self, IDsOfNodes):
1441 return self.editor.AddEdge(IDsOfNodes)
1443 ## Create face either linear or quadratic (this is determined
1444 # by number of given nodes).
1445 # @param IdsOfNodes List of node IDs for creation of element.
1446 # Needed order of nodes in this list corresponds to description
1447 # of MED. \n This description is located by the following link:
1448 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1449 # @return Id of the new face
1450 def AddFace(self, IDsOfNodes):
1451 return self.editor.AddFace(IDsOfNodes)
1453 ## Add polygonal face to mesh by list of nodes ids
1454 # @return Id of the new face
1455 def AddPolygonalFace(self, IdsOfNodes):
1456 return self.editor.AddPolygonalFace(IdsOfNodes)
1458 ## Create volume both similar and quadratic (this is determed
1459 # by number of given nodes).
1460 # @param IdsOfNodes List of node IDs for creation of element.
1461 # Needed order of nodes in this list corresponds to description
1462 # of MED. \n This description is located by the following link:
1463 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1464 # @return Id of the new volumic element
1465 def AddVolume(self, IDsOfNodes):
1466 return self.editor.AddVolume(IDsOfNodes)
1468 ## Create volume of many faces, giving nodes for each face.
1469 # @param IdsOfNodes List of node IDs for volume creation face by face.
1470 # @param Quantities List of integer values, Quantities[i]
1471 # gives quantity of nodes in face number i.
1472 # @return Id of the new volumic element
1473 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1474 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1476 ## Create volume of many faces, giving IDs of existing faces.
1477 # @param IdsOfFaces List of face IDs for volume creation.
1479 # Note: The created volume will refer only to nodes
1480 # of the given faces, not to the faces itself.
1481 # @return Id of the new volumic element
1482 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1483 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1486 ## @brief Bind a node to a vertex
1487 # @param NodeID - node ID
1488 # @param Vertex - vertex or vertex ID
1489 # @return True if succeed else raise an exception
1490 def SetNodeOnVertex(self, NodeID, Vertex):
1491 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
1492 VertexID = Vertex.GetSubShapeIndices()[0]
1496 self.editor.SetNodeOnVertex(NodeID, VertexID)
1497 except SALOME.SALOME_Exception, inst:
1498 raise ValueError, inst.details.text
1502 ## @brief Store node position on an edge
1503 # @param NodeID - node ID
1504 # @param Edge - edge or edge ID
1505 # @param paramOnEdge - parameter on edge where the node is located
1506 # @return True if succeed else raise an exception
1507 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
1508 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
1509 EdgeID = Edge.GetSubShapeIndices()[0]
1513 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
1514 except SALOME.SALOME_Exception, inst:
1515 raise ValueError, inst.details.text
1518 ## @brief Store node position on a face
1519 # @param NodeID - node ID
1520 # @param Face - face or face ID
1521 # @param u - U parameter on face where the node is located
1522 # @param v - V parameter on face where the node is located
1523 # @return True if succeed else raise an exception
1524 def SetNodeOnFace(self, NodeID, Face, u, v):
1525 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
1526 FaceID = Face.GetSubShapeIndices()[0]
1530 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
1531 except SALOME.SALOME_Exception, inst:
1532 raise ValueError, inst.details.text
1535 ## @brief Bind a node to a solid
1536 # @param NodeID - node ID
1537 # @param Solid - solid or solid ID
1538 # @return True if succeed else raise an exception
1539 def SetNodeInVolume(self, NodeID, Solid):
1540 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
1541 SolidID = Solid.GetSubShapeIndices()[0]
1545 self.editor.SetNodeInVolume(NodeID, SolidID)
1546 except SALOME.SALOME_Exception, inst:
1547 raise ValueError, inst.details.text
1550 ## @brief Bind an element to a shape
1551 # @param ElementID - element ID
1552 # @param Shape - shape or shape ID
1553 # @return True if succeed else raise an exception
1554 def SetMeshElementOnShape(self, ElementID, Shape):
1555 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1556 ShapeID = Shape.GetSubShapeIndices()[0]
1560 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
1561 except SALOME.SALOME_Exception, inst:
1562 raise ValueError, inst.details.text
1566 ## Move node with given id
1567 # @param NodeID id of the node
1568 # @param x new X coordinate
1569 # @param y new Y coordinate
1570 # @param z new Z coordinate
1571 # @return True if succeed else False
1572 def MoveNode(self, NodeID, x, y, z):
1573 return self.editor.MoveNode(NodeID, x, y, z)
1575 ## Find a node closest to a point
1576 # @param x X coordinate of a point
1577 # @param y Y coordinate of a point
1578 # @param z Z coordinate of a point
1579 # @return id of a node
1580 def FindNodeClosestTo(self, x, y, z):
1581 preview = self.mesh.GetMeshEditPreviewer()
1582 return preview.MoveClosestNodeToPoint(x, y, z, -1)
1584 ## Find a node closest to a point and move it to a point location
1585 # @param x X coordinate of a point
1586 # @param y Y coordinate of a point
1587 # @param z Z coordinate of a point
1588 # @return id of a moved node
1589 def MeshToPassThroughAPoint(self, x, y, z):
1590 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1592 ## Replace two neighbour triangles sharing Node1-Node2 link
1593 # with ones built on the same 4 nodes but having other common link.
1594 # @param NodeID1 first node id
1595 # @param NodeID2 second node id
1596 # @return false if proper faces not found
1597 def InverseDiag(self, NodeID1, NodeID2):
1598 return self.editor.InverseDiag(NodeID1, NodeID2)
1600 ## Replace two neighbour triangles sharing Node1-Node2 link
1601 # with a quadrangle built on the same 4 nodes.
1602 # @param NodeID1 first node id
1603 # @param NodeID2 second node id
1604 # @return false if proper faces not found
1605 def DeleteDiag(self, NodeID1, NodeID2):
1606 return self.editor.DeleteDiag(NodeID1, NodeID2)
1608 ## Reorient elements by ids
1609 # @param IDsOfElements if undefined reorient all mesh elements
1610 # @return True if succeed else False
1611 def Reorient(self, IDsOfElements=None):
1612 if IDsOfElements == None:
1613 IDsOfElements = self.GetElementsId()
1614 return self.editor.Reorient(IDsOfElements)
1616 ## Reorient all elements of the object
1617 # @param theObject is mesh, submesh or group
1618 # @return True if succeed else False
1619 def ReorientObject(self, theObject):
1620 if ( isinstance( theObject, Mesh )):
1621 theObject = theObject.GetMesh()
1622 return self.editor.ReorientObject(theObject)
1624 ## Fuse neighbour triangles into quadrangles.
1625 # @param IDsOfElements The triangles to be fused,
1626 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1627 # @param MaxAngle is a max angle between element normals at which fusion
1628 # is still performed; theMaxAngle is mesured in radians.
1629 # @return TRUE in case of success, FALSE otherwise.
1630 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1631 if IDsOfElements == []:
1632 IDsOfElements = self.GetElementsId()
1633 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1635 ## Fuse neighbour triangles of the object into quadrangles
1636 # @param theObject is mesh, submesh or group
1637 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1638 # @param MaxAngle is a max angle between element normals at which fusion
1639 # is still performed; theMaxAngle is mesured in radians.
1640 # @return TRUE in case of success, FALSE otherwise.
1641 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1642 if ( isinstance( theObject, Mesh )):
1643 theObject = theObject.GetMesh()
1644 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1646 ## Split quadrangles into triangles.
1647 # @param IDsOfElements the faces to be splitted.
1648 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1649 # @return TRUE in case of success, FALSE otherwise.
1650 def QuadToTri (self, IDsOfElements, theCriterion):
1651 if IDsOfElements == []:
1652 IDsOfElements = self.GetElementsId()
1653 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
1655 ## Split quadrangles into triangles.
1656 # @param theObject object to taking list of elements from, is mesh, submesh or group
1657 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1658 # @return TRUE in case of success, FALSE otherwise.
1659 def QuadToTriObject (self, theObject, theCriterion):
1660 if ( isinstance( theObject, Mesh )):
1661 theObject = theObject.GetMesh()
1662 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
1664 ## Split quadrangles into triangles.
1665 # @param theElems The faces to be splitted
1666 # @param the13Diag is used to choose a diagonal for splitting.
1667 # @return TRUE in case of success, FALSE otherwise.
1668 def SplitQuad (self, IDsOfElements, Diag13):
1669 if IDsOfElements == []:
1670 IDsOfElements = self.GetElementsId()
1671 return self.editor.SplitQuad(IDsOfElements, Diag13)
1673 ## Split quadrangles into triangles.
1674 # @param theObject is object to taking list of elements from, is mesh, submesh or group
1675 # @return TRUE in case of success, FALSE otherwise.
1676 def SplitQuadObject (self, theObject, Diag13):
1677 if ( isinstance( theObject, Mesh )):
1678 theObject = theObject.GetMesh()
1679 return self.editor.SplitQuadObject(theObject, Diag13)
1681 ## Find better splitting of the given quadrangle.
1682 # @param IDOfQuad ID of the quadrangle to be splitted.
1683 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
1684 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1685 # diagonal is better, 0 if error occurs.
1686 def BestSplit (self, IDOfQuad, theCriterion):
1687 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
1689 ## Split quadrangle faces near triangular facets of volumes
1691 def SplitQuadsNearTriangularFacets(self):
1692 faces_array = self.GetElementsByType(SMESH.FACE)
1693 for face_id in faces_array:
1694 if self.GetElemNbNodes(face_id) == 4: # quadrangle
1695 quad_nodes = self.mesh.GetElemNodes(face_id)
1696 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1697 isVolumeFound = False
1698 for node1_elem in node1_elems:
1699 if not isVolumeFound:
1700 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1701 nb_nodes = self.GetElemNbNodes(node1_elem)
1702 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1703 volume_elem = node1_elem
1704 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1705 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1706 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1707 isVolumeFound = True
1708 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1709 self.SplitQuad([face_id], False) # diagonal 2-4
1710 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1711 isVolumeFound = True
1712 self.SplitQuad([face_id], True) # diagonal 1-3
1713 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1714 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1715 isVolumeFound = True
1716 self.SplitQuad([face_id], True) # diagonal 1-3
1718 ## @brief Split hexahedrons into tetrahedrons.
1720 # Use pattern mapping functionality for splitting.
1721 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
1722 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
1723 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
1724 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1725 # key-point will be mapped into <theNode001>-th node of each volume.
1726 # The (0,0,0) key-point of used pattern corresponds to not split corner.
1727 # @return TRUE in case of success, FALSE otherwise.
1728 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
1729 # Pattern: 5.---------.6
1734 # (0,0,1) 4.---------.7 * |
1741 # (0,0,0) 0.---------.3
1742 pattern_tetra = "!!! Nb of points: \n 8 \n\
1752 !!! Indices of points of 6 tetras: \n\
1760 pattern = self.smeshpyD.GetPattern()
1761 isDone = pattern.LoadFromFile(pattern_tetra)
1763 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1766 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1767 isDone = pattern.MakeMesh(self.mesh, False, False)
1768 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1770 # split quafrangle faces near triangular facets of volumes
1771 self.SplitQuadsNearTriangularFacets()
1775 ## @brief Split hexahedrons into prisms.
1777 # Use pattern mapping functionality for splitting.
1778 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
1779 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
1780 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
1781 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1782 # key-point will be mapped into <theNode001>-th node of each volume.
1783 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
1784 # @return TRUE in case of success, FALSE otherwise.
1785 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
1786 # Pattern: 5.---------.6
1791 # (0,0,1) 4.---------.7 |
1798 # (0,0,0) 0.---------.3
1799 pattern_prism = "!!! Nb of points: \n 8 \n\
1809 !!! Indices of points of 2 prisms: \n\
1813 pattern = self.smeshpyD.GetPattern()
1814 isDone = pattern.LoadFromFile(pattern_prism)
1816 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1819 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1820 isDone = pattern.MakeMesh(self.mesh, False, False)
1821 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1823 # split quafrangle faces near triangular facets of volumes
1824 self.SplitQuadsNearTriangularFacets()
1829 # @param IDsOfElements list if ids of elements to smooth
1830 # @param IDsOfFixedNodes list of ids of fixed nodes.
1831 # Note that nodes built on edges and boundary nodes are always fixed.
1832 # @param MaxNbOfIterations maximum number of iterations
1833 # @param MaxAspectRatio varies in range [1.0, inf]
1834 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1835 # @return TRUE in case of success, FALSE otherwise.
1836 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1837 MaxNbOfIterations, MaxAspectRatio, Method):
1838 if IDsOfElements == []:
1839 IDsOfElements = self.GetElementsId()
1840 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1841 MaxNbOfIterations, MaxAspectRatio, Method)
1843 ## Smooth elements belong to given object
1844 # @param theObject object to smooth
1845 # @param IDsOfFixedNodes list of ids of fixed nodes.
1846 # Note that nodes built on edges and boundary nodes are always fixed.
1847 # @param MaxNbOfIterations maximum number of iterations
1848 # @param MaxAspectRatio varies in range [1.0, inf]
1849 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1850 # @return TRUE in case of success, FALSE otherwise.
1851 def SmoothObject(self, theObject, IDsOfFixedNodes,
1852 MaxNbOfIterations, MaxxAspectRatio, Method):
1853 if ( isinstance( theObject, Mesh )):
1854 theObject = theObject.GetMesh()
1855 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1856 MaxNbOfIterations, MaxxAspectRatio, Method)
1858 ## Parametric smooth the given elements
1859 # @param IDsOfElements list if ids of elements to smooth
1860 # @param IDsOfFixedNodes list of ids of fixed nodes.
1861 # Note that nodes built on edges and boundary nodes are always fixed.
1862 # @param MaxNbOfIterations maximum number of iterations
1863 # @param MaxAspectRatio varies in range [1.0, inf]
1864 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1865 # @return TRUE in case of success, FALSE otherwise.
1866 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
1867 MaxNbOfIterations, MaxAspectRatio, Method):
1868 if IDsOfElements == []:
1869 IDsOfElements = self.GetElementsId()
1870 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1871 MaxNbOfIterations, MaxAspectRatio, Method)
1873 ## Parametric smooth elements belong to given object
1874 # @param theObject object to smooth
1875 # @param IDsOfFixedNodes list of ids of fixed nodes.
1876 # Note that nodes built on edges and boundary nodes are always fixed.
1877 # @param MaxNbOfIterations maximum number of iterations
1878 # @param MaxAspectRatio varies in range [1.0, inf]
1879 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1880 # @return TRUE in case of success, FALSE otherwise.
1881 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
1882 MaxNbOfIterations, MaxAspectRatio, Method):
1883 if ( isinstance( theObject, Mesh )):
1884 theObject = theObject.GetMesh()
1885 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
1886 MaxNbOfIterations, MaxAspectRatio, Method)
1888 ## Converts all mesh to quadratic one, deletes old elements, replacing
1889 # them with quadratic ones with the same id.
1890 def ConvertToQuadratic(self, theForce3d):
1891 self.editor.ConvertToQuadratic(theForce3d)
1893 ## Converts all mesh from quadratic to ordinary ones,
1894 # deletes old quadratic elements, \n replacing
1895 # them with ordinary mesh elements with the same id.
1896 # @return TRUE in case of success, FALSE otherwise.
1897 def ConvertFromQuadratic(self):
1898 return self.editor.ConvertFromQuadratic()
1900 ## Renumber mesh nodes
1901 def RenumberNodes(self):
1902 self.editor.RenumberNodes()
1904 ## Renumber mesh elements
1905 def RenumberElements(self):
1906 self.editor.RenumberElements()
1908 ## Generate new elements by rotation of the elements around the axis
1909 # @param IDsOfElements list of ids of elements to sweep
1910 # @param Axix axis of rotation, AxisStruct or line(geom object)
1911 # @param AngleInRadians angle of Rotation
1912 # @param NbOfSteps number of steps
1913 # @param Tolerance tolerance
1914 # @param MakeGroups to generate new groups from existing ones
1915 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an anglular size
1916 # of all steps, else - size of each step
1917 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1918 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance,
1919 MakeGroups=False, TotalAngle=False):
1920 if IDsOfElements == []:
1921 IDsOfElements = self.GetElementsId()
1922 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1923 Axix = self.smeshpyD.GetAxisStruct(Axix)
1924 if TotalAngle and NbOfSteps:
1925 AngleInRadians /= NbOfSteps
1927 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
1928 AngleInRadians, NbOfSteps, Tolerance)
1929 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
1932 ## Generate new elements by rotation of the elements of object around the axis
1933 # @param theObject object wich elements should be sweeped
1934 # @param Axix axis of rotation, AxisStruct or line(geom object)
1935 # @param AngleInRadians angle of Rotation
1936 # @param NbOfSteps number of steps
1937 # @param Tolerance tolerance
1938 # @param MakeGroups to generate new groups from existing ones
1939 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an anglular size
1940 # of all steps, else - size of each step
1941 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1942 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance,
1943 MakeGroups=False, TotalAngle=False):
1944 if ( isinstance( theObject, Mesh )):
1945 theObject = theObject.GetMesh()
1946 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1947 Axix = self.smeshpyD.GetAxisStruct(Axix)
1948 if TotalAngle and NbOfSteps:
1949 AngleInRadians /= NbOfSteps
1951 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
1952 NbOfSteps, Tolerance)
1953 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
1956 ## Generate new elements by extrusion of the elements with given ids
1957 # @param IDsOfElements list of elements ids for extrusion
1958 # @param StepVector vector, defining the direction and value of extrusion
1959 # @param NbOfSteps the number of steps
1960 # @param MakeGroups to generate new groups from existing ones
1961 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1962 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
1963 if IDsOfElements == []:
1964 IDsOfElements = self.GetElementsId()
1965 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1966 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1968 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
1969 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
1972 ## Generate new elements by extrusion of the elements with given ids
1973 # @param IDsOfElements is ids of elements
1974 # @param StepVector vector, defining the direction and value of extrusion
1975 # @param NbOfSteps the number of steps
1976 # @param ExtrFlags set flags for performing extrusion
1977 # @param SewTolerance uses for comparing locations of nodes if flag
1978 # EXTRUSION_FLAG_SEW is set
1979 # @param MakeGroups to generate new groups from existing ones
1980 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1981 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
1982 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1983 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1985 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
1986 ExtrFlags, SewTolerance)
1987 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
1988 ExtrFlags, SewTolerance)
1991 ## Generate new elements by extrusion of the elements belong to object
1992 # @param theObject object wich elements should be processed
1993 # @param StepVector vector, defining the direction and value of extrusion
1994 # @param NbOfSteps the number of steps
1995 # @param MakeGroups to generate new groups from existing ones
1996 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
1997 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
1998 if ( isinstance( theObject, Mesh )):
1999 theObject = theObject.GetMesh()
2000 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2001 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2003 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2004 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2007 ## Generate new elements by extrusion of the elements belong to object
2008 # @param theObject object wich elements should be processed
2009 # @param StepVector vector, defining the direction and value of extrusion
2010 # @param NbOfSteps the number of steps
2011 # @param MakeGroups to generate new groups from existing ones
2012 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2013 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2014 if ( isinstance( theObject, Mesh )):
2015 theObject = theObject.GetMesh()
2016 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2017 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2019 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2020 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2023 ## Generate new elements by extrusion of the elements belong to object
2024 # @param theObject object wich elements should be processed
2025 # @param StepVector vector, defining the direction and value of extrusion
2026 # @param NbOfSteps the number of steps
2027 # @param MakeGroups to generate new groups from existing ones
2028 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2029 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2030 if ( isinstance( theObject, Mesh )):
2031 theObject = theObject.GetMesh()
2032 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2033 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2035 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2036 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2039 ## Generate new elements by extrusion of the given elements
2040 # A path of extrusion must be a meshed edge.
2041 # @param IDsOfElements is ids of elements
2042 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2043 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2044 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2045 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2046 # @param Angles list of angles
2047 # @param HasRefPoint allows to use base point
2048 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2049 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2050 # @param MakeGroups to generate new groups from existing ones
2051 # @param LinearVariation makes compute rotation angles as linear variation of 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 ## Generate new elements by extrusion of the elements belong to object
2075 # A 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 proceeds the extrusion
2078 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2079 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2080 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2081 # @param Angles list of angles
2082 # @param HasRefPoint allows to use base point
2083 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2084 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2085 # @param MakeGroups to generate new groups from existing ones
2086 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2087 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
2088 # only SMESH::Extrusion_Error otherwise
2089 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2090 HasAngles, Angles, HasRefPoint, RefPoint,
2091 MakeGroups=False, LinearVariation=False):
2092 if ( isinstance( theObject, Mesh )):
2093 theObject = theObject.GetMesh()
2094 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2095 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2096 if ( isinstance( PathMesh, Mesh )):
2097 PathMesh = PathMesh.GetMesh()
2098 if HasAngles and Angles and LinearVariation:
2099 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
2102 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
2103 PathShape, NodeStart, HasAngles,
2104 Angles, HasRefPoint, RefPoint)
2105 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
2106 NodeStart, HasAngles, Angles, HasRefPoint,
2109 ## Symmetrical copy of mesh elements
2110 # @param IDsOfElements list of elements ids
2111 # @param Mirror is AxisStruct or geom object(point, line, plane)
2112 # @param theMirrorType is POINT, AXIS or PLANE
2113 # If the Mirror is geom object this parameter is unnecessary
2114 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2115 # @param MakeGroups to generate new groups from existing ones (if Copy)
2116 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2117 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2118 if IDsOfElements == []:
2119 IDsOfElements = self.GetElementsId()
2120 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2121 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2122 if Copy and MakeGroups:
2123 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2124 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2127 ## Create a new mesh by symmetrical copy of mesh elements
2128 # @param IDsOfElements list of elements ids
2129 # @param Mirror is AxisStruct or geom object(point, line, plane)
2130 # @param theMirrorType is POINT, AXIS or PLANE
2131 # If the Mirror is geom object this parameter is unnecessary
2132 # @param MakeGroups to generate new groups from existing ones
2133 # @param NewMeshName is a name of new mesh to create
2134 # @return instance of Mesh class
2135 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
2136 if IDsOfElements == []:
2137 IDsOfElements = self.GetElementsId()
2138 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2139 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2140 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
2141 MakeGroups, NewMeshName)
2142 return Mesh(self.smeshpyD,self.geompyD,mesh)
2144 ## Symmetrical copy of object
2145 # @param theObject mesh, submesh or group
2146 # @param Mirror is AxisStruct or geom object(point, line, plane)
2147 # @param theMirrorType is POINT, AXIS or PLANE
2148 # If the Mirror is geom object this parameter is unnecessary
2149 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2150 # @param MakeGroups to generate new groups from existing ones (if Copy)
2151 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2152 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2153 if ( isinstance( theObject, Mesh )):
2154 theObject = theObject.GetMesh()
2155 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2156 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2157 if Copy and MakeGroups:
2158 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2159 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2162 ## Create a new mesh by symmetrical copy of object
2163 # @param theObject mesh, submesh or group
2164 # @param Mirror is AxisStruct or geom object(point, line, plane)
2165 # @param theMirrorType is POINT, AXIS or PLANE
2166 # If the Mirror is geom object this parameter is unnecessary
2167 # @param MakeGroups to generate new groups from existing ones
2168 # @param NewMeshName is a name of new mesh to create
2169 # @return instance of Mesh class
2170 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
2171 if ( isinstance( theObject, Mesh )):
2172 theObject = theObject.GetMesh()
2173 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2174 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2175 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
2176 MakeGroups, NewMeshName)
2177 return Mesh( self.smeshpyD,self.geompyD,mesh )
2179 ## Translates the elements
2180 # @param IDsOfElements list of elements ids
2181 # @param Vector direction of translation(DirStruct or vector)
2182 # @param Copy allows to copy the translated elements
2183 # @param MakeGroups to generate new groups from existing ones (if Copy)
2184 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2185 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2186 if IDsOfElements == []:
2187 IDsOfElements = self.GetElementsId()
2188 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2189 Vector = self.smeshpyD.GetDirStruct(Vector)
2190 if Copy and MakeGroups:
2191 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2192 self.editor.Translate(IDsOfElements, Vector, Copy)
2195 ## Create a new mesh of translated elements
2196 # @param IDsOfElements list of elements ids
2197 # @param Vector direction of translation(DirStruct or vector)
2198 # @param MakeGroups to generate new groups from existing ones
2199 # @param NewMeshName is a name of new mesh to create
2200 # @return instance of Mesh class
2201 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
2202 if IDsOfElements == []:
2203 IDsOfElements = self.GetElementsId()
2204 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2205 Vector = self.smeshpyD.GetDirStruct(Vector)
2206 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
2207 return Mesh ( self.smeshpyD, self.geompyD, mesh )
2209 ## Translates the object
2210 # @param theObject object to translate(mesh, submesh, or group)
2211 # @param Vector direction of translation(DirStruct or geom vector)
2212 # @param Copy allows to copy the translated elements
2213 # @param MakeGroups to generate new groups from existing ones (if Copy)
2214 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2215 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2216 if ( isinstance( theObject, Mesh )):
2217 theObject = theObject.GetMesh()
2218 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2219 Vector = self.smeshpyD.GetDirStruct(Vector)
2220 if Copy and MakeGroups:
2221 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2222 self.editor.TranslateObject(theObject, Vector, Copy)
2225 ## Create a new mesh from translated object
2226 # @param theObject object to translate(mesh, submesh, or group)
2227 # @param Vector direction of translation(DirStruct or geom vector)
2228 # @param MakeGroups to generate new groups from existing ones
2229 # @param NewMeshName is a name of new mesh to create
2230 # @return instance of Mesh class
2231 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
2232 if (isinstance(theObject, Mesh)):
2233 theObject = theObject.GetMesh()
2234 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
2235 Vector = self.smeshpyD.GetDirStruct(Vector)
2236 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
2237 return Mesh( self.smeshpyD, self.geompyD, mesh )
2239 ## Rotates the elements
2240 # @param IDsOfElements list of elements ids
2241 # @param Axis axis of rotation(AxisStruct or geom line)
2242 # @param AngleInRadians angle of rotation(in radians)
2243 # @param Copy allows to copy the rotated elements
2244 # @param MakeGroups to generate new groups from existing ones (if Copy)
2245 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2246 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2247 if IDsOfElements == []:
2248 IDsOfElements = self.GetElementsId()
2249 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2250 Axis = self.smeshpyD.GetAxisStruct(Axis)
2251 if Copy and MakeGroups:
2252 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2253 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2256 ## Create a new mesh of rotated elements
2257 # @param IDsOfElements list of element ids
2258 # @param Axis axis of rotation(AxisStruct or geom line)
2259 # @param AngleInRadians angle of rotation(in radians)
2260 # @param MakeGroups to generate new groups from existing ones
2261 # @param NewMeshName is a name of new mesh to create
2262 # @return instance of Mesh class
2263 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
2264 if IDsOfElements == []:
2265 IDsOfElements = self.GetElementsId()
2266 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2267 Axis = self.smeshpyD.GetAxisStruct(Axis)
2268 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
2269 MakeGroups, NewMeshName)
2270 return Mesh( self.smeshpyD, self.geompyD, mesh )
2272 ## Rotates the object
2273 # @param theObject object to rotate(mesh, submesh, or group)
2274 # @param Axis axis of rotation(AxisStruct or geom line)
2275 # @param AngleInRadians angle of rotation(in radians)
2276 # @param Copy allows to copy the rotated elements
2277 # @param MakeGroups to generate new groups from existing ones (if Copy)
2278 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
2279 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2280 if (isinstance(theObject, Mesh)):
2281 theObject = theObject.GetMesh()
2282 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2283 Axis = self.smeshpyD.GetAxisStruct(Axis)
2284 if Copy and MakeGroups:
2285 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2286 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2289 ## Create a new mesh from a rotated object
2290 # @param theObject object to rotate (mesh, submesh, or group)
2291 # @param Axis axis of rotation(AxisStruct or geom line)
2292 # @param AngleInRadians angle of rotation(in radians)
2293 # @param MakeGroups to generate new groups from existing ones
2294 # @param NewMeshName is a name of new mesh to create
2295 # @return instance of Mesh class
2296 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
2297 if (isinstance( theObject, Mesh )):
2298 theObject = theObject.GetMesh()
2299 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2300 Axis = self.smeshpyD.GetAxisStruct(Axis)
2301 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
2302 MakeGroups, NewMeshName)
2303 return Mesh( self.smeshpyD, self.geompyD, mesh )
2305 ## Find group of nodes close to each other within Tolerance.
2306 # @param Tolerance tolerance value
2307 # @return list of group of nodes
2308 def FindCoincidentNodes (self, Tolerance):
2309 return self.editor.FindCoincidentNodes(Tolerance)
2311 ## Find group of nodes close to each other within Tolerance.
2312 # @param Tolerance tolerance value
2313 # @param SubMeshOrGroup SubMesh or Group
2314 # @return list of group of nodes
2315 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2316 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2319 # @param GroupsOfNodes list of group of nodes
2320 def MergeNodes (self, GroupsOfNodes):
2321 self.editor.MergeNodes(GroupsOfNodes)
2323 ## Find elements built on the same nodes.
2324 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2325 # @return a list of groups of equal elements
2326 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2327 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2329 ## Merge elements in each given group.
2330 # @param GroupsOfElementsID groups of elements for merging
2331 def MergeElements(self, GroupsOfElementsID):
2332 self.editor.MergeElements(GroupsOfElementsID)
2334 ## Remove all but one of elements built on the same nodes.
2335 def MergeEqualElements(self):
2336 self.editor.MergeEqualElements()
2339 # @return SMESH::Sew_Error
2340 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2341 FirstNodeID2, SecondNodeID2, LastNodeID2,
2342 CreatePolygons, CreatePolyedrs):
2343 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2344 FirstNodeID2, SecondNodeID2, LastNodeID2,
2345 CreatePolygons, CreatePolyedrs)
2347 ## Sew conform free borders
2348 # @return SMESH::Sew_Error
2349 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2350 FirstNodeID2, SecondNodeID2):
2351 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2352 FirstNodeID2, SecondNodeID2)
2354 ## Sew border to side
2355 # @return SMESH::Sew_Error
2356 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2357 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2358 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2359 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2361 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2362 # merged with nodes of elements of Side2.
2363 # Number of elements in theSide1 and in theSide2 must be
2364 # equal and they should have similar node connectivity.
2365 # The nodes to merge should belong to sides borders and
2366 # the first node should be linked to the second.
2367 # @return SMESH::Sew_Error
2368 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2369 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2370 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2371 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2372 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2373 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2375 ## Set new nodes for given element.
2376 # @param ide the element id
2377 # @param newIDs nodes ids
2378 # @return If number of nodes is not corresponded to type of element - returns false
2379 def ChangeElemNodes(self, ide, newIDs):
2380 return self.editor.ChangeElemNodes(ide, newIDs)
2382 ## If during last operation of MeshEditor some nodes were
2383 # created this method returns list of its IDs, \n
2384 # if new nodes not created - returns empty list
2385 # @return list of integer values (can be empty)
2386 def GetLastCreatedNodes(self):
2387 return self.editor.GetLastCreatedNodes()
2389 ## If during last operation of MeshEditor some elements were
2390 # created this method returns list of its IDs, \n
2391 # if new elements not creared - returns empty list
2392 # @return list of integer values (can be empty)
2393 def GetLastCreatedElems(self):
2394 return self.editor.GetLastCreatedElems()
2396 ## Mother class to define algorithm, recommended to do not use directly.
2399 class Mesh_Algorithm:
2400 # @class Mesh_Algorithm
2401 # @brief Class Mesh_Algorithm
2403 #def __init__(self,smesh):
2411 ## Find hypothesis in study by its type name and parameters.
2412 # Find only those hypothesis, which was created in smeshpyD engine.
2413 # @return SMESH.SMESH_Hypothesis
2414 def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
2415 study = smeshpyD.GetCurrentStudy()
2416 #to do: find component by smeshpyD object, not by its data type
2417 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2418 if scomp is not None:
2419 res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
2420 # is hypotheses root label exists?
2421 if res and hypRoot is not None:
2422 iter = study.NewChildIterator(hypRoot)
2423 # check all published hypotheses
2425 hypo_so_i = iter.Value()
2426 attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
2427 if attr is not None:
2428 anIOR = attr.Value()
2429 hypo_o_i = salome.orb.string_to_object(anIOR)
2430 if hypo_o_i is not None:
2432 hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
2433 if hypo_i is not None:
2434 # belongs to this engine?
2435 if smeshpyD.GetObjectId(hypo_i) > 0:
2436 # is it the needed hypothesis?
2437 if hypo_i.GetName() == hypname:
2439 if CompareMethod(hypo_i, args):
2453 ## Find algorithm in study by its type name.
2454 # Find only those algorithm, which was created in smeshpyD engine.
2455 # @return SMESH.SMESH_Algo
2456 def FindAlgorithm (self, algoname, smeshpyD):
2457 study = smeshpyD.GetCurrentStudy()
2458 #to do: find component by smeshpyD object, not by its data type
2459 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2460 if scomp is not None:
2461 res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
2462 # is algorithms root label exists?
2463 if res and hypRoot is not None:
2464 iter = study.NewChildIterator(hypRoot)
2465 # check all published algorithms
2467 algo_so_i = iter.Value()
2468 attr = algo_so_i.FindAttribute("AttributeIOR")[1]
2469 if attr is not None:
2470 anIOR = attr.Value()
2471 algo_o_i = salome.orb.string_to_object(anIOR)
2472 if algo_o_i is not None:
2474 algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
2475 if algo_i is not None:
2476 # belongs to this engine?
2477 if smeshpyD.GetObjectId(algo_i) > 0:
2478 # is it the needed algorithm?
2479 if algo_i.GetName() == algoname:
2492 ## If the algorithm is global, return 0; \n
2493 # else return the submesh associated to this algorithm.
2494 def GetSubMesh(self):
2497 ## Return the wrapped mesher.
2498 def GetAlgorithm(self):
2501 ## Get list of hypothesis that can be used with this algorithm
2502 def GetCompatibleHypothesis(self):
2505 mylist = self.algo.GetCompatibleHypothesis()
2513 def SetName(self, name):
2514 SetName(self.algo, name)
2518 return self.algo.GetId()
2521 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
2523 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
2524 algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
2526 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
2528 self.Assign(algo, mesh, geom)
2532 def Assign(self, algo, mesh, geom):
2534 raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
2541 name = GetName(geom)
2543 name = mesh.geompyD.SubShapeName(geom, piece)
2544 mesh.geompyD.addToStudyInFather(piece, geom, name)
2545 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
2548 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
2549 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
2551 def CompareHyp (self, hyp, args):
2552 print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
2555 def CompareEqualHyp (self, hyp, args):
2559 def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
2560 UseExisting=0, CompareMethod=""):
2563 if CompareMethod == "": CompareMethod = self.CompareHyp
2564 hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
2567 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
2573 a = a + s + str(args[i])
2577 SetName(hypo, hyp + a)
2579 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
2580 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
2584 # Public class: Mesh_Segment
2585 # --------------------------
2587 ## Class to define a segment 1D algorithm for discretization
2590 class Mesh_Segment(Mesh_Algorithm):
2592 ## Private constructor.
2593 def __init__(self, mesh, geom=0):
2594 Mesh_Algorithm.__init__(self)
2595 self.Create(mesh, geom, "Regular_1D")
2597 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
2598 # @param l for the length of segments that cut an edge
2599 # @param UseExisting if ==true - search existing hypothesis created with
2600 # same parameters, else (default) - create new
2601 # @param p precision, used for number of segments calculation.
2602 # It must be pozitive, meaningfull values are in range [0,1].
2603 # In general, number of segments is calculated with formula:
2604 # nb = ceil((edge_length / l) - p)
2605 # Function ceil rounds its argument to the higher integer.
2606 # So, p=0 means rounding of (edge_length / l) to the higher integer,
2607 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
2608 # p=1 means rounding of (edge_length / l) to the lower integer.
2609 # Default value is 1e-07.
2610 # @return an instance of StdMeshers_LocalLength hypothesis
2611 def LocalLength(self, l, UseExisting=0, p=1e-07):
2612 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
2613 CompareMethod=self.CompareLocalLength)
2619 ## Check if the given "LocalLength" hypothesis has the same parameters as given arguments
2620 def CompareLocalLength(self, hyp, args):
2621 if IsEqual(hyp.GetLength(), args[0]):
2622 return IsEqual(hyp.GetPrecision(), args[1])
2625 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
2626 # @param n for the number of segments that cut an edge
2627 # @param s for the scale factor (optional)
2628 # @param UseExisting if ==true - search existing hypothesis created with
2629 # same parameters, else (default) - create new
2630 # @return an instance of StdMeshers_NumberOfSegments hypothesis
2631 def NumberOfSegments(self, n, s=[], UseExisting=0):
2633 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
2634 CompareMethod=self.CompareNumberOfSegments)
2636 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
2637 CompareMethod=self.CompareNumberOfSegments)
2638 hyp.SetDistrType( 1 )
2639 hyp.SetScaleFactor(s)
2640 hyp.SetNumberOfSegments(n)
2644 ## Check if the given "NumberOfSegments" hypothesis has the same parameters as given arguments
2645 def CompareNumberOfSegments(self, hyp, args):
2646 if hyp.GetNumberOfSegments() == args[0]:
2650 if hyp.GetDistrType() == 1:
2651 if IsEqual(hyp.GetScaleFactor(), args[1]):
2655 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
2656 # @param start for the length of the first segment
2657 # @param end for the length of the last segment
2658 # @param UseExisting if ==true - search existing hypothesis created with
2659 # same parameters, else (default) - create new
2660 # @return an instance of StdMeshers_Arithmetic1D hypothesis
2661 def Arithmetic1D(self, start, end, UseExisting=0):
2662 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
2663 CompareMethod=self.CompareArithmetic1D)
2664 hyp.SetLength(start, 1)
2665 hyp.SetLength(end , 0)
2669 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as given arguments
2670 def CompareArithmetic1D(self, hyp, args):
2671 if IsEqual(hyp.GetLength(1), args[0]):
2672 if IsEqual(hyp.GetLength(0), args[1]):
2676 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
2677 # @param start for the length of the first segment
2678 # @param end for the length of the last segment
2679 # @param UseExisting if ==true - search existing hypothesis created with
2680 # same parameters, else (default) - create new
2681 # @return an instance of StdMeshers_StartEndLength hypothesis
2682 def StartEndLength(self, start, end, UseExisting=0):
2683 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
2684 CompareMethod=self.CompareStartEndLength)
2685 hyp.SetLength(start, 1)
2686 hyp.SetLength(end , 0)
2689 ## Check if the given "StartEndLength" hypothesis has the same parameters as given arguments
2690 def CompareStartEndLength(self, hyp, args):
2691 if IsEqual(hyp.GetLength(1), args[0]):
2692 if IsEqual(hyp.GetLength(0), args[1]):
2696 ## Define "Deflection1D" hypothesis
2697 # @param d for the deflection
2698 # @param UseExisting if ==true - search existing hypothesis created with
2699 # same parameters, else (default) - create new
2700 def Deflection1D(self, d, UseExisting=0):
2701 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
2702 CompareMethod=self.CompareDeflection1D)
2703 hyp.SetDeflection(d)
2706 ## Check if the given "Deflection1D" hypothesis has the same parameters as given arguments
2707 def CompareDeflection1D(self, hyp, args):
2708 return IsEqual(hyp.GetDeflection(), args[0])
2710 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
2711 # the opposite side in the case of quadrangular faces
2712 def Propagation(self):
2713 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2715 ## Define "AutomaticLength" hypothesis
2716 # @param fineness for the fineness [0-1]
2717 # @param UseExisting if ==true - search existing hypothesis created with
2718 # same parameters, else (default) - create new
2719 def AutomaticLength(self, fineness=0, UseExisting=0):
2720 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
2721 CompareMethod=self.CompareAutomaticLength)
2722 hyp.SetFineness( fineness )
2725 ## Check if the given "AutomaticLength" hypothesis has the same parameters as given arguments
2726 def CompareAutomaticLength(self, hyp, args):
2727 return IsEqual(hyp.GetFineness(), args[0])
2729 ## Define "SegmentLengthAroundVertex" hypothesis
2730 # @param length for the segment length
2731 # @param vertex for the length localization: vertex index [0,1] | vertex object.
2732 # Any other integer value means what hypo will be set on the
2733 # whole 1D shape, where Mesh_Segment algorithm is assigned.
2734 # @param UseExisting if ==true - search existing hypothesis created with
2735 # same parameters, else (default) - create new
2736 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
2738 store_geom = self.geom
2739 if type(vertex) is types.IntType:
2740 if vertex == 0 or vertex == 1:
2741 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
2749 if self.geom is None:
2750 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
2751 name = GetName(self.geom)
2753 piece = self.mesh.geom
2754 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
2755 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
2756 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
2758 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
2760 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
2761 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
2763 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
2764 CompareMethod=self.CompareLengthNearVertex)
2765 self.geom = store_geom
2766 hyp.SetLength( length )
2769 ## Check if the given "LengthNearVertex" hypothesis has the same parameters as given arguments
2770 def CompareLengthNearVertex(self, hyp, args):
2771 return IsEqual(hyp.GetLength(), args[0])
2773 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
2774 # If the 2D mesher sees that all boundary edges are quadratic ones,
2775 # it generates quadratic faces, else it generates linear faces using
2776 # medium nodes as if they were vertex ones.
2777 # The 3D mesher generates quadratic volumes only if all boundary faces
2778 # are quadratic ones, else it fails.
2779 def QuadraticMesh(self):
2780 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2783 # Public class: Mesh_CompositeSegment
2784 # --------------------------
2786 ## Class to define a segment 1D algorithm for discretization
2789 class Mesh_CompositeSegment(Mesh_Segment):
2791 ## Private constructor.
2792 def __init__(self, mesh, geom=0):
2793 self.Create(mesh, geom, "CompositeSegment_1D")
2796 # Public class: Mesh_Segment_Python
2797 # ---------------------------------
2799 ## Class to define 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 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
2810 # @param n for the number of segments that cut an edge
2811 # @param func for the python function that calculate the length of all segments
2812 # @param UseExisting if ==true - search existing hypothesis created with
2813 # same parameters, else (default) - create new
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 ## Check if the given "PythonSplit1D" hypothesis has the same parameters as 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 ## Class to define a triangle 2D algorithm
2834 class Mesh_Triangle(Mesh_Algorithm):
2843 ## Private constructor.
2844 def __init__(self, mesh, algoType, geom=0):
2845 Mesh_Algorithm.__init__(self)
2847 self.algoType = algoType
2848 if algoType == MEFISTO:
2849 self.Create(mesh, geom, "MEFISTO_2D")
2851 elif algoType == BLSURF:
2853 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
2854 self.SetPhysicalMesh()
2855 elif algoType == NETGEN:
2857 print "Warning: NETGENPlugin module unavailable"
2859 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
2861 elif algoType == NETGEN_2D:
2863 print "Warning: NETGENPlugin module unavailable"
2865 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
2868 ## Define "MaxElementArea" hypothesis to give the maximum area of each triangle
2869 # @param area for the maximum area of each triangle
2870 # @param UseExisting if ==true - search existing hypothesis created with
2871 # same parameters, else (default) - create new
2873 # Only for algoType == MEFISTO || NETGEN_2D
2874 def MaxElementArea(self, area, UseExisting=0):
2875 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2876 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
2877 CompareMethod=self.CompareMaxElementArea)
2878 hyp.SetMaxElementArea(area)
2880 elif self.algoType == NETGEN:
2881 print "Netgen 1D-2D algo doesn't support this hypothesis"
2884 ## Check if the given "MaxElementArea" hypothesis has the same parameters as given arguments
2885 def CompareMaxElementArea(self, hyp, args):
2886 return IsEqual(hyp.GetMaxElementArea(), args[0])
2888 ## Define "LengthFromEdges" hypothesis to build triangles
2889 # based on the length of the edges taken from the wire
2891 # Only for algoType == MEFISTO || NETGEN_2D
2892 def LengthFromEdges(self):
2893 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2894 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2896 elif self.algoType == NETGEN:
2897 print "Netgen 1D-2D algo doesn't support this hypothesis"
2901 # @param thePhysicalMesh is:
2902 # DefaultSize or Custom
2903 def SetPhysicalMesh(self, thePhysicalMesh=1):
2904 if self.params == 0:
2906 self.params.SetPhysicalMesh(thePhysicalMesh)
2909 def SetPhySize(self, theVal):
2910 if self.params == 0:
2912 self.params.SetPhySize(theVal)
2914 ## Set GeometricMesh
2915 # @param theGeometricMesh is:
2916 # DefaultGeom or Custom
2917 def SetGeometricMesh(self, theGeometricMesh=0):
2918 if self.params == 0:
2920 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
2921 self.params.SetGeometricMesh(theGeometricMesh)
2923 ## Set AngleMeshS flag
2924 def SetAngleMeshS(self, theVal=_angleMeshS):
2925 if self.params == 0:
2927 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
2928 self.params.SetAngleMeshS(theVal)
2930 ## Set Gradation flag
2931 def SetGradation(self, theVal=_gradation):
2932 if self.params == 0:
2934 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
2935 self.params.SetGradation(theVal)
2937 ## Set QuadAllowed flag
2939 # Only for algoType == NETGEN || NETGEN_2D
2940 def SetQuadAllowed(self, toAllow=True):
2941 if self.algoType == NETGEN_2D:
2942 if toAllow: # add QuadranglePreference
2943 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2944 else: # remove QuadranglePreference
2945 for hyp in self.mesh.GetHypothesisList( self.geom ):
2946 if hyp.GetName() == "QuadranglePreference":
2947 self.mesh.RemoveHypothesis( self.geom, hyp )
2952 if self.params == 0:
2955 self.params.SetQuadAllowed(toAllow)
2958 ## Define "Netgen 2D Parameters" hypothesis
2960 # Only for algoType == NETGEN
2961 def Parameters(self):
2962 if self.algoType == NETGEN:
2963 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
2964 "libNETGENEngine.so", UseExisting=0)
2966 elif self.algoType == MEFISTO:
2967 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
2969 elif self.algoType == NETGEN_2D:
2970 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
2971 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
2973 elif self.algoType == BLSURF:
2974 self.params = self.Hypothesis("BLSURF_Parameters", [],
2975 "libBLSURFEngine.so", UseExisting=0)
2981 # Only for algoType == NETGEN
2982 def SetMaxSize(self, theSize):
2983 if self.params == 0:
2985 if self.params is not None:
2986 self.params.SetMaxSize(theSize)
2988 ## Set SecondOrder flag
2990 # Only for algoType == NETGEN
2991 def SetSecondOrder(self, theVal):
2992 if self.params == 0:
2994 if self.params is not None:
2995 self.params.SetSecondOrder(theVal)
2997 ## Set Optimize flag
2999 # Only for algoType == NETGEN
3000 def SetOptimize(self, theVal):
3001 if self.params == 0:
3003 if self.params is not None:
3004 self.params.SetOptimize(theVal)
3007 # @param theFineness is:
3008 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3010 # Only for algoType == NETGEN
3011 def SetFineness(self, theFineness):
3012 if self.params == 0:
3014 if self.params is not None:
3015 self.params.SetFineness(theFineness)
3019 # Only for algoType == NETGEN
3020 def SetGrowthRate(self, theRate):
3021 if self.params == 0:
3023 if self.params is not None:
3024 self.params.SetGrowthRate(theRate)
3028 # Only for algoType == NETGEN
3029 def SetNbSegPerEdge(self, theVal):
3030 if self.params == 0:
3032 if self.params is not None:
3033 self.params.SetNbSegPerEdge(theVal)
3035 ## Set NbSegPerRadius
3037 # Only for algoType == NETGEN
3038 def SetNbSegPerRadius(self, theVal):
3039 if self.params == 0:
3041 if self.params is not None:
3042 self.params.SetNbSegPerRadius(theVal)
3044 ## Set Decimesh flag
3045 def SetDecimesh(self, toAllow=False):
3046 if self.params == 0:
3048 self.params.SetDecimesh(toAllow)
3053 # Public class: Mesh_Quadrangle
3054 # -----------------------------
3056 ## Class to define a quadrangle 2D algorithm
3059 class Mesh_Quadrangle(Mesh_Algorithm):
3061 ## Private constructor.
3062 def __init__(self, mesh, geom=0):
3063 Mesh_Algorithm.__init__(self)
3064 self.Create(mesh, geom, "Quadrangle_2D")
3066 ## Define "QuadranglePreference" hypothesis, forcing construction
3067 # of quadrangles if the number of nodes on opposite edges is not the same
3068 # in the case where the global number of nodes on edges is even
3069 def QuadranglePreference(self):
3070 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
3071 CompareMethod=self.CompareEqualHyp)
3074 # Public class: Mesh_Tetrahedron
3075 # ------------------------------
3077 ## Class to define a tetrahedron 3D algorithm
3080 class Mesh_Tetrahedron(Mesh_Algorithm):
3085 ## Private constructor.
3086 def __init__(self, mesh, algoType, geom=0):
3087 Mesh_Algorithm.__init__(self)
3089 if algoType == NETGEN:
3090 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
3093 elif algoType == GHS3D:
3095 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
3098 elif algoType == FULL_NETGEN:
3100 print "Warning: NETGENPlugin module has not been imported."
3101 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3104 self.algoType = algoType
3106 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
3107 # @param vol for the maximum volume of each tetrahedral
3108 # @param UseExisting if ==true - search existing hypothesis created with
3109 # same parameters, else (default) - create new
3110 def MaxElementVolume(self, vol, UseExisting=0):
3111 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
3112 CompareMethod=self.CompareMaxElementVolume)
3113 hyp.SetMaxElementVolume(vol)
3116 ## Check if the given "MaxElementVolume" hypothesis has the same parameters as given arguments
3117 def CompareMaxElementVolume(self, hyp, args):
3118 return IsEqual(hyp.GetMaxElementVolume(), args[0])
3120 ## Define "Netgen 3D Parameters" hypothesis
3121 def Parameters(self):
3122 if (self.algoType == FULL_NETGEN):
3123 self.params = self.Hypothesis("NETGEN_Parameters", [],
3124 "libNETGENEngine.so", UseExisting=0)
3127 print "Algo doesn't support this hypothesis"
3131 def SetMaxSize(self, theSize):
3132 if self.params == 0:
3134 self.params.SetMaxSize(theSize)
3136 ## Set SecondOrder flag
3137 def SetSecondOrder(self, theVal):
3138 if self.params == 0:
3140 self.params.SetSecondOrder(theVal)
3142 ## Set Optimize flag
3143 def SetOptimize(self, theVal):
3144 if self.params == 0:
3146 self.params.SetOptimize(theVal)
3149 # @param theFineness is:
3150 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
3151 def SetFineness(self, theFineness):
3152 if self.params == 0:
3154 self.params.SetFineness(theFineness)
3157 def SetGrowthRate(self, theRate):
3158 if self.params == 0:
3160 self.params.SetGrowthRate(theRate)
3163 def SetNbSegPerEdge(self, theVal):
3164 if self.params == 0:
3166 self.params.SetNbSegPerEdge(theVal)
3168 ## Set NbSegPerRadius
3169 def SetNbSegPerRadius(self, theVal):
3170 if self.params == 0:
3172 self.params.SetNbSegPerRadius(theVal)
3174 # Public class: Mesh_Hexahedron
3175 # ------------------------------
3177 ## Class to define a hexahedron 3D algorithm
3180 class Mesh_Hexahedron(Mesh_Algorithm):
3185 ## Private constructor.
3186 def __init__(self, mesh, algoType=Hexa, geom=0):
3187 Mesh_Algorithm.__init__(self)
3189 self.algoType = algoType
3191 if algoType == Hexa:
3192 self.Create(mesh, geom, "Hexa_3D")
3195 elif algoType == Hexotic:
3196 import HexoticPlugin
3197 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
3200 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
3201 def MinMaxQuad(self, min=3, max=8, quad=True):
3202 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
3204 self.params.SetHexesMinLevel(min)
3205 self.params.SetHexesMaxLevel(max)
3206 self.params.SetHexoticQuadrangles(quad)
3209 # Deprecated, only for compatibility!
3210 # Public class: Mesh_Netgen
3211 # ------------------------------
3213 ## Class to define a NETGEN-based 2D or 3D algorithm
3214 # that need no discrete boundary (i.e. independent)
3216 # This class is deprecated, only for compatibility!
3219 class Mesh_Netgen(Mesh_Algorithm):
3223 ## Private constructor.
3224 def __init__(self, mesh, is3D, geom=0):
3225 Mesh_Algorithm.__init__(self)
3228 print "Warning: NETGENPlugin module has not been imported."
3232 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3236 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3239 ## Define hypothesis containing parameters of the algorithm
3240 def Parameters(self):
3242 hyp = self.Hypothesis("NETGEN_Parameters", [],
3243 "libNETGENEngine.so", UseExisting=0)
3245 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
3246 "libNETGENEngine.so", UseExisting=0)
3249 # Public class: Mesh_Projection1D
3250 # ------------------------------
3252 ## Class to define a projection 1D algorithm
3255 class Mesh_Projection1D(Mesh_Algorithm):
3256 ## Private constructor.
3257 def __init__(self, mesh, geom=0):
3258 Mesh_Algorithm.__init__(self)
3259 self.Create(mesh, geom, "Projection_1D")
3261 ## Define "Source Edge" hypothesis, specifying a meshed edge to
3262 # take a mesh pattern from, and optionally association of vertices
3263 # between the source edge and a target one (where a hipothesis is assigned to)
3264 # @param edge to take nodes distribution from
3265 # @param mesh to take nodes distribution from (optional)
3266 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
3267 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
3268 # to associate with \a srcV (optional)
3269 # @param UseExisting if ==true - search existing hypothesis created with
3270 # same parameters, else (default) - create new
3271 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
3272 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
3274 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
3275 hyp.SetSourceEdge( edge )
3276 if not mesh is None and isinstance(mesh, Mesh):
3277 mesh = mesh.GetMesh()
3278 hyp.SetSourceMesh( mesh )
3279 hyp.SetVertexAssociation( srcV, tgtV )
3282 ## Check if the given "SourceEdge" hypothesis has the same parameters as given arguments
3283 #def CompareSourceEdge(self, hyp, args):
3284 # # seems to be not really useful to reuse existing "SourceEdge" hypothesis
3288 # Public class: Mesh_Projection2D
3289 # ------------------------------
3291 ## Class to define a projection 2D algorithm
3294 class Mesh_Projection2D(Mesh_Algorithm):
3296 ## Private constructor.
3297 def __init__(self, mesh, geom=0):
3298 Mesh_Algorithm.__init__(self)
3299 self.Create(mesh, geom, "Projection_2D")
3300 ## Define "Source Face" hypothesis, specifying a meshed face to
3301 # take a mesh pattern from, and optionally association of vertices
3302 # between the source face and a target one (where a hipothesis is assigned to)
3303 # @param face to take mesh pattern from
3304 # @param mesh to take mesh pattern from (optional)
3305 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
3306 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
3307 # to associate with \a srcV1 (optional)
3308 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
3309 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
3310 # to associate with \a srcV2 (optional)
3311 # @param UseExisting if ==true - search existing hypothesis created with
3312 # same parameters, else (default) - create new
3314 # Note: association vertices must belong to one edge of a face
3315 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
3316 srcV2=None, tgtV2=None, UseExisting=0):
3317 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
3319 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
3320 hyp.SetSourceFace( face )
3321 if not mesh is None and isinstance(mesh, Mesh):
3322 mesh = mesh.GetMesh()
3323 hyp.SetSourceMesh( mesh )
3324 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3327 ## Check if the given "SourceFace" hypothesis has the same parameters as given arguments
3328 #def CompareSourceFace(self, hyp, args):
3329 # # seems to be not really useful to reuse existing "SourceFace" hypothesis
3332 # Public class: Mesh_Projection3D
3333 # ------------------------------
3335 ## Class to define a projection 3D algorithm
3338 class Mesh_Projection3D(Mesh_Algorithm):
3340 ## Private constructor.
3341 def __init__(self, mesh, geom=0):
3342 Mesh_Algorithm.__init__(self)
3343 self.Create(mesh, geom, "Projection_3D")
3345 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
3346 # take a mesh pattern from, and optionally association of vertices
3347 # between the source solid and a target one (where a hipothesis is assigned to)
3348 # @param solid to take mesh pattern from
3349 # @param mesh to take mesh pattern from (optional)
3350 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
3351 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
3352 # to associate with \a srcV1 (optional)
3353 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
3354 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
3355 # to associate with \a srcV2 (optional)
3356 # @param UseExisting - if ==true - search existing hypothesis created with
3357 # same parameters, else (default) - create new
3359 # Note: association vertices must belong to one edge of a solid
3360 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
3361 srcV2=0, tgtV2=0, UseExisting=0):
3362 hyp = self.Hypothesis("ProjectionSource3D",
3363 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
3365 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
3366 hyp.SetSource3DShape( solid )
3367 if not mesh is None and isinstance(mesh, Mesh):
3368 mesh = mesh.GetMesh()
3369 hyp.SetSourceMesh( mesh )
3370 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3373 ## Check if the given "SourceShape3D" hypothesis has the same parameters as given arguments
3374 #def CompareSourceShape3D(self, hyp, args):
3375 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
3379 # Public class: Mesh_Prism
3380 # ------------------------
3382 ## Class to define a 3D extrusion algorithm
3385 class Mesh_Prism3D(Mesh_Algorithm):
3387 ## Private constructor.
3388 def __init__(self, mesh, geom=0):
3389 Mesh_Algorithm.__init__(self)
3390 self.Create(mesh, geom, "Prism_3D")
3392 # Public class: Mesh_RadialPrism
3393 # -------------------------------
3395 ## Class to define a Radial Prism 3D algorithm
3398 class Mesh_RadialPrism3D(Mesh_Algorithm):
3400 ## Private constructor.
3401 def __init__(self, mesh, geom=0):
3402 Mesh_Algorithm.__init__(self)
3403 self.Create(mesh, geom, "RadialPrism_3D")
3405 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
3406 self.nbLayers = None
3408 ## Return 3D hypothesis holding the 1D one
3409 def Get3DHypothesis(self):
3410 return self.distribHyp
3412 ## Private method creating 1D hypothes and storing it in the LayerDistribution
3413 # hypothes. Returns the created hypothes
3414 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
3415 #print "OwnHypothesis",hypType
3416 if not self.nbLayers is None:
3417 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
3418 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
3419 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
3420 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
3421 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
3422 self.distribHyp.SetLayerDistribution( hyp )
3425 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
3426 # prisms to build between the inner and outer shells
3427 # @param UseExisting if ==true - search existing hypothesis created with
3428 # same parameters, else (default) - create new
3429 def NumberOfLayers(self, n, UseExisting=0):
3430 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
3431 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
3432 CompareMethod=self.CompareNumberOfLayers)
3433 self.nbLayers.SetNumberOfLayers( n )
3434 return self.nbLayers
3436 ## Check if the given "NumberOfLayers" hypothesis has the same parameters as given arguments
3437 def CompareNumberOfLayers(self, hyp, args):
3438 return IsEqual(hyp.GetNumberOfLayers(), args[0])
3440 ## Define "LocalLength" hypothesis, specifying segment length
3441 # to build between the inner and outer shells
3442 # @param l for the length of segments
3443 # @param p for the precision of rounding
3444 def LocalLength(self, l, p=1e-07):
3445 hyp = self.OwnHypothesis("LocalLength", [l,p])
3450 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
3451 # prisms to build between the inner and outer shells
3452 # @param n for the number of segments
3453 # @param s for the scale factor (optional)
3454 def NumberOfSegments(self, n, s=[]):
3456 hyp = self.OwnHypothesis("NumberOfSegments", [n])
3458 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
3459 hyp.SetDistrType( 1 )
3460 hyp.SetScaleFactor(s)
3461 hyp.SetNumberOfSegments(n)
3464 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
3465 # to build between the inner and outer shells as arithmetic length increasing
3466 # @param start for the length of the first segment
3467 # @param end for the length of the last segment
3468 def Arithmetic1D(self, start, end ):
3469 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
3470 hyp.SetLength(start, 1)
3471 hyp.SetLength(end , 0)
3474 ## Define "StartEndLength" hypothesis, specifying distribution of segments
3475 # to build between the inner and outer shells as geometric length increasing
3476 # @param start for the length of the first segment
3477 # @param end for the length of the last segment
3478 def StartEndLength(self, start, end):
3479 hyp = self.OwnHypothesis("StartEndLength", [start, end])
3480 hyp.SetLength(start, 1)
3481 hyp.SetLength(end , 0)
3484 ## Define "AutomaticLength" hypothesis, specifying number of segments
3485 # to build between the inner and outer shells
3486 # @param fineness for the fineness [0-1]
3487 def AutomaticLength(self, fineness=0):
3488 hyp = self.OwnHypothesis("AutomaticLength")
3489 hyp.SetFineness( fineness )
3492 # Private class: Mesh_UseExisting
3493 # -------------------------------
3494 class Mesh_UseExisting(Mesh_Algorithm):
3496 def __init__(self, dim, mesh, geom=0):
3498 self.Create(mesh, geom, "UseExisting_1D")
3500 self.Create(mesh, geom, "UseExisting_2D")