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
32 import SMESH # necessary for back compatibility
39 # import NETGENPlugin module if possible
58 NETGEN_1D2D3D = FULL_NETGEN
59 NETGEN_FULL = FULL_NETGEN
64 # MirrorType enumeration
65 POINT = SMESH_MeshEditor.POINT
66 AXIS = SMESH_MeshEditor.AXIS
67 PLANE = SMESH_MeshEditor.PLANE
69 # Smooth_Method enumeration
70 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
71 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
73 # Fineness enumeration(for NETGEN)
81 PrecisionConfusion = 1e-07
83 def IsEqual(val1, val2, tol=PrecisionConfusion):
84 if abs(val1 - val2) < tol:
92 ior = salome.orb.object_to_string(obj)
93 sobj = salome.myStudy.FindObjectIOR(ior)
97 attr = sobj.FindAttribute("AttributeName")[1]
100 ## Sets name to object
101 def SetName(obj, name):
102 ior = salome.orb.object_to_string(obj)
103 sobj = salome.myStudy.FindObjectIOR(ior)
105 attr = sobj.FindAttribute("AttributeName")[1]
108 ## Print error message if a hypothesis was not assigned.
109 def TreatHypoStatus(status, hypName, geomName, isAlgo):
111 hypType = "algorithm"
113 hypType = "hypothesis"
115 if status == HYP_UNKNOWN_FATAL :
116 reason = "for unknown reason"
117 elif status == HYP_INCOMPATIBLE :
118 reason = "this hypothesis mismatches algorithm"
119 elif status == HYP_NOTCONFORM :
120 reason = "not conform mesh would be built"
121 elif status == HYP_ALREADY_EXIST :
122 reason = hypType + " of the same dimension already assigned to this shape"
123 elif status == HYP_BAD_DIM :
124 reason = hypType + " mismatches shape"
125 elif status == HYP_CONCURENT :
126 reason = "there are concurrent hypotheses on sub-shapes"
127 elif status == HYP_BAD_SUBSHAPE :
128 reason = "shape is neither the main one, nor its subshape, nor a valid group"
129 elif status == HYP_BAD_GEOMETRY:
130 reason = "geometry mismatches algorithm's expectation"
131 elif status == HYP_HIDDEN_ALGO:
132 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
133 elif status == HYP_HIDING_ALGO:
134 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
137 hypName = '"' + hypName + '"'
138 geomName= '"' + geomName+ '"'
139 if status < HYP_UNKNOWN_FATAL:
140 print hypName, "was assigned to", geomName,"but", reason
142 print hypName, "was not assigned to",geomName,":", reason
145 class smeshDC(SMESH._objref_SMESH_Gen):
147 def init_smesh(self,theStudy,geompyD):
149 self.SetGeomEngine(geompyD)
150 self.SetCurrentStudy(theStudy)
152 def Mesh(self, obj=0, name=0):
153 return Mesh(self,self.geompyD,obj,name)
155 ## Returns long value from enumeration
156 # Uses for SMESH.FunctorType enumeration
157 def EnumToLong(self,theItem):
160 ## Get PointStruct from vertex
161 # @param theVertex is GEOM object(vertex)
162 # @return SMESH.PointStruct
163 def GetPointStruct(self,theVertex):
164 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
165 return PointStruct(x,y,z)
167 ## Get DirStruct from vector
168 # @param theVector is GEOM object(vector)
169 # @return SMESH.DirStruct
170 def GetDirStruct(self,theVector):
171 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
172 if(len(vertices) != 2):
173 print "Error: vector object is incorrect."
175 p1 = self.geompyD.PointCoordinates(vertices[0])
176 p2 = self.geompyD.PointCoordinates(vertices[1])
177 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
178 dirst = DirStruct(pnt)
181 ## Make DirStruct from a triplet
182 # @param x,y,z are vector components
183 # @return SMESH.DirStruct
184 def MakeDirStruct(self,x,y,z):
185 pnt = PointStruct(x,y,z)
186 return DirStruct(pnt)
188 ## Get AxisStruct from object
189 # @param theObj is GEOM object(line or plane)
190 # @return SMESH.AxisStruct
191 def GetAxisStruct(self,theObj):
192 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
194 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
195 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
196 vertex1 = self.geompyD.PointCoordinates(vertex1)
197 vertex2 = self.geompyD.PointCoordinates(vertex2)
198 vertex3 = self.geompyD.PointCoordinates(vertex3)
199 vertex4 = self.geompyD.PointCoordinates(vertex4)
200 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
201 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
202 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] ]
203 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
205 elif len(edges) == 1:
206 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
207 p1 = self.geompyD.PointCoordinates( vertex1 )
208 p2 = self.geompyD.PointCoordinates( vertex2 )
209 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
213 # From SMESH_Gen interface:
214 # ------------------------
216 ## Set the current mode
217 def SetEmbeddedMode( self,theMode ):
218 #self.SetEmbeddedMode(theMode)
219 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
221 ## Get the current mode
222 def IsEmbeddedMode(self):
223 #return self.IsEmbeddedMode()
224 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
226 ## Set the current study
227 def SetCurrentStudy( self, theStudy ):
228 #self.SetCurrentStudy(theStudy)
229 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
231 ## Get the current study
232 def GetCurrentStudy(self):
233 #return self.GetCurrentStudy()
234 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
236 ## Create Mesh object importing data from given UNV file
237 # @return an instance of Mesh class
238 def CreateMeshesFromUNV( self,theFileName ):
239 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
240 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
243 ## Create Mesh object(s) importing data from given MED file
244 # @return a list of Mesh class instances
245 def CreateMeshesFromMED( self,theFileName ):
246 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
248 for iMesh in range(len(aSmeshMeshes)) :
249 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
250 aMeshes.append(aMesh)
251 return aMeshes, aStatus
253 ## Create Mesh object importing data from given STL file
254 # @return an instance of Mesh class
255 def CreateMeshesFromSTL( self, theFileName ):
256 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
257 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
260 ## From SMESH_Gen interface
261 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
262 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
264 ## From SMESH_Gen interface. Creates pattern
265 def GetPattern(self):
266 return SMESH._objref_SMESH_Gen.GetPattern(self)
270 # Filtering. Auxiliary functions:
271 # ------------------------------
273 ## Creates an empty criterion
274 # @return SMESH.Filter.Criterion
275 def GetEmptyCriterion(self):
276 Type = self.EnumToLong(FT_Undefined)
277 Compare = self.EnumToLong(FT_Undefined)
281 UnaryOp = self.EnumToLong(FT_Undefined)
282 BinaryOp = self.EnumToLong(FT_Undefined)
285 Precision = -1 ##@1e-07
286 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
287 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
289 ## Creates a criterion by given parameters
290 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
291 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
292 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
293 # @param Treshold is threshold value (range of ids as string, shape, numeric)
294 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
295 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
296 # FT_Undefined(must be for the last criterion in criteria)
297 # @return SMESH.Filter.Criterion
298 def GetCriterion(self,elementType,
300 Compare = FT_EqualTo,
302 UnaryOp=FT_Undefined,
303 BinaryOp=FT_Undefined):
304 aCriterion = self.GetEmptyCriterion()
305 aCriterion.TypeOfElement = elementType
306 aCriterion.Type = self.EnumToLong(CritType)
310 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
311 aCriterion.Compare = self.EnumToLong(Compare)
312 elif Compare == "=" or Compare == "==":
313 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
315 aCriterion.Compare = self.EnumToLong(FT_LessThan)
317 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
319 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
322 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
323 FT_BelongToCylinder, FT_LyingOnGeom]:
325 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
326 aCriterion.ThresholdStr = GetName(aTreshold)
327 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
329 print "Error: Treshold should be a shape."
331 elif CritType == FT_RangeOfIds:
333 if isinstance(aTreshold, str):
334 aCriterion.ThresholdStr = aTreshold
336 print "Error: Treshold should be a string."
338 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
339 # Here we do not need treshold
340 if aTreshold == FT_LogicalNOT:
341 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
342 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
343 aCriterion.BinaryOp = aTreshold
347 aTreshold = float(aTreshold)
348 aCriterion.Threshold = aTreshold
350 print "Error: Treshold should be a number."
353 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
354 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
356 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
357 aCriterion.BinaryOp = self.EnumToLong(Treshold)
359 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
360 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
362 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
363 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
367 ## Creates filter by given parameters of criterion
368 # @param elementType is the type of elements in the group
369 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
370 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
371 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
372 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
373 # @return SMESH_Filter
374 def GetFilter(self,elementType,
375 CritType=FT_Undefined,
378 UnaryOp=FT_Undefined):
379 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
380 aFilterMgr = self.CreateFilterManager()
381 aFilter = aFilterMgr.CreateFilter()
383 aCriteria.append(aCriterion)
384 aFilter.SetCriteria(aCriteria)
387 ## Creates numerical functor by its type
388 # @param theCrierion is FT_...; functor type
389 # @return SMESH_NumericalFunctor
390 def GetFunctor(self,theCriterion):
391 aFilterMgr = self.CreateFilterManager()
392 if theCriterion == FT_AspectRatio:
393 return aFilterMgr.CreateAspectRatio()
394 elif theCriterion == FT_AspectRatio3D:
395 return aFilterMgr.CreateAspectRatio3D()
396 elif theCriterion == FT_Warping:
397 return aFilterMgr.CreateWarping()
398 elif theCriterion == FT_MinimumAngle:
399 return aFilterMgr.CreateMinimumAngle()
400 elif theCriterion == FT_Taper:
401 return aFilterMgr.CreateTaper()
402 elif theCriterion == FT_Skew:
403 return aFilterMgr.CreateSkew()
404 elif theCriterion == FT_Area:
405 return aFilterMgr.CreateArea()
406 elif theCriterion == FT_Volume3D:
407 return aFilterMgr.CreateVolume3D()
408 elif theCriterion == FT_MultiConnection:
409 return aFilterMgr.CreateMultiConnection()
410 elif theCriterion == FT_MultiConnection2D:
411 return aFilterMgr.CreateMultiConnection2D()
412 elif theCriterion == FT_Length:
413 return aFilterMgr.CreateLength()
414 elif theCriterion == FT_Length2D:
415 return aFilterMgr.CreateLength2D()
417 print "Error: given parameter is not numerucal functor type."
420 #Register the new proxy for SMESH_Gen
421 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
427 ## Class to define a mesh
429 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
439 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
440 # sets GUI name of this mesh to \a name.
441 # @param obj Shape to be meshed or SMESH_Mesh object
442 # @param name Study name of the mesh
443 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
444 self.smeshpyD=smeshpyD
449 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
451 self.mesh = self.smeshpyD.CreateMesh(self.geom)
452 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
455 self.mesh = self.smeshpyD.CreateEmptyMesh()
457 SetName(self.mesh, name)
459 SetName(self.mesh, GetName(obj))
461 self.editor = self.mesh.GetMeshEditor()
463 ## Method that inits the Mesh object from SMESH_Mesh interface
464 # @param theMesh is SMESH_Mesh object
465 def SetMesh(self, theMesh):
467 self.geom = self.mesh.GetShapeToMesh()
469 ## Method that returns the mesh
470 # @return SMESH_Mesh object
476 name = GetName(self.GetMesh())
480 def SetName(self, name):
481 SetName(self.GetMesh(), name)
483 ## Get the subMesh object associated to a subShape. The subMesh object
484 # gives access to nodes and elements IDs.
485 # \n SubMesh will be used instead of SubShape in a next idl version to
486 # adress a specific subMesh...
487 def GetSubMesh(self, theSubObject, name):
488 submesh = self.mesh.GetSubMesh(theSubObject, name)
491 ## Method that returns the shape associated to the mesh
492 # @return GEOM_Object
496 ## Method that associates given shape to the mesh(entails the mesh recreation)
497 # @param geom shape to be meshed(GEOM_Object)
498 def SetShape(self, geom):
499 self.mesh = self.smeshpyD.CreateMesh(geom)
501 ## Return true if hypotheses are defined well
502 # @param theMesh is an instance of Mesh class
503 # @param theSubObject subshape of a mesh shape
504 def IsReadyToCompute(self, theSubObject):
505 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
507 ## Return errors of hypotheses definintion
508 # error list is empty if everything is OK
509 # @param theMesh is an instance of Mesh class
510 # @param theSubObject subshape of a mesh shape
511 # @return a list of errors
512 def GetAlgoState(self, theSubObject):
513 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
515 ## Return geometrical object the given element is built on.
516 # The returned geometrical object, if not nil, is either found in the
517 # study or is published by this method with the given name
518 # @param theMesh is an instance of Mesh class
519 # @param theElementID an id of the mesh element
520 # @param theGeomName user defined name of geometrical object
521 # @return GEOM::GEOM_Object instance
522 def GetGeometryByMeshElement(self, theElementID, theGeomName):
523 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
525 ## Returns mesh dimension depending on shape one
526 def MeshDimension(self):
527 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
528 if len( shells ) > 0 :
530 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
532 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
538 ## Creates a segment discretization 1D algorithm.
539 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
540 # If the optional \a geom parameter is not sets, this algorithm is global.
541 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
542 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
543 # @param geom If defined, subshape to be meshed
544 def Segment(self, algo=REGULAR, geom=0):
545 ## if Segment(geom) is called by mistake
546 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
547 algo, geom = geom, algo
548 if not algo: algo = REGULAR
551 return Mesh_Segment(self, geom)
553 return Mesh_Segment_Python(self, geom)
554 elif algo == COMPOSITE:
555 return Mesh_CompositeSegment(self, geom)
557 return Mesh_Segment(self, geom)
559 ## Enable creation of nodes and segments usable by 2D algoritms.
560 # Added nodes and segments must be bound to edges and vertices by
561 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
562 # If the optional \a geom parameter is not sets, this algorithm is global.
563 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
564 # @param geom subshape to be manually meshed
565 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
566 def UseExistingSegments(self, geom=0):
567 algo = Mesh_UseExisting(1,self,geom)
568 return algo.GetAlgorithm()
570 ## Enable creation of nodes and faces usable by 3D algoritms.
571 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
572 # and SetMeshElementOnShape()
573 # If the optional \a geom parameter is not sets, this algorithm is global.
574 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
575 # @param geom subshape to be manually meshed
576 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
577 def UseExistingFaces(self, geom=0):
578 algo = Mesh_UseExisting(2,self,geom)
579 return algo.GetAlgorithm()
581 ## Creates a triangle 2D algorithm for faces.
582 # If the optional \a geom parameter is not sets, this algorithm is global.
583 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
584 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
585 # @param geom If defined, subshape to be meshed
586 def Triangle(self, algo=MEFISTO, geom=0):
587 ## if Triangle(geom) is called by mistake
588 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
592 return Mesh_Triangle(self, algo, geom)
594 ## Creates a quadrangle 2D algorithm for faces.
595 # If the optional \a geom parameter is not sets, this algorithm is global.
596 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
597 # @param geom If defined, subshape to be meshed
598 def Quadrangle(self, geom=0):
599 return Mesh_Quadrangle(self, geom)
601 ## Creates a tetrahedron 3D algorithm for solids.
602 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
603 # If the optional \a geom parameter is not sets, this algorithm is global.
604 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
605 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
606 # @param geom If defined, subshape to be meshed
607 def Tetrahedron(self, algo=NETGEN, geom=0):
608 ## if Tetrahedron(geom) is called by mistake
609 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
610 algo, geom = geom, algo
611 if not algo: algo = NETGEN
613 return Mesh_Tetrahedron(self, algo, geom)
615 ## Creates a hexahedron 3D algorithm for solids.
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 geom If defined, subshape to be meshed
619 ## def Hexahedron(self, geom=0):
620 ## return Mesh_Hexahedron(self, geom)
621 def Hexahedron(self, algo=Hexa, geom=0):
622 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
623 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
624 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
625 elif geom == 0: algo, geom = Hexa, algo
626 return Mesh_Hexahedron(self, algo, geom)
628 ## Deprecated, only for compatibility!
629 def Netgen(self, is3D, geom=0):
630 return Mesh_Netgen(self, is3D, geom)
632 ## Creates a projection 1D algorithm for edges.
633 # If the optional \a geom parameter is not sets, this algorithm is global.
634 # Otherwise, this algorithm define a submesh based on \a geom subshape.
635 # @param geom If defined, subshape to be meshed
636 def Projection1D(self, geom=0):
637 return Mesh_Projection1D(self, geom)
639 ## Creates a projection 2D algorithm for faces.
640 # If the optional \a geom parameter is not sets, this algorithm is global.
641 # Otherwise, this algorithm define a submesh based on \a geom subshape.
642 # @param geom If defined, subshape to be meshed
643 def Projection2D(self, geom=0):
644 return Mesh_Projection2D(self, geom)
646 ## Creates a projection 3D algorithm for solids.
647 # If the optional \a geom parameter is not sets, this algorithm is global.
648 # Otherwise, this algorithm define a submesh based on \a geom subshape.
649 # @param geom If defined, subshape to be meshed
650 def Projection3D(self, geom=0):
651 return Mesh_Projection3D(self, geom)
653 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
654 # If the optional \a geom parameter is not sets, this algorithm is global.
655 # Otherwise, this algorithm define a submesh based on \a geom subshape.
656 # @param geom If defined, subshape to be meshed
657 def Prism(self, geom=0):
661 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
662 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
663 if nbSolids == 0 or nbSolids == nbShells:
664 return Mesh_Prism3D(self, geom)
665 return Mesh_RadialPrism3D(self, geom)
667 ## Compute the mesh and return the status of the computation
668 def Compute(self, geom=0):
669 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
671 print "Compute impossible: mesh is not constructed on geom shape."
677 ok = self.smeshpyD.Compute(self.mesh, geom)
678 except SALOME.SALOME_Exception, ex:
679 print "Mesh computation failed, exception caught:"
680 print " ", ex.details.text
683 print "Mesh computation failed, exception caught:"
684 traceback.print_exc()
686 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
697 reason = '%s %sD algorithm is missing' % (glob, dim)
698 elif err.state == HYP_MISSING:
699 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
700 % (glob, dim, name, dim))
701 elif err.state == HYP_NOTCONFORM:
702 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
703 elif err.state == HYP_BAD_PARAMETER:
704 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
705 % ( glob, dim, name ))
706 elif err.state == HYP_BAD_GEOMETRY:
707 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
708 'its expectation' % ( glob, dim, name ))
710 reason = "For unknown reason."+\
711 " Revise Mesh.Compute() implementation in smeshDC.py!"
719 print '"' + GetName(self.mesh) + '"',"has not been computed:"
722 print '"' + GetName(self.mesh) + '"',"has not been computed."
725 if salome.sg.hasDesktop():
726 smeshgui = salome.ImportComponentGUI("SMESH")
727 smeshgui.Init(salome.myStudyId)
728 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
729 salome.sg.updateObjBrowser(1)
733 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
734 # The parameter \a fineness [0,-1] defines mesh fineness
735 def AutomaticTetrahedralization(self, fineness=0):
736 dim = self.MeshDimension()
738 self.RemoveGlobalHypotheses()
739 self.Segment().AutomaticLength(fineness)
741 self.Triangle().LengthFromEdges()
744 self.Tetrahedron(NETGEN)
746 return self.Compute()
748 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
749 # The parameter \a fineness [0,-1] defines mesh fineness
750 def AutomaticHexahedralization(self, fineness=0):
751 dim = self.MeshDimension()
753 self.RemoveGlobalHypotheses()
754 self.Segment().AutomaticLength(fineness)
761 return self.Compute()
764 # @param hyp is a hypothesis to assign
765 # @param geom is subhape of mesh geometry
766 def AddHypothesis(self, hyp, geom=0):
767 if isinstance( hyp, Mesh_Algorithm ):
768 hyp = hyp.GetAlgorithm()
773 status = self.mesh.AddHypothesis(geom, hyp)
774 isAlgo = hyp._narrow( SMESH_Algo )
775 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
778 ## Unassign hypothesis
779 # @param hyp is a hypothesis to unassign
780 # @param geom is subhape of mesh geometry
781 def RemoveHypothesis(self, hyp, geom=0):
782 if isinstance( hyp, Mesh_Algorithm ):
783 hyp = hyp.GetAlgorithm()
788 status = self.mesh.RemoveHypothesis(geom, hyp)
791 ## Get the list of hypothesis added on a geom
792 # @param geom is subhape of mesh geometry
793 def GetHypothesisList(self, geom):
794 return self.mesh.GetHypothesisList( geom )
796 ## Removes all global hypotheses
797 def RemoveGlobalHypotheses(self):
798 current_hyps = self.mesh.GetHypothesisList( self.geom )
799 for hyp in current_hyps:
800 self.mesh.RemoveHypothesis( self.geom, hyp )
804 ## Create a mesh group based on geometric object \a grp
805 # and give a \a name, \n if this parameter is not defined
806 # the name is the same as the geometric group name \n
807 # Note: Works like GroupOnGeom().
808 # @param grp is a geometric group, a vertex, an edge, a face or a solid
809 # @param name is the name of the mesh group
810 # @return SMESH_GroupOnGeom
811 def Group(self, grp, name=""):
812 return self.GroupOnGeom(grp, name)
814 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
815 # Export the mesh in a file with the MED format and choice the \a version of MED format
816 # @param f is the file name
817 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
818 def ExportToMED(self, f, version, opt=0):
819 self.mesh.ExportToMED(f, opt, version)
821 ## Export the mesh in a file with the MED format
822 # @param f is the file name
823 # @param auto_groups boolean parameter for creating/not creating
824 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
825 # the typical use is auto_groups=false.
826 # @param version MED format version(MED_V2_1 or MED_V2_2)
827 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
828 self.mesh.ExportToMED(f, auto_groups, version)
830 ## Export the mesh in a file with the DAT format
831 # @param f is the file name
832 def ExportDAT(self, f):
833 self.mesh.ExportDAT(f)
835 ## Export the mesh in a file with the UNV format
836 # @param f is the file name
837 def ExportUNV(self, f):
838 self.mesh.ExportUNV(f)
840 ## Export the mesh in a file with the STL format
841 # @param f is the file name
842 # @param ascii defined the kind of file contents
843 def ExportSTL(self, f, ascii=1):
844 self.mesh.ExportSTL(f, ascii)
847 # Operations with groups:
848 # ----------------------
850 ## Creates an empty mesh group
851 # @param elementType is the type of elements in the group
852 # @param name is the name of the mesh group
853 # @return SMESH_Group
854 def CreateEmptyGroup(self, elementType, name):
855 return self.mesh.CreateGroup(elementType, name)
857 ## Creates a mesh group based on geometric object \a grp
858 # and give a \a name, \n if this parameter is not defined
859 # the name is the same as the geometric group name
860 # @param grp is a geometric group, a vertex, an edge, a face or a solid
861 # @param name is the name of the mesh group
862 # @return SMESH_GroupOnGeom
863 def GroupOnGeom(self, grp, name="", typ=None):
868 tgeo = str(grp.GetShapeType())
875 elif tgeo == "SOLID":
877 elif tgeo == "SHELL":
879 elif tgeo == "COMPOUND":
880 if len( self.geompyD.GetObjectIDs( grp )) == 0:
881 print "Mesh.Group: empty geometric group", GetName( grp )
883 tgeo = self.geompyD.GetType(grp)
884 if tgeo == geompyDC.ShapeType["VERTEX"]:
886 elif tgeo == geompyDC.ShapeType["EDGE"]:
888 elif tgeo == geompyDC.ShapeType["FACE"]:
890 elif tgeo == geompyDC.ShapeType["SOLID"]:
894 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
897 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
899 ## Create a mesh group by the given ids of elements
900 # @param groupName is the name of the mesh group
901 # @param elementType is the type of elements in the group
902 # @param elemIDs is the list of ids
903 # @return SMESH_Group
904 def MakeGroupByIds(self, groupName, elementType, elemIDs):
905 group = self.mesh.CreateGroup(elementType, groupName)
909 ## Create a mesh group by the given conditions
910 # @param groupName is the name of the mesh group
911 # @param elementType is the type of elements in the group
912 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
913 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
914 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
915 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
916 # @return SMESH_Group
920 CritType=FT_Undefined,
923 UnaryOp=FT_Undefined):
924 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
925 group = self.MakeGroupByCriterion(groupName, aCriterion)
928 ## Create a mesh group by the given criterion
929 # @param groupName is the name of the mesh group
930 # @param Criterion is the instance of Criterion class
931 # @return SMESH_Group
932 def MakeGroupByCriterion(self, groupName, Criterion):
933 aFilterMgr = self.smeshpyD.CreateFilterManager()
934 aFilter = aFilterMgr.CreateFilter()
936 aCriteria.append(Criterion)
937 aFilter.SetCriteria(aCriteria)
938 group = self.MakeGroupByFilter(groupName, aFilter)
941 ## Create a mesh group by the given criteria(list of criterions)
942 # @param groupName is the name of the mesh group
943 # @param Criteria is the list of criterions
944 # @return SMESH_Group
945 def MakeGroupByCriteria(self, groupName, theCriteria):
946 aFilterMgr = self.smeshpyD.CreateFilterManager()
947 aFilter = aFilterMgr.CreateFilter()
948 aFilter.SetCriteria(theCriteria)
949 group = self.MakeGroupByFilter(groupName, aFilter)
952 ## Create a mesh group by the given filter
953 # @param groupName is the name of the mesh group
954 # @param Criterion is the instance of Filter class
955 # @return SMESH_Group
956 def MakeGroupByFilter(self, groupName, theFilter):
957 anIds = theFilter.GetElementsId(self.mesh)
958 anElemType = theFilter.GetElementType()
959 group = self.MakeGroupByIds(groupName, anElemType, anIds)
962 ## Pass mesh elements through the given filter and return ids
963 # @param theFilter is SMESH_Filter
964 # @return list of ids
965 def GetIdsFromFilter(self, theFilter):
966 return theFilter.GetElementsId(self.mesh)
968 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
969 # Returns list of special structures(borders).
970 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
971 def GetFreeBorders(self):
972 aFilterMgr = self.smeshpyD.CreateFilterManager()
973 aPredicate = aFilterMgr.CreateFreeEdges()
974 aPredicate.SetMesh(self.mesh)
975 aBorders = aPredicate.GetBorders()
979 def RemoveGroup(self, group):
980 self.mesh.RemoveGroup(group)
982 ## Remove group with its contents
983 def RemoveGroupWithContents(self, group):
984 self.mesh.RemoveGroupWithContents(group)
986 ## Get the list of groups existing in the mesh
988 return self.mesh.GetGroups()
990 ## Get number of groups existing in the mesh
992 return self.mesh.NbGroups()
994 ## Get the list of names of groups existing in the mesh
995 def GetGroupNames(self):
996 groups = self.GetGroups()
999 names.append(group.GetName())
1002 ## Union of two groups
1003 # New group is created. All mesh elements that are
1004 # present in initial groups are added to the new one
1005 def UnionGroups(self, group1, group2, name):
1006 return self.mesh.UnionGroups(group1, group2, name)
1008 ## Intersection of two groups
1009 # New group is created. All mesh elements that are
1010 # present in both initial groups are added to the new one.
1011 def IntersectGroups(self, group1, group2, name):
1012 return self.mesh.IntersectGroups(group1, group2, name)
1014 ## Cut of two groups
1015 # New group is created. All mesh elements that are present in
1016 # main group but do not present in tool group are added to the new one
1017 def CutGroups(self, mainGroup, toolGroup, name):
1018 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1021 # Get some info about mesh:
1022 # ------------------------
1024 ## Get the log of nodes and elements added or removed since previous
1026 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1027 # @return list of log_block structures:
1032 def GetLog(self, clearAfterGet):
1033 return self.mesh.GetLog(clearAfterGet)
1035 ## Clear the log of nodes and elements added or removed since previous
1036 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1038 self.mesh.ClearLog()
1040 def SetAutoColor(self, color):
1041 self.mesh.SetAutoColor(color)
1043 def GetAutoColor(self):
1044 return self.mesh.GetAutoColor()
1046 ## Get the internal Id
1048 return self.mesh.GetId()
1051 def GetStudyId(self):
1052 return self.mesh.GetStudyId()
1054 ## Check group names for duplications.
1055 # Consider maximum group name length stored in MED file.
1056 def HasDuplicatedGroupNamesMED(self):
1057 return self.mesh.HasDuplicatedGroupNamesMED()
1059 ## Obtain instance of SMESH_MeshEditor
1060 def GetMeshEditor(self):
1061 return self.mesh.GetMeshEditor()
1064 def GetMEDMesh(self):
1065 return self.mesh.GetMEDMesh()
1068 # Get informations about mesh contents:
1069 # ------------------------------------
1071 ## Returns number of nodes in mesh
1073 return self.mesh.NbNodes()
1075 ## Returns number of elements in mesh
1076 def NbElements(self):
1077 return self.mesh.NbElements()
1079 ## Returns number of edges in mesh
1081 return self.mesh.NbEdges()
1083 ## Returns number of edges with given order in mesh
1084 # @param elementOrder is order of elements:
1085 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1086 def NbEdgesOfOrder(self, elementOrder):
1087 return self.mesh.NbEdgesOfOrder(elementOrder)
1089 ## Returns number of faces in mesh
1091 return self.mesh.NbFaces()
1093 ## Returns number of faces with given order in mesh
1094 # @param elementOrder is order of elements:
1095 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1096 def NbFacesOfOrder(self, elementOrder):
1097 return self.mesh.NbFacesOfOrder(elementOrder)
1099 ## Returns number of triangles in mesh
1100 def NbTriangles(self):
1101 return self.mesh.NbTriangles()
1103 ## Returns number of triangles with given order in mesh
1104 # @param elementOrder is order of elements:
1105 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1106 def NbTrianglesOfOrder(self, elementOrder):
1107 return self.mesh.NbTrianglesOfOrder(elementOrder)
1109 ## Returns number of quadrangles in mesh
1110 def NbQuadrangles(self):
1111 return self.mesh.NbQuadrangles()
1113 ## Returns number of quadrangles with given order in mesh
1114 # @param elementOrder is order of elements:
1115 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1116 def NbQuadranglesOfOrder(self, elementOrder):
1117 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1119 ## Returns number of polygons in mesh
1120 def NbPolygons(self):
1121 return self.mesh.NbPolygons()
1123 ## Returns number of volumes in mesh
1124 def NbVolumes(self):
1125 return self.mesh.NbVolumes()
1127 ## Returns number of volumes with given order in mesh
1128 # @param elementOrder is order of elements:
1129 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1130 def NbVolumesOfOrder(self, elementOrder):
1131 return self.mesh.NbVolumesOfOrder(elementOrder)
1133 ## Returns number of tetrahedrons in mesh
1135 return self.mesh.NbTetras()
1137 ## Returns number of tetrahedrons with given order in mesh
1138 # @param elementOrder is order of elements:
1139 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1140 def NbTetrasOfOrder(self, elementOrder):
1141 return self.mesh.NbTetrasOfOrder(elementOrder)
1143 ## Returns number of hexahedrons in mesh
1145 return self.mesh.NbHexas()
1147 ## Returns number of hexahedrons with given order in mesh
1148 # @param elementOrder is order of elements:
1149 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1150 def NbHexasOfOrder(self, elementOrder):
1151 return self.mesh.NbHexasOfOrder(elementOrder)
1153 ## Returns number of pyramids in mesh
1154 def NbPyramids(self):
1155 return self.mesh.NbPyramids()
1157 ## Returns number of pyramids with given order in mesh
1158 # @param elementOrder is order of elements:
1159 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1160 def NbPyramidsOfOrder(self, elementOrder):
1161 return self.mesh.NbPyramidsOfOrder(elementOrder)
1163 ## Returns number of prisms in mesh
1165 return self.mesh.NbPrisms()
1167 ## Returns number of prisms with given order in mesh
1168 # @param elementOrder is order of elements:
1169 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1170 def NbPrismsOfOrder(self, elementOrder):
1171 return self.mesh.NbPrismsOfOrder(elementOrder)
1173 ## Returns number of polyhedrons in mesh
1174 def NbPolyhedrons(self):
1175 return self.mesh.NbPolyhedrons()
1177 ## Returns number of submeshes in mesh
1178 def NbSubMesh(self):
1179 return self.mesh.NbSubMesh()
1181 ## Returns list of mesh elements ids
1182 def GetElementsId(self):
1183 return self.mesh.GetElementsId()
1185 ## Returns list of ids of mesh elements with given type
1186 # @param elementType is required type of elements
1187 def GetElementsByType(self, elementType):
1188 return self.mesh.GetElementsByType(elementType)
1190 ## Returns list of mesh nodes ids
1191 def GetNodesId(self):
1192 return self.mesh.GetNodesId()
1194 # Get informations about mesh elements:
1195 # ------------------------------------
1197 ## Returns type of mesh element
1198 def GetElementType(self, id, iselem):
1199 return self.mesh.GetElementType(id, iselem)
1201 ## Returns list of submesh elements ids
1202 # @param Shape is geom object(subshape) IOR
1203 # Shape must be subshape of a ShapeToMesh()
1204 def GetSubMeshElementsId(self, Shape):
1205 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1206 ShapeID = Shape.GetSubShapeIndices()[0]
1209 return self.mesh.GetSubMeshElementsId(ShapeID)
1211 ## Returns list of submesh nodes ids
1212 # @param Shape is geom object(subshape) IOR
1213 # Shape must be subshape of a ShapeToMesh()
1214 def GetSubMeshNodesId(self, Shape, all):
1215 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1216 ShapeID = Shape.GetSubShapeIndices()[0]
1219 return self.mesh.GetSubMeshNodesId(ShapeID, all)
1221 ## Returns list of ids of submesh elements with given type
1222 # @param Shape is geom object(subshape) IOR
1223 # Shape must be subshape of a ShapeToMesh()
1224 def GetSubMeshElementType(self, Shape):
1225 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1226 ShapeID = Shape.GetSubShapeIndices()[0]
1229 return self.mesh.GetSubMeshElementType(ShapeID)
1231 ## Get mesh description
1233 return self.mesh.Dump()
1236 # Get information about nodes and elements of mesh by its ids:
1237 # -----------------------------------------------------------
1239 ## Get XYZ coordinates of node as list of double
1240 # \n If there is not node for given ID - returns empty list
1241 def GetNodeXYZ(self, id):
1242 return self.mesh.GetNodeXYZ(id)
1244 ## For given node returns list of IDs of inverse elements
1245 # \n If there is not node for given ID - returns empty list
1246 def GetNodeInverseElements(self, id):
1247 return self.mesh.GetNodeInverseElements(id)
1249 ## @brief Return position of a node on shape
1250 # @return SMESH::NodePosition
1251 def GetNodePosition(self,NodeID):
1252 return self.mesh.GetNodePosition(NodeID)
1254 ## If given element is node returns IDs of shape from position
1255 # \n If there is not node for given ID - returns -1
1256 def GetShapeID(self, id):
1257 return self.mesh.GetShapeID(id)
1259 ## For given element returns ID of result shape after
1260 # FindShape() from SMESH_MeshEditor
1261 # \n If there is not element for given ID - returns -1
1262 def GetShapeIDForElem(self,id):
1263 return self.mesh.GetShapeIDForElem(id)
1265 ## Returns number of nodes for given element
1266 # \n If there is not element for given ID - returns -1
1267 def GetElemNbNodes(self, id):
1268 return self.mesh.GetElemNbNodes(id)
1270 ## Returns ID of node by given index for given element
1271 # \n If there is not element for given ID - returns -1
1272 # \n If there is not node for given index - returns -2
1273 def GetElemNode(self, id, index):
1274 return self.mesh.GetElemNode(id, index)
1276 ## Returns IDs of nodes of given element
1277 def GetElemNodes(self, id):
1278 return self.mesh.GetElemNodes(id)
1280 ## Returns true if given node is medium node
1281 # in given quadratic element
1282 def IsMediumNode(self, elementID, nodeID):
1283 return self.mesh.IsMediumNode(elementID, nodeID)
1285 ## Returns true if given node is medium node
1286 # in one of quadratic elements
1287 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1288 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1290 ## Returns number of edges for given element
1291 def ElemNbEdges(self, id):
1292 return self.mesh.ElemNbEdges(id)
1294 ## Returns number of faces for given element
1295 def ElemNbFaces(self, id):
1296 return self.mesh.ElemNbFaces(id)
1298 ## Returns true if given element is polygon
1299 def IsPoly(self, id):
1300 return self.mesh.IsPoly(id)
1302 ## Returns true if given element is quadratic
1303 def IsQuadratic(self, id):
1304 return self.mesh.IsQuadratic(id)
1306 ## Returns XYZ coordinates of bary center for given element
1308 # \n If there is not element for given ID - returns empty list
1309 def BaryCenter(self, id):
1310 return self.mesh.BaryCenter(id)
1313 # Mesh edition (SMESH_MeshEditor functionality):
1314 # ---------------------------------------------
1316 ## Removes elements from mesh by ids
1317 # @param IDsOfElements is list of ids of elements to remove
1318 def RemoveElements(self, IDsOfElements):
1319 return self.editor.RemoveElements(IDsOfElements)
1321 ## Removes nodes from mesh by ids
1322 # @param IDsOfNodes is list of ids of nodes to remove
1323 def RemoveNodes(self, IDsOfNodes):
1324 return self.editor.RemoveNodes(IDsOfNodes)
1326 ## Add node to mesh by coordinates
1327 def AddNode(self, x, y, z):
1328 return self.editor.AddNode( x, y, z)
1331 ## Create edge both similar and quadratic (this is determed
1332 # by number of given nodes).
1333 # @param IdsOfNodes List of node IDs for creation of element.
1334 # Needed order of nodes in this list corresponds to description
1335 # of MED. \n This description is located by the following link:
1336 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1337 def AddEdge(self, IDsOfNodes):
1338 return self.editor.AddEdge(IDsOfNodes)
1340 ## Create face both similar and quadratic (this is determed
1341 # by number of given nodes).
1342 # @param IdsOfNodes List of node IDs for creation of element.
1343 # Needed order of nodes in this list corresponds to description
1344 # of MED. \n This description is located by the following link:
1345 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1346 def AddFace(self, IDsOfNodes):
1347 return self.editor.AddFace(IDsOfNodes)
1349 ## Add polygonal face to mesh by list of nodes ids
1350 def AddPolygonalFace(self, IdsOfNodes):
1351 return self.editor.AddPolygonalFace(IdsOfNodes)
1353 ## Create volume both similar and quadratic (this is determed
1354 # by number of given nodes).
1355 # @param IdsOfNodes List of node IDs for creation of element.
1356 # Needed order of nodes in this list corresponds to description
1357 # of MED. \n This description is located by the following link:
1358 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1359 def AddVolume(self, IDsOfNodes):
1360 return self.editor.AddVolume(IDsOfNodes)
1362 ## Create volume of many faces, giving nodes for each face.
1363 # @param IdsOfNodes List of node IDs for volume creation face by face.
1364 # @param Quantities List of integer values, Quantities[i]
1365 # gives quantity of nodes in face number i.
1366 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1367 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1369 ## Create volume of many faces, giving IDs of existing faces.
1370 # @param IdsOfFaces List of face IDs for volume creation.
1372 # Note: The created volume will refer only to nodes
1373 # of the given faces, not to the faces itself.
1374 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1375 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1378 ## @brief Bind a node to a vertex
1379 # @param NodeID - node ID
1380 # @param Vertex - vertex or vertex ID
1381 # @return True if succeed else raise an exception
1382 def SetNodeOnVertex(self, NodeID, Vertex):
1383 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
1384 VertexID = Vertex.GetSubShapeIndices()[0]
1388 self.editor.SetNodeOnVertex(NodeID, VertexID)
1389 except SALOME.SALOME_Exception, inst:
1390 raise ValueError, inst.details.text
1394 ## @brief Store node position on an edge
1395 # @param NodeID - node ID
1396 # @param Edge - edge or edge ID
1397 # @param paramOnEdge - parameter on edge where the node is located
1398 # @return True if succeed else raise an exception
1399 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
1400 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
1401 EdgeID = Edge.GetSubShapeIndices()[0]
1405 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
1406 except SALOME.SALOME_Exception, inst:
1407 raise ValueError, inst.details.text
1410 ## @brief Store node position on a face
1411 # @param NodeID - node ID
1412 # @param Face - face or face ID
1413 # @param u - U parameter on face where the node is located
1414 # @param v - V parameter on face where the node is located
1415 # @return True if succeed else raise an exception
1416 def SetNodeOnFace(self, NodeID, Face, u, v):
1417 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
1418 FaceID = Face.GetSubShapeIndices()[0]
1422 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
1423 except SALOME.SALOME_Exception, inst:
1424 raise ValueError, inst.details.text
1427 ## @brief Bind a node to a solid
1428 # @param NodeID - node ID
1429 # @param Solid - solid or solid ID
1430 # @return True if succeed else raise an exception
1431 def SetNodeInVolume(self, NodeID, Solid):
1432 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
1433 SolidID = Solid.GetSubShapeIndices()[0]
1437 self.editor.SetNodeInVolume(NodeID, SolidID)
1438 except SALOME.SALOME_Exception, inst:
1439 raise ValueError, inst.details.text
1442 ## @brief Bind an element to a shape
1443 # @param ElementID - element ID
1444 # @param Shape - shape or shape ID
1445 # @return True if succeed else raise an exception
1446 def SetMeshElementOnShape(self, ElementID, Shape):
1447 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
1448 ShapeID = Shape.GetSubShapeIndices()[0]
1452 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
1453 except SALOME.SALOME_Exception, inst:
1454 raise ValueError, inst.details.text
1458 ## Move node with given id
1459 # @param NodeID id of the node
1460 # @param x new X coordinate
1461 # @param y new Y coordinate
1462 # @param z new Z coordinate
1463 def MoveNode(self, NodeID, x, y, z):
1464 return self.editor.MoveNode(NodeID, x, y, z)
1466 ## Find a node closest to a point
1467 # @param x X coordinate of a point
1468 # @param y Y coordinate of a point
1469 # @param z Z coordinate of a point
1470 # @return id of a node
1471 def FindNodeClosestTo(self, x, y, z):
1472 preview = self.mesh.GetMeshEditPreviewer()
1473 return preview.MoveClosestNodeToPoint(x, y, z, -1)
1475 ## Find a node closest to a point and move it to a point location
1476 # @param x X coordinate of a point
1477 # @param y Y coordinate of a point
1478 # @param z Z coordinate of a point
1479 # @return id of a moved node
1480 def MeshToPassThroughAPoint(self, x, y, z):
1481 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
1483 ## Replace two neighbour triangles sharing Node1-Node2 link
1484 # with ones built on the same 4 nodes but having other common link.
1485 # @param NodeID1 first node id
1486 # @param NodeID2 second node id
1487 # @return false if proper faces not found
1488 def InverseDiag(self, NodeID1, NodeID2):
1489 return self.editor.InverseDiag(NodeID1, NodeID2)
1491 ## Replace two neighbour triangles sharing Node1-Node2 link
1492 # with a quadrangle built on the same 4 nodes.
1493 # @param NodeID1 first node id
1494 # @param NodeID2 second node id
1495 # @return false if proper faces not found
1496 def DeleteDiag(self, NodeID1, NodeID2):
1497 return self.editor.DeleteDiag(NodeID1, NodeID2)
1499 ## Reorient elements by ids
1500 # @param IDsOfElements if undefined reorient all mesh elements
1501 def Reorient(self, IDsOfElements=None):
1502 if IDsOfElements == None:
1503 IDsOfElements = self.GetElementsId()
1504 return self.editor.Reorient(IDsOfElements)
1506 ## Reorient all elements of the object
1507 # @param theObject is mesh, submesh or group
1508 def ReorientObject(self, theObject):
1509 if ( isinstance( theObject, Mesh )):
1510 theObject = theObject.GetMesh()
1511 return self.editor.ReorientObject(theObject)
1513 ## Fuse neighbour triangles into quadrangles.
1514 # @param IDsOfElements The triangles to be fused,
1515 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1516 # @param MaxAngle is a max angle between element normals at which fusion
1517 # is still performed; theMaxAngle is mesured in radians.
1518 # @return TRUE in case of success, FALSE otherwise.
1519 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1520 if IDsOfElements == []:
1521 IDsOfElements = self.GetElementsId()
1522 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1524 ## Fuse neighbour triangles of the object into quadrangles
1525 # @param theObject is mesh, submesh or group
1526 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1527 # @param MaxAngle is a max angle between element normals at which fusion
1528 # is still performed; theMaxAngle is mesured in radians.
1529 # @return TRUE in case of success, FALSE otherwise.
1530 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1531 if ( isinstance( theObject, Mesh )):
1532 theObject = theObject.GetMesh()
1533 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
1535 ## Split quadrangles into triangles.
1536 # @param IDsOfElements the faces to be splitted.
1537 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1538 # @return TRUE in case of success, FALSE otherwise.
1539 def QuadToTri (self, IDsOfElements, theCriterion):
1540 if IDsOfElements == []:
1541 IDsOfElements = self.GetElementsId()
1542 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
1544 ## Split quadrangles into triangles.
1545 # @param theObject object to taking list of elements from, is mesh, submesh or group
1546 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1547 def QuadToTriObject (self, theObject, theCriterion):
1548 if ( isinstance( theObject, Mesh )):
1549 theObject = theObject.GetMesh()
1550 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
1552 ## Split quadrangles into triangles.
1553 # @param theElems The faces to be splitted
1554 # @param the13Diag is used to choose a diagonal for splitting.
1555 # @return TRUE in case of success, FALSE otherwise.
1556 def SplitQuad (self, IDsOfElements, Diag13):
1557 if IDsOfElements == []:
1558 IDsOfElements = self.GetElementsId()
1559 return self.editor.SplitQuad(IDsOfElements, Diag13)
1561 ## Split quadrangles into triangles.
1562 # @param theObject is object to taking list of elements from, is mesh, submesh or group
1563 def SplitQuadObject (self, theObject, Diag13):
1564 if ( isinstance( theObject, Mesh )):
1565 theObject = theObject.GetMesh()
1566 return self.editor.SplitQuadObject(theObject, Diag13)
1568 ## Find better splitting of the given quadrangle.
1569 # @param IDOfQuad ID of the quadrangle to be splitted.
1570 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
1571 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1572 # diagonal is better, 0 if error occurs.
1573 def BestSplit (self, IDOfQuad, theCriterion):
1574 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
1576 ## Split quafrangle faces near triangular facets of volumes
1578 def SplitQuadsNearTriangularFacets(self):
1579 faces_array = self.GetElementsByType(SMESH.FACE)
1580 for face_id in faces_array:
1581 if self.GetElemNbNodes(face_id) == 4: # quadrangle
1582 quad_nodes = self.mesh.GetElemNodes(face_id)
1583 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1584 isVolumeFound = False
1585 for node1_elem in node1_elems:
1586 if not isVolumeFound:
1587 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1588 nb_nodes = self.GetElemNbNodes(node1_elem)
1589 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1590 volume_elem = node1_elem
1591 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1592 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1593 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1594 isVolumeFound = True
1595 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1596 self.SplitQuad([face_id], False) # diagonal 2-4
1597 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1598 isVolumeFound = True
1599 self.SplitQuad([face_id], True) # diagonal 1-3
1600 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1601 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1602 isVolumeFound = True
1603 self.SplitQuad([face_id], True) # diagonal 1-3
1605 ## @brief Split hexahedrons into tetrahedrons.
1607 # Use pattern mapping functionality for splitting.
1608 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
1609 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
1610 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
1611 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1612 # key-point will be mapped into <theNode001>-th node of each volume.
1613 # The (0,0,0) key-point of used pattern corresponds to not split corner.
1614 # @return TRUE in case of success, FALSE otherwise.
1615 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
1616 # Pattern: 5.---------.6
1621 # (0,0,1) 4.---------.7 * |
1628 # (0,0,0) 0.---------.3
1629 pattern_tetra = "!!! Nb of points: \n 8 \n\
1639 !!! Indices of points of 6 tetras: \n\
1647 pattern = self.smeshpyD.GetPattern()
1648 isDone = pattern.LoadFromFile(pattern_tetra)
1650 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1653 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1654 isDone = pattern.MakeMesh(self.mesh, False, False)
1655 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1657 # split quafrangle faces near triangular facets of volumes
1658 self.SplitQuadsNearTriangularFacets()
1662 ## @brief Split hexahedrons into prisms.
1664 # Use pattern mapping functionality for splitting.
1665 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
1666 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
1667 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
1668 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1669 # key-point will be mapped into <theNode001>-th node of each volume.
1670 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
1671 # @return TRUE in case of success, FALSE otherwise.
1672 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
1673 # Pattern: 5.---------.6
1678 # (0,0,1) 4.---------.7 |
1685 # (0,0,0) 0.---------.3
1686 pattern_prism = "!!! Nb of points: \n 8 \n\
1696 !!! Indices of points of 2 prisms: \n\
1700 pattern = self.smeshpyD.GetPattern()
1701 isDone = pattern.LoadFromFile(pattern_prism)
1703 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
1706 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
1707 isDone = pattern.MakeMesh(self.mesh, False, False)
1708 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
1710 # split quafrangle faces near triangular facets of volumes
1711 self.SplitQuadsNearTriangularFacets()
1716 # @param IDsOfElements list if ids of elements to smooth
1717 # @param IDsOfFixedNodes list of ids of fixed nodes.
1718 # Note that nodes built on edges and boundary nodes are always fixed.
1719 # @param MaxNbOfIterations maximum number of iterations
1720 # @param MaxAspectRatio varies in range [1.0, inf]
1721 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1722 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1723 MaxNbOfIterations, MaxAspectRatio, Method):
1724 if IDsOfElements == []:
1725 IDsOfElements = self.GetElementsId()
1726 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1727 MaxNbOfIterations, MaxAspectRatio, Method)
1729 ## Smooth elements belong to given object
1730 # @param theObject object to smooth
1731 # @param IDsOfFixedNodes list of ids of fixed nodes.
1732 # Note that nodes built on edges and boundary nodes are always fixed.
1733 # @param MaxNbOfIterations maximum number of iterations
1734 # @param MaxAspectRatio varies in range [1.0, inf]
1735 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1736 def SmoothObject(self, theObject, IDsOfFixedNodes,
1737 MaxNbOfIterations, MaxxAspectRatio, Method):
1738 if ( isinstance( theObject, Mesh )):
1739 theObject = theObject.GetMesh()
1740 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1741 MaxNbOfIterations, MaxxAspectRatio, Method)
1743 ## Parametric smooth the given elements
1744 # @param IDsOfElements list if ids of elements to smooth
1745 # @param IDsOfFixedNodes list of ids of fixed nodes.
1746 # Note that nodes built on edges and boundary nodes are always fixed.
1747 # @param MaxNbOfIterations maximum number of iterations
1748 # @param MaxAspectRatio varies in range [1.0, inf]
1749 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1750 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
1751 MaxNbOfIterations, MaxAspectRatio, Method):
1752 if IDsOfElements == []:
1753 IDsOfElements = self.GetElementsId()
1754 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1755 MaxNbOfIterations, MaxAspectRatio, Method)
1757 ## Parametric smooth elements belong to given object
1758 # @param theObject object to smooth
1759 # @param IDsOfFixedNodes list of ids of fixed nodes.
1760 # Note that nodes built on edges and boundary nodes are always fixed.
1761 # @param MaxNbOfIterations maximum number of iterations
1762 # @param MaxAspectRatio varies in range [1.0, inf]
1763 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1764 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
1765 MaxNbOfIterations, MaxAspectRatio, Method):
1766 if ( isinstance( theObject, Mesh )):
1767 theObject = theObject.GetMesh()
1768 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
1769 MaxNbOfIterations, MaxAspectRatio, Method)
1771 ## Converts all mesh to quadratic one, deletes old elements, replacing
1772 # them with quadratic ones with the same id.
1773 def ConvertToQuadratic(self, theForce3d):
1774 self.editor.ConvertToQuadratic(theForce3d)
1776 ## Converts all mesh from quadratic to ordinary ones,
1777 # deletes old quadratic elements, \n replacing
1778 # them with ordinary mesh elements with the same id.
1779 def ConvertFromQuadratic(self):
1780 return self.editor.ConvertFromQuadratic()
1782 ## Renumber mesh nodes
1783 def RenumberNodes(self):
1784 self.editor.RenumberNodes()
1786 ## Renumber mesh elements
1787 def RenumberElements(self):
1788 self.editor.RenumberElements()
1790 ## Generate new elements by rotation of the elements around the axis
1791 # @param IDsOfElements list of ids of elements to sweep
1792 # @param Axix axis of rotation, AxisStruct or line(geom object)
1793 # @param AngleInRadians angle of Rotation
1794 # @param NbOfSteps number of steps
1795 # @param Tolerance tolerance
1796 # @param MakeGroups to generate new groups from existing ones
1797 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
1798 if IDsOfElements == []:
1799 IDsOfElements = self.GetElementsId()
1800 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1801 Axix = self.smeshpyD.GetAxisStruct(Axix)
1803 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
1804 AngleInRadians, NbOfSteps, Tolerance)
1805 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
1808 ## Generate new elements by rotation of the elements of object around the axis
1809 # @param theObject object wich elements should be sweeped
1810 # @param Axix axis of rotation, AxisStruct or line(geom object)
1811 # @param AngleInRadians angle of Rotation
1812 # @param NbOfSteps number of steps
1813 # @param Tolerance tolerance
1814 # @param MakeGroups to generate new groups from existing ones
1815 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
1816 if ( isinstance( theObject, Mesh )):
1817 theObject = theObject.GetMesh()
1818 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
1819 Axix = self.smeshpyD.GetAxisStruct(Axix)
1821 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
1822 NbOfSteps, Tolerance)
1823 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
1826 ## Generate new elements by extrusion of the elements with given ids
1827 # @param IDsOfElements list of elements ids for extrusion
1828 # @param StepVector vector, defining the direction and value of extrusion
1829 # @param NbOfSteps the number of steps
1830 # @param MakeGroups to generate new groups from existing ones
1831 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
1832 if IDsOfElements == []:
1833 IDsOfElements = self.GetElementsId()
1834 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1835 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1837 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
1838 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
1841 ## Generate new elements by extrusion of the elements with given ids
1842 # @param IDsOfElements is ids of elements
1843 # @param StepVector vector, defining the direction and value of extrusion
1844 # @param NbOfSteps the number of steps
1845 # @param ExtrFlags set flags for performing extrusion
1846 # @param SewTolerance uses for comparing locations of nodes if flag
1847 # EXTRUSION_FLAG_SEW is set
1848 # @param MakeGroups to generate new groups from existing ones
1849 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
1850 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1851 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1853 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
1854 ExtrFlags, SewTolerance)
1855 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
1856 ExtrFlags, SewTolerance)
1859 ## Generate new elements by extrusion of the elements belong to object
1860 # @param theObject object wich elements should be processed
1861 # @param StepVector vector, defining the direction and value of extrusion
1862 # @param NbOfSteps the number of steps
1863 # @param MakeGroups to generate new groups from existing ones
1864 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
1865 if ( isinstance( theObject, Mesh )):
1866 theObject = theObject.GetMesh()
1867 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1868 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1870 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
1871 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
1874 ## Generate new elements by extrusion of the elements belong to object
1875 # @param theObject object wich elements should be processed
1876 # @param StepVector vector, defining the direction and value of extrusion
1877 # @param NbOfSteps the number of steps
1878 # @param MakeGroups to generate new groups from existing ones
1879 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
1880 if ( isinstance( theObject, Mesh )):
1881 theObject = theObject.GetMesh()
1882 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1883 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1885 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
1886 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
1889 ## Generate new elements by extrusion of the elements belong to object
1890 # @param theObject object wich elements should be processed
1891 # @param StepVector vector, defining the direction and value of extrusion
1892 # @param NbOfSteps the number of steps
1893 # @param MakeGroups to generate new groups from existing ones
1894 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
1895 if ( isinstance( theObject, Mesh )):
1896 theObject = theObject.GetMesh()
1897 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
1898 StepVector = self.smeshpyD.GetDirStruct(StepVector)
1900 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
1901 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
1904 ## Generate new elements by extrusion of the given elements
1905 # A path of extrusion must be a meshed edge.
1906 # @param IDsOfElements is ids of elements
1907 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
1908 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
1909 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
1910 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
1911 # @param Angles list of angles
1912 # @param HasRefPoint allows to use base point
1913 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
1914 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
1915 # @param MakeGroups to generate new groups from existing ones
1916 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
1917 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
1918 HasAngles, Angles, HasRefPoint, RefPoint,
1919 MakeGroups=False, LinearVariation=False):
1920 if IDsOfElements == []:
1921 IDsOfElements = self.GetElementsId()
1922 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
1923 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
1926 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
1927 PathShape, NodeStart, HasAngles,
1928 Angles, HasRefPoint, RefPoint)
1929 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
1930 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
1932 ## Generate new elements by extrusion of the elements belong to object
1933 # A path of extrusion must be a meshed edge.
1934 # @param IDsOfElements is ids of elements
1935 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
1936 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
1937 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
1938 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
1939 # @param Angles list of angles
1940 # @param HasRefPoint allows to use base point
1941 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
1942 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
1943 # @param MakeGroups to generate new groups from existing ones
1944 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
1945 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
1946 HasAngles, Angles, HasRefPoint, RefPoint,
1947 MakeGroups=False, LinearVariation=False):
1948 if ( isinstance( theObject, Mesh )):
1949 theObject = theObject.GetMesh()
1950 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
1951 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
1953 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
1954 PathShape, NodeStart, HasAngles,
1955 Angles, HasRefPoint, RefPoint)
1956 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
1957 NodeStart, HasAngles, Angles, HasRefPoint,
1960 ## Symmetrical copy of mesh elements
1961 # @param IDsOfElements list of elements ids
1962 # @param Mirror is AxisStruct or geom object(point, line, plane)
1963 # @param theMirrorType is POINT, AXIS or PLANE
1964 # If the Mirror is geom object this parameter is unnecessary
1965 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
1966 # @param MakeGroups to generate new groups from existing ones (if Copy)
1967 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
1968 if IDsOfElements == []:
1969 IDsOfElements = self.GetElementsId()
1970 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
1971 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
1972 if Copy and MakeGroups:
1973 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
1974 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
1977 ## Create a new mesh by symmetrical copy of mesh elements
1978 # @param IDsOfElements list of elements ids
1979 # @param Mirror is AxisStruct or geom object(point, line, plane)
1980 # @param theMirrorType is POINT, AXIS or PLANE
1981 # If the Mirror is geom object this parameter is unnecessary
1982 # @param MakeGroups to generate new groups from existing ones
1983 # @param NewMeshName is a name of new mesh to create
1984 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
1985 if IDsOfElements == []:
1986 IDsOfElements = self.GetElementsId()
1987 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
1988 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
1989 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
1990 MakeGroups, NewMeshName)
1991 return Mesh(self.smeshpyD,self.geompyD,mesh)
1993 ## Symmetrical copy of object
1994 # @param theObject mesh, submesh or group
1995 # @param Mirror is AxisStruct or geom object(point, line, plane)
1996 # @param theMirrorType is POINT, AXIS or PLANE
1997 # If the Mirror is geom object this parameter is unnecessary
1998 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
1999 # @param MakeGroups to generate new groups from existing ones (if Copy)
2000 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2001 if ( isinstance( theObject, Mesh )):
2002 theObject = theObject.GetMesh()
2003 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2004 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2005 if Copy and MakeGroups:
2006 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2007 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2010 ## Create a new mesh by symmetrical copy of object
2011 # @param theObject mesh, submesh or group
2012 # @param Mirror is AxisStruct or geom object(point, line, plane)
2013 # @param theMirrorType is POINT, AXIS or PLANE
2014 # If the Mirror is geom object this parameter is unnecessary
2015 # @param MakeGroups to generate new groups from existing ones
2016 # @param NewMeshName is a name of new mesh to create
2017 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
2018 if ( isinstance( theObject, Mesh )):
2019 theObject = theObject.GetMesh()
2020 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2021 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2022 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
2023 MakeGroups, NewMeshName)
2024 return Mesh( self.smeshpyD,self.geompyD,mesh )
2026 ## Translates the elements
2027 # @param IDsOfElements list of elements ids
2028 # @param Vector direction of translation(DirStruct or vector)
2029 # @param Copy allows to copy the translated elements
2030 # @param MakeGroups to generate new groups from existing ones (if Copy)
2031 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2032 if IDsOfElements == []:
2033 IDsOfElements = self.GetElementsId()
2034 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2035 Vector = self.smeshpyD.GetDirStruct(Vector)
2036 if Copy and MakeGroups:
2037 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2038 self.editor.Translate(IDsOfElements, Vector, Copy)
2041 ## Create a new mesh of translated elements
2042 # @param IDsOfElements list of elements ids
2043 # @param Vector direction of translation(DirStruct or vector)
2044 # @param MakeGroups to generate new groups from existing ones
2045 # @param NewMeshName is a name of new mesh to create
2046 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
2047 if IDsOfElements == []:
2048 IDsOfElements = self.GetElementsId()
2049 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2050 Vector = self.smeshpyD.GetDirStruct(Vector)
2051 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
2052 return Mesh ( self.smeshpyD, self.geompyD, mesh )
2054 ## Translates the object
2055 # @param theObject object to translate(mesh, submesh, or group)
2056 # @param Vector direction of translation(DirStruct or geom vector)
2057 # @param Copy allows to copy the translated elements
2058 # @param MakeGroups to generate new groups from existing ones (if Copy)
2059 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2060 if ( isinstance( theObject, Mesh )):
2061 theObject = theObject.GetMesh()
2062 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2063 Vector = self.smeshpyD.GetDirStruct(Vector)
2064 if Copy and MakeGroups:
2065 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2066 self.editor.TranslateObject(theObject, Vector, Copy)
2069 ## Create a new mesh from translated object
2070 # @param theObject object to translate(mesh, submesh, or group)
2071 # @param Vector direction of translation(DirStruct or geom vector)
2072 # @param MakeGroups to generate new groups from existing ones
2073 # @param NewMeshName is a name of new mesh to create
2074 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
2075 if (isinstance(theObject, Mesh)):
2076 theObject = theObject.GetMesh()
2077 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
2078 Vector = self.smeshpyD.GetDirStruct(Vector)
2079 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
2080 return Mesh( self.smeshpyD, self.geompyD, mesh )
2082 ## Rotates the elements
2083 # @param IDsOfElements list of elements ids
2084 # @param Axis axis of rotation(AxisStruct or geom line)
2085 # @param AngleInRadians angle of rotation(in radians)
2086 # @param Copy allows to copy the rotated elements
2087 # @param MakeGroups to generate new groups from existing ones (if Copy)
2088 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2089 if IDsOfElements == []:
2090 IDsOfElements = self.GetElementsId()
2091 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2092 Axis = self.smeshpyD.GetAxisStruct(Axis)
2093 if Copy and MakeGroups:
2094 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2095 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2098 ## Create a new mesh of rotated elements
2099 # @param IDsOfElements list of element ids
2100 # @param Axis axis of rotation(AxisStruct or geom line)
2101 # @param AngleInRadians angle of rotation(in radians)
2102 # @param MakeGroups to generate new groups from existing ones
2103 # @param NewMeshName is a name of new mesh to create
2104 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
2105 if IDsOfElements == []:
2106 IDsOfElements = self.GetElementsId()
2107 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2108 Axis = self.smeshpyD.GetAxisStruct(Axis)
2109 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
2110 MakeGroups, NewMeshName)
2111 return Mesh( self.smeshpyD, self.geompyD, mesh )
2113 ## Rotates the object
2114 # @param theObject object to rotate(mesh, submesh, or group)
2115 # @param Axis axis of rotation(AxisStruct or geom line)
2116 # @param AngleInRadians angle of rotation(in radians)
2117 # @param Copy allows to copy the rotated elements
2118 # @param MakeGroups to generate new groups from existing ones (if Copy)
2119 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2120 if (isinstance(theObject, Mesh)):
2121 theObject = theObject.GetMesh()
2122 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2123 Axis = self.smeshpyD.GetAxisStruct(Axis)
2124 if Copy and MakeGroups:
2125 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2126 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2129 ## Create a new mesh from a rotated object
2130 # @param theObject object to rotate (mesh, submesh, or group)
2131 # @param Axis axis of rotation(AxisStruct or geom line)
2132 # @param AngleInRadians angle of rotation(in radians)
2133 # @param MakeGroups to generate new groups from existing ones
2134 # @param NewMeshName is a name of new mesh to create
2135 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
2136 if (isinstance( theObject, Mesh )):
2137 theObject = theObject.GetMesh()
2138 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
2139 Axis = self.smeshpyD.GetAxisStruct(Axis)
2140 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
2141 MakeGroups, NewMeshName)
2142 return Mesh( self.smeshpyD, self.geompyD, mesh )
2144 ## Find group of nodes close to each other within Tolerance.
2145 # @param Tolerance tolerance value
2146 # @param list of group of nodes
2147 def FindCoincidentNodes (self, Tolerance):
2148 return self.editor.FindCoincidentNodes(Tolerance)
2150 ## Find group of nodes close to each other within Tolerance.
2151 # @param Tolerance tolerance value
2152 # @param SubMeshOrGroup SubMesh or Group
2153 # @param list of group of nodes
2154 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2155 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2158 # @param list of group of nodes
2159 def MergeNodes (self, GroupsOfNodes):
2160 self.editor.MergeNodes(GroupsOfNodes)
2162 ## Find elements built on the same nodes.
2163 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2164 # @return a list of groups of equal elements
2165 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2166 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2168 ## Merge elements in each given group.
2169 # @param GroupsOfElementsID groups of elements for merging
2170 def MergeElements(self, GroupsOfElementsID):
2171 self.editor.MergeElements(GroupsOfElementsID)
2173 ## Remove all but one of elements built on the same nodes.
2174 def MergeEqualElements(self):
2175 self.editor.MergeEqualElements()
2178 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2179 FirstNodeID2, SecondNodeID2, LastNodeID2,
2180 CreatePolygons, CreatePolyedrs):
2181 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2182 FirstNodeID2, SecondNodeID2, LastNodeID2,
2183 CreatePolygons, CreatePolyedrs)
2185 ## Sew conform free borders
2186 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2187 FirstNodeID2, SecondNodeID2):
2188 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2189 FirstNodeID2, SecondNodeID2)
2191 ## Sew border to side
2192 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2193 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2194 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2195 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2197 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2198 # merged with nodes of elements of Side2.
2199 # Number of elements in theSide1 and in theSide2 must be
2200 # equal and they should have similar node connectivity.
2201 # The nodes to merge should belong to sides borders and
2202 # the first node should be linked to the second.
2203 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2204 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2205 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2206 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2207 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2208 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2210 ## Set new nodes for given element.
2211 # @param ide the element id
2212 # @param newIDs nodes ids
2213 # @return If number of nodes is not corresponded to type of element - returns false
2214 def ChangeElemNodes(self, ide, newIDs):
2215 return self.editor.ChangeElemNodes(ide, newIDs)
2217 ## If during last operation of MeshEditor some nodes were
2218 # created this method returns list of its IDs, \n
2219 # if new nodes not created - returns empty list
2220 def GetLastCreatedNodes(self):
2221 return self.editor.GetLastCreatedNodes()
2223 ## If during last operation of MeshEditor some elements were
2224 # created this method returns list of its IDs, \n
2225 # if new elements not creared - returns empty list
2226 def GetLastCreatedElems(self):
2227 return self.editor.GetLastCreatedElems()
2229 ## Mother class to define algorithm, recommended to do not use directly.
2232 class Mesh_Algorithm:
2233 # @class Mesh_Algorithm
2234 # @brief Class Mesh_Algorithm
2236 #def __init__(self,smesh):
2244 ## Find hypothesis in study by its type name and parameters.
2245 # Find only those hypothesis, which was created in smeshpyD engine.
2246 def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
2247 study = smeshpyD.GetCurrentStudy()
2248 #to do: find component by smeshpyD object, not by its data type
2249 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2250 if scomp is not None:
2251 res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
2252 # is hypotheses root label exists?
2253 if res and hypRoot is not None:
2254 iter = study.NewChildIterator(hypRoot)
2255 # check all published hypotheses
2257 hypo_so_i = iter.Value()
2258 attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
2259 if attr is not None:
2260 anIOR = attr.Value()
2261 hypo_o_i = salome.orb.string_to_object(anIOR)
2262 if hypo_o_i is not None:
2264 hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
2265 if hypo_i is not None:
2266 # belongs to this engine?
2267 if smeshpyD.GetObjectId(hypo_i) > 0:
2268 # is it the needed hypothesis?
2269 if hypo_i.GetName() == hypname:
2271 if CompareMethod(hypo_i, args):
2285 ## Find algorithm in study by its type name.
2286 # Find only those algorithm, which was created in smeshpyD engine.
2287 def FindAlgorithm (self, algoname, smeshpyD):
2288 study = smeshpyD.GetCurrentStudy()
2289 #to do: find component by smeshpyD object, not by its data type
2290 scomp = study.FindComponent(smeshpyD.ComponentDataType())
2291 if scomp is not None:
2292 res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
2293 # is algorithms root label exists?
2294 if res and hypRoot is not None:
2295 iter = study.NewChildIterator(hypRoot)
2296 # check all published algorithms
2298 algo_so_i = iter.Value()
2299 attr = algo_so_i.FindAttribute("AttributeIOR")[1]
2300 if attr is not None:
2301 anIOR = attr.Value()
2302 algo_o_i = salome.orb.string_to_object(anIOR)
2303 if algo_o_i is not None:
2305 algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
2306 if algo_i is not None:
2307 # belongs to this engine?
2308 if smeshpyD.GetObjectId(algo_i) > 0:
2309 # is it the needed algorithm?
2310 if algo_i.GetName() == algoname:
2323 ## If the algorithm is global, return 0; \n
2324 # else return the submesh associated to this algorithm.
2325 def GetSubMesh(self):
2328 ## Return the wrapped mesher.
2329 def GetAlgorithm(self):
2332 ## Get list of hypothesis that can be used with this algorithm
2333 def GetCompatibleHypothesis(self):
2336 mylist = self.algo.GetCompatibleHypothesis()
2344 def SetName(self, name):
2345 SetName(self.algo, name)
2349 return self.algo.GetId()
2352 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
2354 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
2355 algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
2357 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
2359 self.Assign(algo, mesh, geom)
2363 def Assign(self, algo, mesh, geom):
2365 raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
2372 name = GetName(geom)
2374 name = mesh.geompyD.SubShapeName(geom, piece)
2375 mesh.geompyD.addToStudyInFather(piece, geom, name)
2376 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
2379 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
2380 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
2382 def CompareHyp (self, hyp, args):
2383 print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
2386 def CompareEqualHyp (self, hyp, args):
2390 def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
2391 UseExisting=0, CompareMethod=""):
2394 if CompareMethod == "": CompareMethod = self.CompareHyp
2395 hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
2398 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
2404 a = a + s + str(args[i])
2408 SetName(hypo, hyp + a)
2410 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
2411 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
2415 # Public class: Mesh_Segment
2416 # --------------------------
2418 ## Class to define a segment 1D algorithm for discretization
2421 class Mesh_Segment(Mesh_Algorithm):
2423 ## Private constructor.
2424 def __init__(self, mesh, geom=0):
2425 Mesh_Algorithm.__init__(self)
2426 self.Create(mesh, geom, "Regular_1D")
2428 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
2429 # @param l for the length of segments that cut an edge
2430 # @param UseExisting if ==true - search existing hypothesis created with
2431 # same parameters, else (default) - create new
2432 # @param p precision, used for number of segments calculation.
2433 # It must be pozitive, meaningfull values are in range [0,1].
2434 # In general, number of segments is calculated with formula:
2435 # nb = ceil((edge_length / l) - p)
2436 # Function ceil rounds its argument to the higher integer.
2437 # So, p=0 means rounding of (edge_length / l) to the higher integer,
2438 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
2439 # p=1 means rounding of (edge_length / l) to the lower integer.
2440 # Default value is 1e-07.
2441 def LocalLength(self, l, UseExisting=0, p=1e-07):
2442 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
2443 CompareMethod=self.CompareLocalLength)
2448 ## Check if the given "LocalLength" hypothesis has the same parameters as given arguments
2449 def CompareLocalLength(self, hyp, args):
2450 if IsEqual(hyp.GetLength(), args[0]):
2451 return IsEqual(hyp.GetPrecision(), args[1])
2454 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
2455 # @param n for the number of segments that cut an edge
2456 # @param s for the scale factor (optional)
2457 # @param UseExisting if ==true - search existing hypothesis created with
2458 # same parameters, else (default) - create new
2459 def NumberOfSegments(self, n, s=[], UseExisting=0):
2461 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
2462 CompareMethod=self.CompareNumberOfSegments)
2464 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
2465 CompareMethod=self.CompareNumberOfSegments)
2466 hyp.SetDistrType( 1 )
2467 hyp.SetScaleFactor(s)
2468 hyp.SetNumberOfSegments(n)
2471 ## Check if the given "NumberOfSegments" hypothesis has the same parameters as given arguments
2472 def CompareNumberOfSegments(self, hyp, args):
2473 if hyp.GetNumberOfSegments() == args[0]:
2477 if hyp.GetDistrType() == 1:
2478 if IsEqual(hyp.GetScaleFactor(), args[1]):
2482 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
2483 # @param start for the length of the first segment
2484 # @param end for the length of the last segment
2485 # @param UseExisting if ==true - search existing hypothesis created with
2486 # same parameters, else (default) - create new
2487 def Arithmetic1D(self, start, end, UseExisting=0):
2488 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
2489 CompareMethod=self.CompareArithmetic1D)
2490 hyp.SetLength(start, 1)
2491 hyp.SetLength(end , 0)
2494 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as given arguments
2495 def CompareArithmetic1D(self, hyp, args):
2496 if IsEqual(hyp.GetLength(1), args[0]):
2497 if IsEqual(hyp.GetLength(0), args[1]):
2501 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
2502 # @param start for the length of the first segment
2503 # @param end for the length of the last segment
2504 # @param UseExisting if ==true - search existing hypothesis created with
2505 # same parameters, else (default) - create new
2506 def StartEndLength(self, start, end, UseExisting=0):
2507 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
2508 CompareMethod=self.CompareStartEndLength)
2509 hyp.SetLength(start, 1)
2510 hyp.SetLength(end , 0)
2513 ## Check if the given "StartEndLength" hypothesis has the same parameters as given arguments
2514 def CompareStartEndLength(self, hyp, args):
2515 if IsEqual(hyp.GetLength(1), args[0]):
2516 if IsEqual(hyp.GetLength(0), args[1]):
2520 ## Define "Deflection1D" hypothesis
2521 # @param d for the deflection
2522 # @param UseExisting if ==true - search existing hypothesis created with
2523 # same parameters, else (default) - create new
2524 def Deflection1D(self, d, UseExisting=0):
2525 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
2526 CompareMethod=self.CompareDeflection1D)
2527 hyp.SetDeflection(d)
2530 ## Check if the given "Deflection1D" hypothesis has the same parameters as given arguments
2531 def CompareDeflection1D(self, hyp, args):
2532 return IsEqual(hyp.GetDeflection(), args[0])
2534 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
2535 # the opposite side in the case of quadrangular faces
2536 def Propagation(self):
2537 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2539 ## Define "AutomaticLength" hypothesis
2540 # @param fineness for the fineness [0-1]
2541 # @param UseExisting if ==true - search existing hypothesis created with
2542 # same parameters, else (default) - create new
2543 def AutomaticLength(self, fineness=0, UseExisting=0):
2544 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
2545 CompareMethod=self.CompareAutomaticLength)
2546 hyp.SetFineness( fineness )
2549 ## Check if the given "AutomaticLength" hypothesis has the same parameters as given arguments
2550 def CompareAutomaticLength(self, hyp, args):
2551 return IsEqual(hyp.GetFineness(), args[0])
2553 ## Define "SegmentLengthAroundVertex" hypothesis
2554 # @param length for the segment length
2555 # @param vertex for the length localization: vertex index [0,1] | vertex object.
2556 # Any other integer value means what hypo will be set on the
2557 # whole 1D shape, where Mesh_Segment algorithm is assigned.
2558 # @param UseExisting if ==true - search existing hypothesis created with
2559 # same parameters, else (default) - create new
2560 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
2562 store_geom = self.geom
2563 if type(vertex) is types.IntType:
2564 if vertex == 0 or vertex == 1:
2565 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
2573 if self.geom is None:
2574 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
2575 name = GetName(self.geom)
2577 piece = self.mesh.geom
2578 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
2579 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
2580 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
2582 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
2584 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
2585 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
2587 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
2588 CompareMethod=self.CompareLengthNearVertex)
2589 self.geom = store_geom
2590 hyp.SetLength( length )
2593 ## Check if the given "LengthNearVertex" hypothesis has the same parameters as given arguments
2594 def CompareLengthNearVertex(self, hyp, args):
2595 return IsEqual(hyp.GetLength(), args[0])
2597 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
2598 # If the 2D mesher sees that all boundary edges are quadratic ones,
2599 # it generates quadratic faces, else it generates linear faces using
2600 # medium nodes as if they were vertex ones.
2601 # The 3D mesher generates quadratic volumes only if all boundary faces
2602 # are quadratic ones, else it fails.
2603 def QuadraticMesh(self):
2604 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2607 # Public class: Mesh_CompositeSegment
2608 # --------------------------
2610 ## Class to define a segment 1D algorithm for discretization
2613 class Mesh_CompositeSegment(Mesh_Segment):
2615 ## Private constructor.
2616 def __init__(self, mesh, geom=0):
2617 self.Create(mesh, geom, "CompositeSegment_1D")
2620 # Public class: Mesh_Segment_Python
2621 # ---------------------------------
2623 ## Class to define a segment 1D algorithm for discretization with python function
2626 class Mesh_Segment_Python(Mesh_Segment):
2628 ## Private constructor.
2629 def __init__(self, mesh, geom=0):
2630 import Python1dPlugin
2631 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
2633 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
2634 # @param n for the number of segments that cut an edge
2635 # @param func for the python function that calculate the length of all segments
2636 # @param UseExisting if ==true - search existing hypothesis created with
2637 # same parameters, else (default) - create new
2638 def PythonSplit1D(self, n, func, UseExisting=0):
2639 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
2640 UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
2641 hyp.SetNumberOfSegments(n)
2642 hyp.SetPythonLog10RatioFunction(func)
2645 ## Check if the given "PythonSplit1D" hypothesis has the same parameters as given arguments
2646 def ComparePythonSplit1D(self, hyp, args):
2647 #if hyp.GetNumberOfSegments() == args[0]:
2648 # if hyp.GetPythonLog10RatioFunction() == args[1]:
2652 # Public class: Mesh_Triangle
2653 # ---------------------------
2655 ## Class to define a triangle 2D algorithm
2658 class Mesh_Triangle(Mesh_Algorithm):
2667 ## Private constructor.
2668 def __init__(self, mesh, algoType, geom=0):
2669 Mesh_Algorithm.__init__(self)
2671 self.algoType = algoType
2672 if algoType == MEFISTO:
2673 self.Create(mesh, geom, "MEFISTO_2D")
2675 elif algoType == BLSURF:
2677 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
2678 self.SetPhysicalMesh()
2679 elif algoType == NETGEN:
2681 print "Warning: NETGENPlugin module unavailable"
2683 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
2685 elif algoType == NETGEN_2D:
2687 print "Warning: NETGENPlugin module unavailable"
2689 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
2692 ## Define "MaxElementArea" hypothesis to give the maximum area of each triangle
2693 # @param area for the maximum area of each triangle
2694 # @param UseExisting if ==true - search existing hypothesis created with
2695 # same parameters, else (default) - create new
2697 # Only for algoType == MEFISTO || NETGEN_2D
2698 def MaxElementArea(self, area, UseExisting=0):
2699 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2700 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
2701 CompareMethod=self.CompareMaxElementArea)
2702 hyp.SetMaxElementArea(area)
2704 elif self.algoType == NETGEN:
2705 print "Netgen 1D-2D algo doesn't support this hypothesis"
2708 ## Check if the given "MaxElementArea" hypothesis has the same parameters as given arguments
2709 def CompareMaxElementArea(self, hyp, args):
2710 return IsEqual(hyp.GetMaxElementArea(), args[0])
2712 ## Define "LengthFromEdges" hypothesis to build triangles
2713 # based on the length of the edges taken from the wire
2715 # Only for algoType == MEFISTO || NETGEN_2D
2716 def LengthFromEdges(self):
2717 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
2718 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2720 elif self.algoType == NETGEN:
2721 print "Netgen 1D-2D algo doesn't support this hypothesis"
2725 # @param thePhysicalMesh is:
2726 # DefaultSize or Custom
2727 def SetPhysicalMesh(self, thePhysicalMesh=1):
2728 if self.params == 0:
2730 self.params.SetPhysicalMesh(thePhysicalMesh)
2733 def SetPhySize(self, theVal):
2734 if self.params == 0:
2736 self.params.SetPhySize(theVal)
2738 ## Set GeometricMesh
2739 # @param theGeometricMesh is:
2740 # DefaultGeom or Custom
2741 def SetGeometricMesh(self, theGeometricMesh=0):
2742 if self.params == 0:
2744 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
2745 self.params.SetGeometricMesh(theGeometricMesh)
2747 ## Set AngleMeshS flag
2748 def SetAngleMeshS(self, theVal=_angleMeshS):
2749 if self.params == 0:
2751 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
2752 self.params.SetAngleMeshS(theVal)
2754 ## Set Gradation flag
2755 def SetGradation(self, theVal=_gradation):
2756 if self.params == 0:
2758 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
2759 self.params.SetGradation(theVal)
2761 ## Set QuadAllowed flag
2763 # Only for algoType == NETGEN || NETGEN_2D
2764 def SetQuadAllowed(self, toAllow=True):
2765 if self.algoType == NETGEN_2D:
2766 if toAllow: # add QuadranglePreference
2767 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
2768 else: # remove QuadranglePreference
2769 for hyp in self.mesh.GetHypothesisList( self.geom ):
2770 if hyp.GetName() == "QuadranglePreference":
2771 self.mesh.RemoveHypothesis( self.geom, hyp )
2776 if self.params == 0:
2779 self.params.SetQuadAllowed(toAllow)
2782 ## Define "Netgen 2D Parameters" hypothesis
2784 # Only for algoType == NETGEN
2785 def Parameters(self):
2786 if self.algoType == NETGEN:
2787 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
2788 "libNETGENEngine.so", UseExisting=0)
2790 elif self.algoType == MEFISTO:
2791 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
2793 elif self.algoType == NETGEN_2D:
2794 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
2795 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
2797 elif self.algoType == BLSURF:
2798 self.params = self.Hypothesis("BLSURF_Parameters", [],
2799 "libBLSURFEngine.so", UseExisting=0)
2805 # Only for algoType == NETGEN
2806 def SetMaxSize(self, theSize):
2807 if self.params == 0:
2809 if self.params is not None:
2810 self.params.SetMaxSize(theSize)
2812 ## Set SecondOrder flag
2814 # Only for algoType == NETGEN
2815 def SetSecondOrder(self, theVal):
2816 if self.params == 0:
2818 if self.params is not None:
2819 self.params.SetSecondOrder(theVal)
2821 ## Set Optimize flag
2823 # Only for algoType == NETGEN
2824 def SetOptimize(self, theVal):
2825 if self.params == 0:
2827 if self.params is not None:
2828 self.params.SetOptimize(theVal)
2831 # @param theFineness is:
2832 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
2834 # Only for algoType == NETGEN
2835 def SetFineness(self, theFineness):
2836 if self.params == 0:
2838 if self.params is not None:
2839 self.params.SetFineness(theFineness)
2843 # Only for algoType == NETGEN
2844 def SetGrowthRate(self, theRate):
2845 if self.params == 0:
2847 if self.params is not None:
2848 self.params.SetGrowthRate(theRate)
2852 # Only for algoType == NETGEN
2853 def SetNbSegPerEdge(self, theVal):
2854 if self.params == 0:
2856 if self.params is not None:
2857 self.params.SetNbSegPerEdge(theVal)
2859 ## Set NbSegPerRadius
2861 # Only for algoType == NETGEN
2862 def SetNbSegPerRadius(self, theVal):
2863 if self.params == 0:
2865 if self.params is not None:
2866 self.params.SetNbSegPerRadius(theVal)
2868 ## Set Decimesh flag
2869 def SetDecimesh(self, toAllow=False):
2870 if self.params == 0:
2872 self.params.SetDecimesh(toAllow)
2877 # Public class: Mesh_Quadrangle
2878 # -----------------------------
2880 ## Class to define a quadrangle 2D algorithm
2883 class Mesh_Quadrangle(Mesh_Algorithm):
2885 ## Private constructor.
2886 def __init__(self, mesh, geom=0):
2887 Mesh_Algorithm.__init__(self)
2888 self.Create(mesh, geom, "Quadrangle_2D")
2890 ## Define "QuadranglePreference" hypothesis, forcing construction
2891 # of quadrangles if the number of nodes on opposite edges is not the same
2892 # in the case where the global number of nodes on edges is even
2893 def QuadranglePreference(self):
2894 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
2895 CompareMethod=self.CompareEqualHyp)
2898 # Public class: Mesh_Tetrahedron
2899 # ------------------------------
2901 ## Class to define a tetrahedron 3D algorithm
2904 class Mesh_Tetrahedron(Mesh_Algorithm):
2909 ## Private constructor.
2910 def __init__(self, mesh, algoType, geom=0):
2911 Mesh_Algorithm.__init__(self)
2913 if algoType == NETGEN:
2914 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
2917 elif algoType == GHS3D:
2919 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
2922 elif algoType == FULL_NETGEN:
2924 print "Warning: NETGENPlugin module has not been imported."
2925 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
2928 self.algoType = algoType
2930 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
2931 # @param vol for the maximum volume of each tetrahedral
2932 # @param UseExisting if ==true - search existing hypothesis created with
2933 # same parameters, else (default) - create new
2934 def MaxElementVolume(self, vol, UseExisting=0):
2935 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
2936 CompareMethod=self.CompareMaxElementVolume)
2937 hyp.SetMaxElementVolume(vol)
2940 ## Check if the given "MaxElementVolume" hypothesis has the same parameters as given arguments
2941 def CompareMaxElementVolume(self, hyp, args):
2942 return IsEqual(hyp.GetMaxElementVolume(), args[0])
2944 ## Define "Netgen 3D Parameters" hypothesis
2945 def Parameters(self):
2946 if (self.algoType == FULL_NETGEN):
2947 self.params = self.Hypothesis("NETGEN_Parameters", [],
2948 "libNETGENEngine.so", UseExisting=0)
2951 print "Algo doesn't support this hypothesis"
2955 def SetMaxSize(self, theSize):
2956 if self.params == 0:
2958 self.params.SetMaxSize(theSize)
2960 ## Set SecondOrder flag
2961 def SetSecondOrder(self, theVal):
2962 if self.params == 0:
2964 self.params.SetSecondOrder(theVal)
2966 ## Set Optimize flag
2967 def SetOptimize(self, theVal):
2968 if self.params == 0:
2970 self.params.SetOptimize(theVal)
2973 # @param theFineness is:
2974 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
2975 def SetFineness(self, theFineness):
2976 if self.params == 0:
2978 self.params.SetFineness(theFineness)
2981 def SetGrowthRate(self, theRate):
2982 if self.params == 0:
2984 self.params.SetGrowthRate(theRate)
2987 def SetNbSegPerEdge(self, theVal):
2988 if self.params == 0:
2990 self.params.SetNbSegPerEdge(theVal)
2992 ## Set NbSegPerRadius
2993 def SetNbSegPerRadius(self, theVal):
2994 if self.params == 0:
2996 self.params.SetNbSegPerRadius(theVal)
2998 # Public class: Mesh_Hexahedron
2999 # ------------------------------
3001 ## Class to define a hexahedron 3D algorithm
3004 class Mesh_Hexahedron(Mesh_Algorithm):
3009 ## Private constructor.
3010 def __init__(self, mesh, algoType=Hexa, geom=0):
3011 Mesh_Algorithm.__init__(self)
3013 self.algoType = algoType
3015 if algoType == Hexa:
3016 self.Create(mesh, geom, "Hexa_3D")
3019 elif algoType == Hexotic:
3020 import HexoticPlugin
3021 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
3024 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
3025 def MinMaxQuad(self, min=3, max=8, quad=True):
3026 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
3028 self.params.SetHexesMinLevel(min)
3029 self.params.SetHexesMaxLevel(max)
3030 self.params.SetHexoticQuadrangles(quad)
3033 # Deprecated, only for compatibility!
3034 # Public class: Mesh_Netgen
3035 # ------------------------------
3037 ## Class to define a NETGEN-based 2D or 3D algorithm
3038 # that need no discrete boundary (i.e. independent)
3040 # This class is deprecated, only for compatibility!
3043 class Mesh_Netgen(Mesh_Algorithm):
3047 ## Private constructor.
3048 def __init__(self, mesh, is3D, geom=0):
3049 Mesh_Algorithm.__init__(self)
3052 print "Warning: NETGENPlugin module has not been imported."
3056 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
3060 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
3063 ## Define hypothesis containing parameters of the algorithm
3064 def Parameters(self):
3066 hyp = self.Hypothesis("NETGEN_Parameters", [],
3067 "libNETGENEngine.so", UseExisting=0)
3069 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
3070 "libNETGENEngine.so", UseExisting=0)
3073 # Public class: Mesh_Projection1D
3074 # ------------------------------
3076 ## Class to define a projection 1D algorithm
3079 class Mesh_Projection1D(Mesh_Algorithm):
3081 ## Private constructor.
3082 def __init__(self, mesh, geom=0):
3083 Mesh_Algorithm.__init__(self)
3084 self.Create(mesh, geom, "Projection_1D")
3086 ## Define "Source Edge" hypothesis, specifying a meshed edge to
3087 # take a mesh pattern from, and optionally association of vertices
3088 # between the source edge and a target one (where a hipothesis is assigned to)
3089 # @param edge to take nodes distribution from
3090 # @param mesh to take nodes distribution from (optional)
3091 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
3092 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
3093 # to associate with \a srcV (optional)
3094 # @param UseExisting if ==true - search existing hypothesis created with
3095 # same parameters, else (default) - create new
3096 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
3097 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
3099 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
3100 hyp.SetSourceEdge( edge )
3101 if not mesh is None and isinstance(mesh, Mesh):
3102 mesh = mesh.GetMesh()
3103 hyp.SetSourceMesh( mesh )
3104 hyp.SetVertexAssociation( srcV, tgtV )
3107 ## Check if the given "SourceEdge" hypothesis has the same parameters as given arguments
3108 #def CompareSourceEdge(self, hyp, args):
3109 # # seems to be not really useful to reuse existing "SourceEdge" hypothesis
3113 # Public class: Mesh_Projection2D
3114 # ------------------------------
3116 ## Class to define a projection 2D algorithm
3119 class Mesh_Projection2D(Mesh_Algorithm):
3121 ## Private constructor.
3122 def __init__(self, mesh, geom=0):
3123 Mesh_Algorithm.__init__(self)
3124 self.Create(mesh, geom, "Projection_2D")
3126 ## Define "Source Face" hypothesis, specifying a meshed face to
3127 # take a mesh pattern from, and optionally association of vertices
3128 # between the source face and a target one (where a hipothesis is assigned to)
3129 # @param face to take mesh pattern from
3130 # @param mesh to take mesh pattern from (optional)
3131 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
3132 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
3133 # to associate with \a srcV1 (optional)
3134 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
3135 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
3136 # to associate with \a srcV2 (optional)
3137 # @param UseExisting if ==true - search existing hypothesis created with
3138 # same parameters, else (default) - create new
3140 # Note: association vertices must belong to one edge of a face
3141 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
3142 srcV2=None, tgtV2=None, UseExisting=0):
3143 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
3145 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
3146 hyp.SetSourceFace( face )
3147 if not mesh is None and isinstance(mesh, Mesh):
3148 mesh = mesh.GetMesh()
3149 hyp.SetSourceMesh( mesh )
3150 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3153 ## Check if the given "SourceFace" hypothesis has the same parameters as given arguments
3154 #def CompareSourceFace(self, hyp, args):
3155 # # seems to be not really useful to reuse existing "SourceFace" hypothesis
3158 # Public class: Mesh_Projection3D
3159 # ------------------------------
3161 ## Class to define a projection 3D algorithm
3164 class Mesh_Projection3D(Mesh_Algorithm):
3166 ## Private constructor.
3167 def __init__(self, mesh, geom=0):
3168 Mesh_Algorithm.__init__(self)
3169 self.Create(mesh, geom, "Projection_3D")
3171 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
3172 # take a mesh pattern from, and optionally association of vertices
3173 # between the source solid and a target one (where a hipothesis is assigned to)
3174 # @param solid to take mesh pattern from
3175 # @param mesh to take mesh pattern from (optional)
3176 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
3177 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
3178 # to associate with \a srcV1 (optional)
3179 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
3180 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
3181 # to associate with \a srcV2 (optional)
3182 # @param UseExisting - if ==true - search existing hypothesis created with
3183 # same parameters, else (default) - create new
3185 # Note: association vertices must belong to one edge of a solid
3186 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
3187 srcV2=0, tgtV2=0, UseExisting=0):
3188 hyp = self.Hypothesis("ProjectionSource3D",
3189 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
3191 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
3192 hyp.SetSource3DShape( solid )
3193 if not mesh is None and isinstance(mesh, Mesh):
3194 mesh = mesh.GetMesh()
3195 hyp.SetSourceMesh( mesh )
3196 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
3199 ## Check if the given "SourceShape3D" hypothesis has the same parameters as given arguments
3200 #def CompareSourceShape3D(self, hyp, args):
3201 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
3205 # Public class: Mesh_Prism
3206 # ------------------------
3208 ## Class to define a 3D extrusion algorithm
3211 class Mesh_Prism3D(Mesh_Algorithm):
3213 ## Private constructor.
3214 def __init__(self, mesh, geom=0):
3215 Mesh_Algorithm.__init__(self)
3216 self.Create(mesh, geom, "Prism_3D")
3218 # Public class: Mesh_RadialPrism
3219 # -------------------------------
3221 ## Class to define a Radial Prism 3D algorithm
3224 class Mesh_RadialPrism3D(Mesh_Algorithm):
3226 ## Private constructor.
3227 def __init__(self, mesh, geom=0):
3228 Mesh_Algorithm.__init__(self)
3229 self.Create(mesh, geom, "RadialPrism_3D")
3231 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
3232 self.nbLayers = None
3234 ## Return 3D hypothesis holding the 1D one
3235 def Get3DHypothesis(self):
3236 return self.distribHyp
3238 ## Private method creating 1D hypothes and storing it in the LayerDistribution
3239 # hypothes. Returns the created hypothes
3240 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
3241 #print "OwnHypothesis",hypType
3242 if not self.nbLayers is None:
3243 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
3244 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
3245 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
3246 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
3247 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
3248 self.distribHyp.SetLayerDistribution( hyp )
3251 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
3252 # prisms to build between the inner and outer shells
3253 # @param UseExisting if ==true - search existing hypothesis created with
3254 # same parameters, else (default) - create new
3255 def NumberOfLayers(self, n, UseExisting=0):
3256 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
3257 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
3258 CompareMethod=self.CompareNumberOfLayers)
3259 self.nbLayers.SetNumberOfLayers( n )
3260 return self.nbLayers
3262 ## Check if the given "NumberOfLayers" hypothesis has the same parameters as given arguments
3263 def CompareNumberOfLayers(self, hyp, args):
3264 return IsEqual(hyp.GetNumberOfLayers(), args[0])
3266 ## Define "LocalLength" hypothesis, specifying segment length
3267 # to build between the inner and outer shells
3268 # @param l for the length of segments
3269 # @param p for the precision of rounding
3270 def LocalLength(self, l, p=1e-07):
3271 hyp = self.OwnHypothesis("LocalLength", [l,p])
3276 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
3277 # prisms to build between the inner and outer shells
3278 # @param n for the number of segments
3279 # @param s for the scale factor (optional)
3280 def NumberOfSegments(self, n, s=[]):
3282 hyp = self.OwnHypothesis("NumberOfSegments", [n])
3284 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
3285 hyp.SetDistrType( 1 )
3286 hyp.SetScaleFactor(s)
3287 hyp.SetNumberOfSegments(n)
3290 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
3291 # to build between the inner and outer shells as arithmetic length increasing
3292 # @param start for the length of the first segment
3293 # @param end for the length of the last segment
3294 def Arithmetic1D(self, start, end ):
3295 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
3296 hyp.SetLength(start, 1)
3297 hyp.SetLength(end , 0)
3300 ## Define "StartEndLength" hypothesis, specifying distribution of segments
3301 # to build between the inner and outer shells as geometric length increasing
3302 # @param start for the length of the first segment
3303 # @param end for the length of the last segment
3304 def StartEndLength(self, start, end):
3305 hyp = self.OwnHypothesis("StartEndLength", [start, end])
3306 hyp.SetLength(start, 1)
3307 hyp.SetLength(end , 0)
3310 ## Define "AutomaticLength" hypothesis, specifying number of segments
3311 # to build between the inner and outer shells
3312 # @param fineness for the fineness [0-1]
3313 def AutomaticLength(self, fineness=0):
3314 hyp = self.OwnHypothesis("AutomaticLength")
3315 hyp.SetFineness( fineness )
3318 # Private class: Mesh_UseExisting
3319 # -------------------------------
3320 class Mesh_UseExisting(Mesh_Algorithm):
3322 def __init__(self, dim, mesh, geom=0):
3324 self.Create(mesh, geom, "UseExisting_1D")
3326 self.Create(mesh, geom, "UseExisting_2D")