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
37 # import NETGENPlugin module if possible
57 # MirrorType enumeration
58 POINT = SMESH_MeshEditor.POINT
59 AXIS = SMESH_MeshEditor.AXIS
60 PLANE = SMESH_MeshEditor.PLANE
62 # Smooth_Method enumeration
63 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
64 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
66 # Fineness enumeration(for NETGEN)
78 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
79 smesh.SetCurrentStudy(salome.myStudy)
85 ior = salome.orb.object_to_string(obj)
86 sobj = salome.myStudy.FindObjectIOR(ior)
90 attr = sobj.FindAttribute("AttributeName")[1]
93 ## Sets name to object
94 def SetName(obj, name):
95 ior = salome.orb.object_to_string(obj)
96 sobj = salome.myStudy.FindObjectIOR(ior)
98 attr = sobj.FindAttribute("AttributeName")[1]
101 ## Returns long value from enumeration
102 # Uses for SMESH.FunctorType enumeration
103 def EnumToLong(theItem):
106 ## Get PointStruct from vertex
107 # @param theVertex is GEOM object(vertex)
108 # @return SMESH.PointStruct
109 def GetPointStruct(theVertex):
110 [x, y, z] = geompy.PointCoordinates(theVertex)
111 return PointStruct(x,y,z)
113 ## Get DirStruct from vector
114 # @param theVector is GEOM object(vector)
115 # @return SMESH.DirStruct
116 def GetDirStruct(theVector):
117 vertices = geompy.SubShapeAll( theVector, geompy.ShapeType["VERTEX"] )
118 if(len(vertices) != 2):
119 print "Error: vector object is incorrect."
121 p1 = geompy.PointCoordinates(vertices[0])
122 p2 = geompy.PointCoordinates(vertices[1])
123 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
127 ## Get AxisStruct from object
128 # @param theObj is GEOM object(line or plane)
129 # @return SMESH.AxisStruct
130 def GetAxisStruct(theObj):
131 edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
133 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
134 vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
135 vertex1 = geompy.PointCoordinates(vertex1)
136 vertex2 = geompy.PointCoordinates(vertex2)
137 vertex3 = geompy.PointCoordinates(vertex3)
138 vertex4 = geompy.PointCoordinates(vertex4)
139 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
140 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
141 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] ]
142 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
144 elif len(edges) == 1:
145 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
146 p1 = geompy.PointCoordinates( vertex1 )
147 p2 = geompy.PointCoordinates( vertex2 )
148 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
152 # From SMESH_Gen interface:
153 # ------------------------
155 ## Set the current mode
156 def SetEmbeddedMode( theMode ):
157 smesh.SetEmbeddedMode(theMode)
159 ## Get the current mode
160 def IsEmbeddedMode():
161 return smesh.IsEmbeddedMode()
163 ## Set the current study
164 def SetCurrentStudy( theStudy ):
165 smesh.SetCurrentStudy(theStudy)
167 ## Get the current study
168 def GetCurrentStudy():
169 return smesh.GetCurrentStudy()
171 ## Create Mesh object importing data from given UNV file
172 # @return an instance of Mesh class
173 def CreateMeshesFromUNV( theFileName ):
174 aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
175 aMesh = Mesh(aSmeshMesh)
178 ## Create Mesh object(s) importing data from given MED file
179 # @return a list of Mesh class instances
180 def CreateMeshesFromMED( theFileName ):
181 aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
183 for iMesh in range(len(aSmeshMeshes)) :
184 aMesh = Mesh(aSmeshMeshes[iMesh])
185 aMeshes.append(aMesh)
186 return aMeshes, aStatus
188 ## Create Mesh object importing data from given STL file
189 # @return an instance of Mesh class
190 def CreateMeshesFromSTL( theFileName ):
191 aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
192 aMesh = Mesh(aSmeshMesh)
195 ## From SMESH_Gen interface
196 def GetSubShapesId( theMainObject, theListOfSubObjects ):
197 return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
199 ## From SMESH_Gen interface. Creates pattern
201 return smesh.GetPattern()
205 # Filtering. Auxiliary functions:
206 # ------------------------------
208 ## Creates an empty criterion
209 # @return SMESH.Filter.Criterion
210 def GetEmptyCriterion():
211 Type = EnumToLong(FT_Undefined)
212 Compare = EnumToLong(FT_Undefined)
216 UnaryOp = EnumToLong(FT_Undefined)
217 BinaryOp = EnumToLong(FT_Undefined)
220 Precision = -1 ##@1e-07
221 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
222 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
224 ## Creates a criterion by given parameters
225 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
226 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
227 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
228 # @param Treshold is threshold value (range of ids as string, shape, numeric)
229 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
230 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
231 # FT_Undefined(must be for the last criterion in criteria)
232 # @return SMESH.Filter.Criterion
233 def GetCriterion(elementType,
235 Compare = FT_EqualTo,
237 UnaryOp=FT_Undefined,
238 BinaryOp=FT_Undefined):
239 aCriterion = GetEmptyCriterion()
240 aCriterion.TypeOfElement = elementType
241 aCriterion.Type = EnumToLong(CritType)
245 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
246 aCriterion.Compare = EnumToLong(Compare)
248 aCriterion.Compare = EnumToLong(FT_EqualTo)
251 if CritType in [FT_BelongToGeom, FT_BelongToPlane,
252 FT_BelongToCylinder, FT_LyingOnGeom]:
254 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
255 aCriterion.ThresholdStr = GetName(aTreshold)
256 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
258 print "Error: Treshold should be a shape."
260 elif CritType == FT_RangeOfIds:
262 if isinstance(aTreshold, str):
263 aCriterion.ThresholdStr = aTreshold
265 print "Error: Treshold should be a string."
267 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
268 # Here we don't need treshold
269 if aTreshold == FT_LogicalNOT:
270 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
271 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
272 aCriterion.BinaryOp = aTreshold
276 aTreshold = float(aTreshold)
277 aCriterion.Threshold = aTreshold
279 print "Error: Treshold should be a number."
282 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
283 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
285 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
286 aCriterion.BinaryOp = EnumToLong(Treshold)
288 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
289 aCriterion.BinaryOp = EnumToLong(UnaryOp)
291 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
292 aCriterion.BinaryOp = EnumToLong(BinaryOp)
296 ## Creates filter by given parameters of criterion
297 # @param elementType is the type of elements in the group
298 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
299 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
300 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
301 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
302 # @return SMESH_Filter
303 def GetFilter(elementType,
304 CritType=FT_Undefined,
307 UnaryOp=FT_Undefined):
308 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
309 aFilterMgr = smesh.CreateFilterManager()
310 aFilter = aFilterMgr.CreateFilter()
312 aCriteria.append(aCriterion)
313 aFilter.SetCriteria(aCriteria)
316 ## Creates numerical functor by its type
317 # @param theCrierion is FT_...; functor type
318 # @return SMESH_NumericalFunctor
319 def GetFunctor(theCriterion):
320 aFilterMgr = smesh.CreateFilterManager()
321 if theCriterion == FT_AspectRatio:
322 return aFilterMgr.CreateAspectRatio()
323 elif theCriterion == FT_AspectRatio3D:
324 return aFilterMgr.CreateAspectRatio3D()
325 elif theCriterion == FT_Warping:
326 return aFilterMgr.CreateWarping()
327 elif theCriterion == FT_MinimumAngle:
328 return aFilterMgr.CreateMinimumAngle()
329 elif theCriterion == FT_Taper:
330 return aFilterMgr.CreateTaper()
331 elif theCriterion == FT_Skew:
332 return aFilterMgr.CreateSkew()
333 elif theCriterion == FT_Area:
334 return aFilterMgr.CreateArea()
335 elif theCriterion == FT_Volume3D:
336 return aFilterMgr.CreateVolume3D()
337 elif theCriterion == FT_MultiConnection:
338 return aFilterMgr.CreateMultiConnection()
339 elif theCriterion == FT_MultiConnection2D:
340 return aFilterMgr.CreateMultiConnection2D()
341 elif theCriterion == FT_Length:
342 return aFilterMgr.CreateLength()
343 elif theCriterion == FT_Length2D:
344 return aFilterMgr.CreateLength2D()
346 print "Error: given parameter is not numerucal functor type."
351 ## Mother class to define algorithm, recommended to don't use directly.
354 class Mesh_Algorithm:
355 # @class Mesh_Algorithm
356 # @brief Class Mesh_Algorithm
363 ## If the algorithm is global, return 0; \n
364 # else return the submesh associated to this algorithm.
365 def GetSubMesh(self):
368 ## Return the wrapped mesher.
369 def GetAlgorithm(self):
372 ## Get list of hypothesis that can be used with this algorithm
373 def GetCompatibleHypothesis(self):
376 list = self.algo.GetCompatibleHypothesis()
384 def SetName(self, name):
385 SetName(self.algo, name)
389 return self.algo.GetId()
391 ## Private method. Print error message if a hypothesis was not assigned.
392 def TreatHypoStatus(self, status, hypName, geomName, isAlgo):
394 hypType = "algorithm"
396 hypType = "hypothesis"
397 if status == HYP_UNKNOWN_FATAL :
398 reason = "for unknown reason"
399 elif status == HYP_INCOMPATIBLE :
400 reason = "this hypothesis mismatches algorithm"
401 elif status == HYP_NOTCONFORM :
402 reason = "not conform mesh would be built"
403 elif status == HYP_ALREADY_EXIST :
404 reason = hypType + " of the same dimension already assigned to this shape"
405 elif status == HYP_BAD_DIM :
406 reason = hypType + " mismatches shape"
407 elif status == HYP_CONCURENT :
408 reason = "there are concurrent hypotheses on sub-shapes"
409 elif status == HYP_BAD_SUBSHAPE :
410 reason = "shape is neither the main one, nor its subshape, nor a valid group"
411 elif status == HYP_BAD_GEOMETRY:
412 reason = "geometry mismatches algorithm's expectation"
415 hypName = '"' + hypName + '"'
416 geomName= '"' + geomName+ '"'
417 if status < HYP_UNKNOWN_FATAL:
418 print hypName, "was assigned to", geomName,"but", reason
420 print hypName, "was not assigned to",geomName,":", reason
424 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
426 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
431 name = GetName(piece)
436 name = geompy.SubShapeName(geom, piece)
437 geompy.addToStudyInFather(piece, geom, name)
438 self.subm = mesh.mesh.GetSubMesh(geom, hypo)
440 self.algo = smesh.CreateHypothesis(hypo, so)
441 SetName(self.algo, name + "/" + hypo)
442 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
443 self.TreatHypoStatus( status, hypo, name, 1 )
446 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
447 hypo = smesh.CreateHypothesis(hyp, so)
453 a = a + s + str(args[i])
456 name = GetName(self.geom)
457 SetName(hypo, name + "/" + hyp + a)
458 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
459 self.TreatHypoStatus( status, hyp, name, 0 )
463 # Public class: Mesh_Segment
464 # --------------------------
466 ## Class to define a segment 1D algorithm for discretization
469 class Mesh_Segment(Mesh_Algorithm):
471 ## Private constructor.
472 def __init__(self, mesh, geom=0):
473 self.Create(mesh, geom, "Regular_1D")
475 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
476 # @param l for the length of segments that cut an edge
477 def LocalLength(self, l):
478 hyp = self.Hypothesis("LocalLength", [l])
482 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
483 # @param n for the number of segments that cut an edge
484 # @param s for the scale factor (optional)
485 def NumberOfSegments(self, n, s=[]):
487 hyp = self.Hypothesis("NumberOfSegments", [n])
489 hyp = self.Hypothesis("NumberOfSegments", [n,s])
490 hyp.SetDistrType( 1 )
491 hyp.SetScaleFactor(s)
492 hyp.SetNumberOfSegments(n)
495 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
496 # @param start for the length of the first segment
497 # @param end for the length of the last segment
498 def Arithmetic1D(self, start, end):
499 hyp = self.Hypothesis("Arithmetic1D", [start, end])
500 hyp.SetLength(start, 1)
501 hyp.SetLength(end , 0)
504 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
505 # @param start for the length of the first segment
506 # @param end for the length of the last segment
507 def StartEndLength(self, start, end):
508 hyp = self.Hypothesis("StartEndLength", [start, end])
509 hyp.SetLength(start, 1)
510 hyp.SetLength(end , 0)
513 ## Define "Deflection1D" hypothesis
514 # @param d for the deflection
515 def Deflection1D(self, d):
516 hyp = self.Hypothesis("Deflection1D", [d])
520 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
521 # the opposite side in the case of quadrangular faces
522 def Propagation(self):
523 return self.Hypothesis("Propagation")
525 ## Define "AutomaticLength" hypothesis
526 # @param fineness for the fineness [0-1]
527 def AutomaticLength(self, fineness=0):
528 hyp = self.Hypothesis("AutomaticLength")
529 hyp.SetFineness( fineness )
532 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
533 # If the 2D mesher sees that all boundary edges are quadratic ones,
534 # it generates quadratic faces, else it generates linear faces using
535 # medium nodes as if they were vertex ones.
536 # The 3D mesher generates quadratic volumes only if all boundary faces
537 # are quadratic ones, else it fails.
538 def QuadraticMesh(self):
539 hyp = self.Hypothesis("QuadraticMesh")
542 # Public class: Mesh_Segment_Python
543 # ---------------------------------
545 ## Class to define a segment 1D algorithm for discretization with python function
548 class Mesh_Segment_Python(Mesh_Segment):
550 ## Private constructor.
551 def __init__(self, mesh, geom=0):
552 import Python1dPlugin
553 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
555 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
556 # @param n for the number of segments that cut an edge
557 # @param func for the python function that calculate the length of all segments
558 def PythonSplit1D(self, n, func):
559 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
560 hyp.SetNumberOfSegments(n)
561 hyp.SetPythonLog10RatioFunction(func)
564 # Public class: Mesh_Triangle
565 # ---------------------------
567 ## Class to define a triangle 2D algorithm
570 class Mesh_Triangle(Mesh_Algorithm):
577 ## Private constructor.
578 def __init__(self, mesh, algoType, geom=0):
579 self.algoType = algoType
580 if algoType == MEFISTO:
581 self.Create(mesh, geom, "MEFISTO_2D")
582 elif algoType == BLSURF:
584 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
585 self.SetPhysicalMesh()
586 elif algoType == NETGEN:
588 print "Warning: NETGENPlugin module has not been imported."
589 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
591 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
592 # @param area for the maximum area of each triangles
593 def MaxElementArea(self, area):
594 if self.algoType == MEFISTO:
595 hyp = self.Hypothesis("MaxElementArea", [area])
596 hyp.SetMaxElementArea(area)
598 elif self.algoType == NETGEN:
599 print "Netgen 1D-2D algo doesn't support this hypothesis"
602 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
603 def LengthFromEdges(self):
604 if self.algoType == MEFISTO:
605 hyp = self.Hypothesis("LengthFromEdges")
607 elif self.algoType == NETGEN:
608 print "Netgen 1D-2D algo doesn't support this hypothesis"
611 ## Define "Netgen 2D Parameters" hypothesis
612 def Parameters(self):
613 if self.algoType == NETGEN:
614 self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
616 elif self.algoType == MEFISTO:
617 print "Mefisto algo doesn't support this hypothesis"
619 elif self.algoType == BLSURF:
620 self.params = self.Hypothesis("BLSURF_Parameters", [], "libBLSURFEngine.so")
624 def SetMaxSize(self, theSize):
627 self.params.SetMaxSize(theSize)
629 ## Set SecondOrder flag
630 def SetSecondOrder(seld, theVal):
633 self.params.SetSecondOrder(theVal)
636 def SetOptimize(self, theVal):
639 self.params.SetOptimize(theVal)
642 # @param theFineness is:
643 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
644 def SetFineness(self, theFineness):
647 self.params.SetFineness(theFineness)
650 def SetGrowthRate(self, theRate):
653 self.params.SetGrowthRate(theRate)
656 def SetNbSegPerEdge(self, theVal):
659 self.params.SetNbSegPerEdge(theVal)
661 ## Set NbSegPerRadius
662 def SetNbSegPerRadius(self, theVal):
665 self.params.SetNbSegPerRadius(theVal)
668 # @param thePhysicalMesh is:
669 # DefaultSize or Custom
670 def SetPhysicalMesh(self, thePhysicalMesh=1):
673 self.params.SetPhysicalMesh(thePhysicalMesh)
676 def SetPhySize(self, theVal):
679 self.params.SetPhySize(theVal)
682 # @param theGeometricMesh is:
683 # DefaultGeom or Custom
684 def SetGeometricMesh(self, theGeometricMesh=0):
687 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
688 self.params.SetGeometricMesh(theGeometricMesh)
690 ## Set AngleMeshS flag
691 def SetAngleMeshS(self, theVal=_angleMeshS):
694 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
695 self.params.SetAngleMeshS(theVal)
697 ## Set Gradation flag
698 def SetGradation(self, theVal=_gradation):
701 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
702 self.params.SetGradation(theVal)
704 ## Set QuadAllowed flag
705 def SetQuadAllowed(self, toAllow=False):
708 self.params.SetQuadAllowed(toAllow)
711 def SetDecimesh(self, toAllow=False):
714 self.params.SetDecimesh(toAllow)
716 # Public class: Mesh_Quadrangle
717 # -----------------------------
719 ## Class to define a quadrangle 2D algorithm
722 class Mesh_Quadrangle(Mesh_Algorithm):
724 ## Private constructor.
725 def __init__(self, mesh, geom=0):
726 self.Create(mesh, geom, "Quadrangle_2D")
728 ## Define "QuadranglePreference" hypothesis, forcing construction
729 # of quadrangles if the number of nodes on opposite edges is not the same
730 # in the case where the global number of nodes on edges is even
731 def QuadranglePreference(self):
732 hyp = self.Hypothesis("QuadranglePreference")
735 # Public class: Mesh_Tetrahedron
736 # ------------------------------
738 ## Class to define a tetrahedron 3D algorithm
741 class Mesh_Tetrahedron(Mesh_Algorithm):
746 ## Private constructor.
747 def __init__(self, mesh, algoType, geom=0):
748 if algoType == NETGEN:
749 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
750 elif algoType == GHS3D:
752 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
753 elif algoType == FULL_NETGEN:
755 print "Warning: NETGENPlugin module has not been imported."
756 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
757 self.algoType = algoType
759 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
760 # @param vol for the maximum volume of each tetrahedral
761 def MaxElementVolume(self, vol):
762 hyp = self.Hypothesis("MaxElementVolume", [vol])
763 hyp.SetMaxElementVolume(vol)
766 ## Define "Netgen 3D Parameters" hypothesis
767 def Parameters(self):
768 if (self.algoType == FULL_NETGEN):
769 self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
772 print "Algo doesn't support this hypothesis"
776 def SetMaxSize(self, theSize):
779 self.params.SetMaxSize(theSize)
781 ## Set SecondOrder flag
782 def SetSecondOrder(self, theVal):
785 self.params.SetSecondOrder(theVal)
788 def SetOptimize(self, theVal):
791 self.params.SetOptimize(theVal)
794 # @param theFineness is:
795 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
796 def SetFineness(self, theFineness):
799 self.params.SetFineness(theFineness)
802 def SetGrowthRate(self, theRate):
805 self.params.SetGrowthRate(theRate)
808 def SetNbSegPerEdge(self, theVal):
811 self.params.SetNbSegPerEdge(theVal)
813 ## Set NbSegPerRadius
814 def SetNbSegPerRadius(self, theVal):
817 self.params.SetNbSegPerRadius(theVal)
819 # Public class: Mesh_Hexahedron
820 # ------------------------------
822 ## Class to define a hexahedron 3D algorithm
825 class Mesh_Hexahedron(Mesh_Algorithm):
827 ## Private constructor.
828 ## def __init__(self, mesh, geom=0):
829 ## self.Create(mesh, geom, "Hexa_3D")
830 def __init__(self, mesh, algo, geom):
832 self.Create(mesh, geom, "Hexa_3D")
833 elif algo == Hexotic:
835 self.Create(mesh, geom, "Hexotic_3D" , "libHexoticEngine.so")
837 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
838 def MinMaxQuad(self, min=3, max=8, quad=True):
839 hyp = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so")
840 hyp.SetHexesMinLevel(min)
841 hyp.SetHexesMaxLevel(max)
842 hyp.SetHexoticQuadrangles(quad)
845 # Deprecated, only for compatibility!
846 # Public class: Mesh_Netgen
847 # ------------------------------
849 ## Class to define a NETGEN-based 2D or 3D algorithm
850 # that need no discrete boundary (i.e. independent)
852 # This class is deprecated, only for compatibility!
855 class Mesh_Netgen(Mesh_Algorithm):
859 ## Private constructor.
860 def __init__(self, mesh, is3D, geom=0):
862 print "Warning: NETGENPlugin module has not been imported."
866 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
868 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
870 ## Define hypothesis containing parameters of the algorithm
871 def Parameters(self):
873 hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
875 hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
878 # Public class: Mesh_Projection1D
879 # ------------------------------
881 ## Class to define a projection 1D algorithm
884 class Mesh_Projection1D(Mesh_Algorithm):
886 ## Private constructor.
887 def __init__(self, mesh, geom=0):
888 self.Create(mesh, geom, "Projection_1D")
890 ## Define "Source Edge" hypothesis, specifying a meshed edge to
891 # take a mesh pattern from, and optionally association of vertices
892 # between the source edge and a target one (where a hipothesis is assigned to)
893 # @param edge to take nodes distribution from
894 # @param mesh to take nodes distribution from (optional)
895 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
896 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
897 # to associate with \a srcV (optional)
898 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
899 hyp = self.Hypothesis("ProjectionSource1D")
900 hyp.SetSourceEdge( edge )
901 if not mesh is None and isinstance(mesh, Mesh):
902 mesh = mesh.GetMesh()
903 hyp.SetSourceMesh( mesh )
904 hyp.SetVertexAssociation( srcV, tgtV )
908 # Public class: Mesh_Projection2D
909 # ------------------------------
911 ## Class to define a projection 2D algorithm
914 class Mesh_Projection2D(Mesh_Algorithm):
916 ## Private constructor.
917 def __init__(self, mesh, geom=0):
918 self.Create(mesh, geom, "Projection_2D")
920 ## Define "Source Face" hypothesis, specifying a meshed face to
921 # take a mesh pattern from, and optionally association of vertices
922 # between the source face and a target one (where a hipothesis is assigned to)
923 # @param face to take mesh pattern from
924 # @param mesh to take mesh pattern from (optional)
925 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
926 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
927 # to associate with \a srcV1 (optional)
928 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
929 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
930 # to associate with \a srcV2 (optional)
932 # Note: association vertices must belong to one edge of a face
933 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
934 hyp = self.Hypothesis("ProjectionSource2D")
935 hyp.SetSourceFace( face )
936 if not mesh is None and isinstance(mesh, Mesh):
937 mesh = mesh.GetMesh()
938 hyp.SetSourceMesh( mesh )
939 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
942 # Public class: Mesh_Projection3D
943 # ------------------------------
945 ## Class to define a projection 3D algorithm
948 class Mesh_Projection3D(Mesh_Algorithm):
950 ## Private constructor.
951 def __init__(self, mesh, geom=0):
952 self.Create(mesh, geom, "Projection_3D")
954 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
955 # take a mesh pattern from, and optionally association of vertices
956 # between the source solid and a target one (where a hipothesis is assigned to)
957 # @param solid to take mesh pattern from
958 # @param mesh to take mesh pattern from (optional)
959 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
960 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
961 # to associate with \a srcV1 (optional)
962 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
963 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
964 # to associate with \a srcV2 (optional)
966 # Note: association vertices must belong to one edge of a solid
967 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
968 hyp = self.Hypothesis("ProjectionSource3D")
969 hyp.SetSource3DShape( solid )
970 if not mesh is None and isinstance(mesh, Mesh):
971 mesh = mesh.GetMesh()
972 hyp.SetSourceMesh( mesh )
973 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
977 # Public class: Mesh_Prism
978 # ------------------------
980 ## Class to define a Prism 3D algorithm
983 class Mesh_Prism3D(Mesh_Algorithm):
985 ## Private constructor.
986 def __init__(self, mesh, geom=0):
987 self.Create(mesh, geom, "Prism_3D")
989 # Public class: Mesh_RadialPrism
990 # -------------------------------
992 ## Class to define a Radial Prism 3D algorithm
995 class Mesh_RadialPrism3D(Mesh_Algorithm):
997 ## Private constructor.
998 def __init__(self, mesh, geom=0):
999 self.Create(mesh, geom, "RadialPrism_3D")
1000 self.distribHyp = self.Hypothesis( "LayerDistribution" )
1001 self.nbLayers = None
1003 ## Return 3D hypothesis holding the 1D one
1004 def Get3DHypothesis(self):
1005 return self.distribHyp
1007 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1008 # hypothes. Returns the created hypothes
1009 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1010 if not self.nbLayers is None:
1011 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1012 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1013 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
1014 hyp = smesh.CreateHypothesis(hypType, so)
1015 SetCurrentStudy( study ) # anable publishing
1016 self.distribHyp.SetLayerDistribution( hyp )
1019 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1020 # prisms to build between the inner and outer shells
1021 def NumberOfLayers(self, n ):
1022 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1023 self.nbLayers = self.Hypothesis("NumberOfLayers")
1024 self.nbLayers.SetNumberOfLayers( n )
1025 return self.nbLayers
1027 ## Define "LocalLength" hypothesis, specifying segment length
1028 # to build between the inner and outer shells
1029 # @param l for the length of segments
1030 def LocalLength(self, l):
1031 hyp = self.OwnHypothesis("LocalLength", [l])
1035 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1036 # prisms to build between the inner and outer shells
1037 # @param n for the number of segments
1038 # @param s for the scale factor (optional)
1039 def NumberOfSegments(self, n, s=[]):
1041 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1043 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1044 hyp.SetDistrType( 1 )
1045 hyp.SetScaleFactor(s)
1046 hyp.SetNumberOfSegments(n)
1049 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1050 # to build between the inner and outer shells as arithmetic length increasing
1051 # @param start for the length of the first segment
1052 # @param end for the length of the last segment
1053 def Arithmetic1D(self, start, end):
1054 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1055 hyp.SetLength(start, 1)
1056 hyp.SetLength(end , 0)
1059 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1060 # to build between the inner and outer shells as geometric length increasing
1061 # @param start for the length of the first segment
1062 # @param end for the length of the last segment
1063 def StartEndLength(self, start, end):
1064 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1065 hyp.SetLength(start, 1)
1066 hyp.SetLength(end , 0)
1069 ## Define "AutomaticLength" hypothesis, specifying number of segments
1070 # to build between the inner and outer shells
1071 # @param fineness for the fineness [0-1]
1072 def AutomaticLength(self, fineness=0):
1073 hyp = self.OwnHypothesis("AutomaticLength")
1074 hyp.SetFineness( fineness )
1078 # Public class: Mesh
1079 # ==================
1081 ## Class to define a mesh
1083 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1093 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1094 # sets GUI name of this mesh to \a name.
1095 # @param obj Shape to be meshed or SMESH_Mesh object
1096 # @param name Study name of the mesh
1097 def __init__(self, obj=0, name=0):
1101 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1103 self.mesh = smesh.CreateMesh(self.geom)
1104 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1107 self.mesh = smesh.CreateEmptyMesh()
1109 SetName(self.mesh, name)
1111 SetName(self.mesh, GetName(obj))
1113 self.editor = self.mesh.GetMeshEditor()
1115 ## Method that inits the Mesh object from SMESH_Mesh interface
1116 # @param theMesh is SMESH_Mesh object
1117 def SetMesh(self, theMesh):
1119 self.geom = self.mesh.GetShapeToMesh()
1121 ## Method that returns the mesh
1122 # @return SMESH_Mesh object
1128 name = GetName(self.GetMesh())
1132 def SetName(self, name):
1133 SetName(self.GetMesh(), name)
1135 ## Get the subMesh object associated to a subShape. The subMesh object
1136 # gives access to nodes and elements IDs.
1137 # \n SubMesh will be used instead of SubShape in a next idl version to
1138 # adress a specific subMesh...
1139 def GetSubMesh(self, theSubObject, name):
1140 submesh = self.mesh.GetSubMesh(theSubObject, name)
1143 ## Method that returns the shape associated to the mesh
1144 # @return GEOM_Object
1148 ## Method that associates given shape to the mesh(entails the mesh recreation)
1149 # @param geom shape to be meshed(GEOM_Object)
1150 def SetShape(self, geom):
1151 self.mesh = smesh.CreateMesh(geom)
1153 ## Return true if hypotheses are defined well
1154 # @param theMesh is an instance of Mesh class
1155 # @param theSubObject subshape of a mesh shape
1156 def IsReadyToCompute(self, theSubObject):
1157 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1159 ## Return errors of hypotheses definintion
1160 # error list is empty if everything is OK
1161 # @param theMesh is an instance of Mesh class
1162 # @param theSubObject subshape of a mesh shape
1163 # @return a list of errors
1164 def GetAlgoState(self, theSubObject):
1165 return smesh.GetAlgoState(self.mesh, theSubObject)
1167 ## Return geometrical object the given element is built on.
1168 # The returned geometrical object, if not nil, is either found in the
1169 # study or is published by this method with the given name
1170 # @param theMesh is an instance of Mesh class
1171 # @param theElementID an id of the mesh element
1172 # @param theGeomName user defined name of geometrical object
1173 # @return GEOM::GEOM_Object instance
1174 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1175 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1177 ## Returns mesh dimension depending on shape one
1178 def MeshDimension(self):
1179 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1180 if len( shells ) > 0 :
1182 elif geompy.NumberOfFaces( self.geom ) > 0 :
1184 elif geompy.NumberOfEdges( self.geom ) > 0 :
1190 ## Creates a segment discretization 1D algorithm.
1191 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1192 # If the optional \a geom parameter is not sets, this algorithm is global.
1193 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1194 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1195 # @param geom If defined, subshape to be meshed
1196 def Segment(self, algo=REGULAR, geom=0):
1197 ## if Segment(geom) is called by mistake
1198 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1199 algo, geom = geom, algo
1202 return Mesh_Segment(self, geom)
1203 elif algo == PYTHON:
1204 return Mesh_Segment_Python(self, geom)
1206 return Mesh_Segment(self, geom)
1208 ## Creates a triangle 2D algorithm for faces.
1209 # If the optional \a geom parameter is not sets, this algorithm is global.
1210 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1211 # @param algo values are: smesh.MEFISTO or smesh.NETGEN
1212 # @param geom If defined, subshape to be meshed
1213 def Triangle(self, algo=MEFISTO, geom=0):
1214 ## if Triangle(geom) is called by mistake
1215 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1219 return Mesh_Triangle(self, algo, geom)
1221 ## Creates a quadrangle 2D algorithm for faces.
1222 # If the optional \a geom parameter is not sets, this algorithm is global.
1223 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1224 # @param geom If defined, subshape to be meshed
1225 def Quadrangle(self, geom=0):
1226 return Mesh_Quadrangle(self, geom)
1228 ## Creates a tetrahedron 3D algorithm for solids.
1229 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1230 # If the optional \a geom parameter is not sets, this algorithm is global.
1231 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1232 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1233 # @param geom If defined, subshape to be meshed
1234 def Tetrahedron(self, algo=NETGEN, geom=0):
1235 ## if Tetrahedron(geom) is called by mistake
1236 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1237 algo, geom = geom, algo
1239 return Mesh_Tetrahedron(self, algo, geom)
1241 ## Creates a hexahedron 3D algorithm for solids.
1242 # If the optional \a geom parameter is not sets, this algorithm is global.
1243 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1244 # @param geom If defined, subshape to be meshed
1245 ## def Hexahedron(self, geom=0):
1246 ## return Mesh_Hexahedron(self, geom)
1247 def Hexahedron(self, algo=Hexa, geom=0):
1248 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1249 if ( isinstance(algo, geompy.GEOM._objref_GEOM_Object) ):
1250 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
1251 elif geom == 0: algo, geom = Hexa, algo
1252 return Mesh_Hexahedron(self, algo, geom)
1254 ## Deprecated, only for compatibility!
1255 def Netgen(self, is3D, geom=0):
1256 return Mesh_Netgen(self, is3D, geom)
1258 ## Creates a projection 1D algorithm for edges.
1259 # If the optional \a geom parameter is not sets, this algorithm is global.
1260 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1261 # @param geom If defined, subshape to be meshed
1262 def Projection1D(self, geom=0):
1263 return Mesh_Projection1D(self, geom)
1265 ## Creates a projection 2D algorithm for faces.
1266 # If the optional \a geom parameter is not sets, this algorithm is global.
1267 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1268 # @param geom If defined, subshape to be meshed
1269 def Projection2D(self, geom=0):
1270 return Mesh_Projection2D(self, geom)
1272 ## Creates a projection 3D algorithm for solids.
1273 # If the optional \a geom parameter is not sets, this algorithm is global.
1274 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1275 # @param geom If defined, subshape to be meshed
1276 def Projection3D(self, geom=0):
1277 return Mesh_Projection3D(self, geom)
1279 ## Creates a Prism 3D or RadialPrism 3D algorithm for solids.
1280 # If the optional \a geom parameter is not sets, this algorithm is global.
1281 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1282 # @param geom If defined, subshape to be meshed
1283 def Prism(self, geom=0):
1287 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1288 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1289 if nbSolids == 0 or nbSolids == nbShells:
1290 return Mesh_Prism3D(self, geom)
1291 return Mesh_RadialPrism3D(self, geom)
1293 ## Compute the mesh and return the status of the computation
1294 def Compute(self, geom=0):
1295 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1297 print "Compute impossible: mesh is not constructed on geom shape."
1301 ok = smesh.Compute(self.mesh, geom)
1303 errors = smesh.GetAlgoState( self.mesh, geom )
1306 if err.isGlobalAlgo:
1311 dim = str(err.algoDim)
1312 if err.name == MISSING_ALGO:
1313 reason = glob + dim + "D algorithm is missing"
1314 elif err.name == MISSING_HYPO:
1315 name = '"' + err.algoName + '"'
1316 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1317 elif err.name == NOT_CONFORM_MESH:
1318 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1319 elif err.name == BAD_PARAM_VALUE:
1320 name = '"' + err.algoName + '"'
1321 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1322 " has a bad parameter value"
1324 reason = "For unknown reason."+\
1325 " Revise Mesh.Compute() implementation in smesh.py!"
1327 if allReasons != "":
1330 allReasons += reason
1332 if allReasons != "":
1333 print '"' + GetName(self.mesh) + '"',"not computed:"
1337 if salome.sg.hasDesktop():
1338 smeshgui = salome.ImportComponentGUI("SMESH")
1339 smeshgui.Init(salome.myStudyId)
1340 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok )
1341 salome.sg.updateObjBrowser(1)
1345 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1346 # The parameter \a fineness [0,-1] defines mesh fineness
1347 def AutomaticTetrahedralization(self, fineness=0):
1348 dim = self.MeshDimension()
1350 self.RemoveGlobalHypotheses()
1351 self.Segment().AutomaticLength(fineness)
1353 self.Triangle().LengthFromEdges()
1356 self.Tetrahedron(NETGEN)
1358 return self.Compute()
1360 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1361 # The parameter \a fineness [0,-1] defines mesh fineness
1362 def AutomaticHexahedralization(self, fineness=0):
1363 dim = self.MeshDimension()
1365 self.RemoveGlobalHypotheses()
1366 self.Segment().AutomaticLength(fineness)
1373 return self.Compute()
1375 ## Get the list of hypothesis added on a geom
1376 # @param geom is subhape of mesh geometry
1377 def GetHypothesisList(self, geom):
1378 return self.mesh.GetHypothesisList( geom )
1380 ## Removes all global hypotheses
1381 def RemoveGlobalHypotheses(self):
1382 current_hyps = self.mesh.GetHypothesisList( self.geom )
1383 for hyp in current_hyps:
1384 self.mesh.RemoveHypothesis( self.geom, hyp )
1388 ## Create a mesh group based on geometric object \a grp
1389 # and give a \a name, \n if this parameter is not defined
1390 # the name is the same as the geometric group name \n
1391 # Note: Works like GroupOnGeom().
1392 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1393 # @param name is the name of the mesh group
1394 # @return SMESH_GroupOnGeom
1395 def Group(self, grp, name=""):
1396 return self.GroupOnGeom(grp, name)
1398 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1399 # Export the mesh in a file with the MED format and choice the \a version of MED format
1400 # @param f is the file name
1401 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1402 def ExportToMED(self, f, version, opt=0):
1403 self.mesh.ExportToMED(f, opt, version)
1405 ## Export the mesh in a file with the MED format
1406 # @param f is the file name
1407 # @param auto_groups boolean parameter for creating/not creating
1408 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1409 # the typical use is auto_groups=false.
1410 # @param version MED format version(MED_V2_1 or MED_V2_2)
1411 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1412 self.mesh.ExportToMED(f, auto_groups, version)
1414 ## Export the mesh in a file with the DAT format
1415 # @param f is the file name
1416 def ExportDAT(self, f):
1417 self.mesh.ExportDAT(f)
1419 ## Export the mesh in a file with the UNV format
1420 # @param f is the file name
1421 def ExportUNV(self, f):
1422 self.mesh.ExportUNV(f)
1424 ## Export the mesh in a file with the STL format
1425 # @param f is the file name
1426 # @param ascii defined the kind of file contents
1427 def ExportSTL(self, f, ascii=1):
1428 self.mesh.ExportSTL(f, ascii)
1431 # Operations with groups:
1432 # ----------------------
1434 ## Creates an empty mesh group
1435 # @param elementType is the type of elements in the group
1436 # @param name is the name of the mesh group
1437 # @return SMESH_Group
1438 def CreateEmptyGroup(self, elementType, name):
1439 return self.mesh.CreateGroup(elementType, name)
1441 ## Creates a mesh group based on geometric object \a grp
1442 # and give a \a name, \n if this parameter is not defined
1443 # the name is the same as the geometric group name
1444 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1445 # @param name is the name of the mesh group
1446 # @return SMESH_GroupOnGeom
1447 def GroupOnGeom(self, grp, name="", type=None):
1449 name = grp.GetName()
1452 tgeo = str(grp.GetShapeType())
1453 if tgeo == "VERTEX":
1455 elif tgeo == "EDGE":
1457 elif tgeo == "FACE":
1459 elif tgeo == "SOLID":
1461 elif tgeo == "SHELL":
1463 elif tgeo == "COMPOUND":
1464 if len( geompy.GetObjectIDs( grp )) == 0:
1465 print "Mesh.Group: empty geometric group", GetName( grp )
1467 tgeo = geompy.GetType(grp)
1468 if tgeo == geompy.ShapeType["VERTEX"]:
1470 elif tgeo == geompy.ShapeType["EDGE"]:
1472 elif tgeo == geompy.ShapeType["FACE"]:
1474 elif tgeo == geompy.ShapeType["SOLID"]:
1478 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1481 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1483 ## Create a mesh group by the given ids of elements
1484 # @param groupName is the name of the mesh group
1485 # @param elementType is the type of elements in the group
1486 # @param elemIDs is the list of ids
1487 # @return SMESH_Group
1488 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1489 group = self.mesh.CreateGroup(elementType, groupName)
1493 ## Create a mesh group by the given conditions
1494 # @param groupName is the name of the mesh group
1495 # @param elementType is the type of elements in the group
1496 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1497 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1498 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1499 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1500 # @return SMESH_Group
1504 CritType=FT_Undefined,
1507 UnaryOp=FT_Undefined):
1508 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1509 group = self.MakeGroupByCriterion(groupName, aCriterion)
1512 ## Create a mesh group by the given criterion
1513 # @param groupName is the name of the mesh group
1514 # @param Criterion is the instance of Criterion class
1515 # @return SMESH_Group
1516 def MakeGroupByCriterion(self, groupName, Criterion):
1517 aFilterMgr = smesh.CreateFilterManager()
1518 aFilter = aFilterMgr.CreateFilter()
1520 aCriteria.append(Criterion)
1521 aFilter.SetCriteria(aCriteria)
1522 group = self.MakeGroupByFilter(groupName, aFilter)
1525 ## Create a mesh group by the given criteria(list of criterions)
1526 # @param groupName is the name of the mesh group
1527 # @param Criteria is the list of criterions
1528 # @return SMESH_Group
1529 def MakeGroupByCriteria(self, groupName, theCriteria):
1530 aFilterMgr = smesh.CreateFilterManager()
1531 aFilter = aFilterMgr.CreateFilter()
1532 aFilter.SetCriteria(theCriteria)
1533 group = self.MakeGroupByFilter(groupName, aFilter)
1536 ## Create a mesh group by the given filter
1537 # @param groupName is the name of the mesh group
1538 # @param Criterion is the instance of Filter class
1539 # @return SMESH_Group
1540 def MakeGroupByFilter(self, groupName, theFilter):
1541 anIds = theFilter.GetElementsId(self.mesh)
1542 anElemType = theFilter.GetElementType()
1543 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1546 ## Pass mesh elements through the given filter and return ids
1547 # @param theFilter is SMESH_Filter
1548 # @return list of ids
1549 def GetIdsFromFilter(self, theFilter):
1550 return theFilter.GetElementsId(self.mesh)
1552 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1553 # Returns list of special structures(borders).
1554 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1555 def GetFreeBorders(self):
1556 aFilterMgr = smesh.CreateFilterManager()
1557 aPredicate = aFilterMgr.CreateFreeEdges()
1558 aPredicate.SetMesh(self.mesh)
1559 aBorders = aPredicate.GetBorders()
1563 def RemoveGroup(self, group):
1564 self.mesh.RemoveGroup(group)
1566 ## Remove group with its contents
1567 def RemoveGroupWithContents(self, group):
1568 self.mesh.RemoveGroupWithContents(group)
1570 ## Get the list of groups existing in the mesh
1571 def GetGroups(self):
1572 return self.mesh.GetGroups()
1574 ## Get the list of names of groups existing in the mesh
1575 def GetGroupNames(self):
1576 groups = self.GetGroups()
1578 for group in groups:
1579 names.append(group.GetName())
1582 ## Union of two groups
1583 # New group is created. All mesh elements that are
1584 # present in initial groups are added to the new one
1585 def UnionGroups(self, group1, group2, name):
1586 return self.mesh.UnionGroups(group1, group2, name)
1588 ## Intersection of two groups
1589 # New group is created. All mesh elements that are
1590 # present in both initial groups are added to the new one.
1591 def IntersectGroups(self, group1, group2, name):
1592 return self.mesh.IntersectGroups(group1, group2, name)
1594 ## Cut of two groups
1595 # New group is created. All mesh elements that are present in
1596 # main group but do not present in tool group are added to the new one
1597 def CutGroups(self, mainGroup, toolGroup, name):
1598 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1601 # Get some info about mesh:
1602 # ------------------------
1604 ## Get the log of nodes and elements added or removed since previous
1606 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1607 # @return list of log_block structures:
1612 def GetLog(self, clearAfterGet):
1613 return self.mesh.GetLog(clearAfterGet)
1615 ## Clear the log of nodes and elements added or removed since previous
1616 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1618 self.mesh.ClearLog()
1620 ## Get the internal Id
1622 return self.mesh.GetId()
1625 def GetStudyId(self):
1626 return self.mesh.GetStudyId()
1628 ## Check group names for duplications.
1629 # Consider maximum group name length stored in MED file.
1630 def HasDuplicatedGroupNamesMED(self):
1631 return self.mesh.GetStudyId()
1633 ## Obtain instance of SMESH_MeshEditor
1634 def GetMeshEditor(self):
1635 return self.mesh.GetMeshEditor()
1638 def GetMEDMesh(self):
1639 return self.mesh.GetMEDMesh()
1642 # Get informations about mesh contents:
1643 # ------------------------------------
1645 ## Returns number of nodes in mesh
1647 return self.mesh.NbNodes()
1649 ## Returns number of elements in mesh
1650 def NbElements(self):
1651 return self.mesh.NbElements()
1653 ## Returns number of edges in mesh
1655 return self.mesh.NbEdges()
1657 ## Returns number of edges with given order in mesh
1658 # @param elementOrder is order of elements:
1659 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1660 def NbEdgesOfOrder(self, elementOrder):
1661 return self.mesh.NbEdgesOfOrder(elementOrder)
1663 ## Returns number of faces in mesh
1665 return self.mesh.NbFaces()
1667 ## Returns number of faces with given order in mesh
1668 # @param elementOrder is order of elements:
1669 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1670 def NbFacesOfOrder(self, elementOrder):
1671 return self.mesh.NbFacesOfOrder(elementOrder)
1673 ## Returns number of triangles in mesh
1674 def NbTriangles(self):
1675 return self.mesh.NbTriangles()
1677 ## Returns number of triangles with given order in mesh
1678 # @param elementOrder is order of elements:
1679 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1680 def NbTrianglesOfOrder(self, elementOrder):
1681 return self.mesh.NbTrianglesOfOrder(elementOrder)
1683 ## Returns number of quadrangles in mesh
1684 def NbQuadrangles(self):
1685 return self.mesh.NbQuadrangles()
1687 ## Returns number of quadrangles with given order in mesh
1688 # @param elementOrder is order of elements:
1689 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1690 def NbQuadranglesOfOrder(self, elementOrder):
1691 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1693 ## Returns number of polygons in mesh
1694 def NbPolygons(self):
1695 return self.mesh.NbPolygons()
1697 ## Returns number of volumes in mesh
1698 def NbVolumes(self):
1699 return self.mesh.NbVolumes()
1701 ## Returns number of volumes with given order in mesh
1702 # @param elementOrder is order of elements:
1703 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1704 def NbVolumesOfOrder(self, elementOrder):
1705 return self.mesh.NbVolumesOfOrder(elementOrder)
1707 ## Returns number of tetrahedrons in mesh
1709 return self.mesh.NbTetras()
1711 ## Returns number of tetrahedrons with given order in mesh
1712 # @param elementOrder is order of elements:
1713 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1714 def NbTetrasOfOrder(self, elementOrder):
1715 return self.mesh.NbTetrasOfOrder(elementOrder)
1717 ## Returns number of hexahedrons in mesh
1719 return self.mesh.NbHexas()
1721 ## Returns number of hexahedrons with given order in mesh
1722 # @param elementOrder is order of elements:
1723 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1724 def NbHexasOfOrder(self, elementOrder):
1725 return self.mesh.NbHexasOfOrder(elementOrder)
1727 ## Returns number of pyramids in mesh
1728 def NbPyramids(self):
1729 return self.mesh.NbPyramids()
1731 ## Returns number of pyramids with given order in mesh
1732 # @param elementOrder is order of elements:
1733 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1734 def NbPyramidsOfOrder(self, elementOrder):
1735 return self.mesh.NbPyramidsOfOrder(elementOrder)
1737 ## Returns number of prisms in mesh
1739 return self.mesh.NbPrisms()
1741 ## Returns number of prisms with given order in mesh
1742 # @param elementOrder is order of elements:
1743 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1744 def NbPrismsOfOrder(self, elementOrder):
1745 return self.mesh.NbPrismsOfOrder(elementOrder)
1747 ## Returns number of polyhedrons in mesh
1748 def NbPolyhedrons(self):
1749 return self.mesh.NbPolyhedrons()
1751 ## Returns number of submeshes in mesh
1752 def NbSubMesh(self):
1753 return self.mesh.NbSubMesh()
1755 ## Returns list of mesh elements ids
1756 def GetElementsId(self):
1757 return self.mesh.GetElementsId()
1759 ## Returns list of ids of mesh elements with given type
1760 # @param elementType is required type of elements
1761 def GetElementsByType(self, elementType):
1762 return self.mesh.GetElementsByType(elementType)
1764 ## Returns list of mesh nodes ids
1765 def GetNodesId(self):
1766 return self.mesh.GetNodesId()
1768 # Get informations about mesh elements:
1769 # ------------------------------------
1771 ## Returns type of mesh element
1772 def GetElementType(self, id, iselem):
1773 return self.mesh.GetElementType(id, iselem)
1775 ## Returns list of submesh elements ids
1776 # @param shapeID is geom object(subshape) IOR
1777 def GetSubMeshElementsId(self, shapeID):
1778 return self.mesh.GetSubMeshElementsId(shapeID)
1780 ## Returns list of submesh nodes ids
1781 # @param shapeID is geom object(subshape) IOR
1782 def GetSubMeshNodesId(self, shapeID, all):
1783 return self.mesh.GetSubMeshNodesId(shapeID, all)
1785 ## Returns list of ids of submesh elements with given type
1786 # @param shapeID is geom object(subshape) IOR
1787 def GetSubMeshElementType(self, shapeID):
1788 return self.mesh.GetSubMeshElementType(shapeID)
1790 ## Get mesh description
1792 return self.mesh.Dump()
1795 # Get information about nodes and elements of mesh by its ids:
1796 # -----------------------------------------------------------
1798 ## Get XYZ coordinates of node as list of double
1799 # \n If there is not node for given ID - returns empty list
1800 def GetNodeXYZ(self, id):
1801 return self.mesh.GetNodeXYZ(id)
1803 ## For given node returns list of IDs of inverse elements
1804 # \n If there is not node for given ID - returns empty list
1805 def GetNodeInverseElements(self, id):
1806 return self.mesh.GetNodeInverseElements(id)
1808 ## If given element is node returns IDs of shape from position
1809 # \n If there is not node for given ID - returns -1
1810 def GetShapeID(self, id):
1811 return self.mesh.GetShapeID(id)
1813 ## For given element returns ID of result shape after
1814 # FindShape() from SMESH_MeshEditor
1815 # \n If there is not element for given ID - returns -1
1816 def GetShapeIDForElem(id):
1817 return self.mesh.GetShapeIDForElem(id)
1819 ## Returns number of nodes for given element
1820 # \n If there is not element for given ID - returns -1
1821 def GetElemNbNodes(self, id):
1822 return self.mesh.GetElemNbNodes(id)
1824 ## Returns ID of node by given index for given element
1825 # \n If there is not element for given ID - returns -1
1826 # \n If there is not node for given index - returns -2
1827 def GetElemNode(self, id, index):
1828 return self.mesh.GetElemNode(id, index)
1830 ## Returns true if given node is medium node
1831 # in given quadratic element
1832 def IsMediumNode(self, elementID, nodeID):
1833 return self.mesh.IsMediumNode(elementID, nodeID)
1835 ## Returns true if given node is medium node
1836 # in one of quadratic elements
1837 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1838 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1840 ## Returns number of edges for given element
1841 def ElemNbEdges(self, id):
1842 return self.mesh.ElemNbEdges(id)
1844 ## Returns number of faces for given element
1845 def ElemNbFaces(self, id):
1846 return self.mesh.ElemNbFaces(id)
1848 ## Returns true if given element is polygon
1849 def IsPoly(self, id):
1850 return self.mesh.IsPoly(id)
1852 ## Returns true if given element is quadratic
1853 def IsQuadratic(self, id):
1854 return self.mesh.IsQuadratic(id)
1856 ## Returns XYZ coordinates of bary center for given element
1858 # \n If there is not element for given ID - returns empty list
1859 def BaryCenter(self, id):
1860 return self.mesh.BaryCenter(id)
1863 # Mesh edition (SMESH_MeshEditor functionality):
1864 # ---------------------------------------------
1866 ## Removes elements from mesh by ids
1867 # @param IDsOfElements is list of ids of elements to remove
1868 def RemoveElements(self, IDsOfElements):
1869 return self.editor.RemoveElements(IDsOfElements)
1871 ## Removes nodes from mesh by ids
1872 # @param IDsOfNodes is list of ids of nodes to remove
1873 def RemoveNodes(self, IDsOfNodes):
1874 return self.editor.RemoveNodes(IDsOfNodes)
1876 ## Add node to mesh by coordinates
1877 def AddNode(self, x, y, z):
1878 return self.editor.AddNode( x, y, z)
1881 ## Create edge both similar and quadratic (this is determed
1882 # by number of given nodes).
1883 # @param IdsOfNodes List of node IDs for creation of element.
1884 # Needed order of nodes in this list corresponds to description
1885 # of MED. \n This description is located by the following link:
1886 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1887 def AddEdge(self, IDsOfNodes):
1888 return self.editor.AddEdge(IDsOfNodes)
1890 ## Create face both similar and quadratic (this is determed
1891 # by number of given nodes).
1892 # @param IdsOfNodes List of node IDs for creation of element.
1893 # Needed order of nodes in this list corresponds to description
1894 # of MED. \n This description is located by the following link:
1895 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1896 def AddFace(self, IDsOfNodes):
1897 return self.editor.AddFace(IDsOfNodes)
1899 ## Add polygonal face to mesh by list of nodes ids
1900 def AddPolygonalFace(self, IdsOfNodes):
1901 return self.editor.AddPolygonalFace(IdsOfNodes)
1903 ## Create volume both similar and quadratic (this is determed
1904 # by number of given nodes).
1905 # @param IdsOfNodes List of node IDs for creation of element.
1906 # Needed order of nodes in this list corresponds to description
1907 # of MED. \n This description is located by the following link:
1908 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1909 def AddVolume(self, IDsOfNodes):
1910 return self.editor.AddVolume(IDsOfNodes)
1912 ## Create volume of many faces, giving nodes for each face.
1913 # @param IdsOfNodes List of node IDs for volume creation face by face.
1914 # @param Quantities List of integer values, Quantities[i]
1915 # gives quantity of nodes in face number i.
1916 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1917 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1919 ## Create volume of many faces, giving IDs of existing faces.
1920 # @param IdsOfFaces List of face IDs for volume creation.
1922 # Note: The created volume will refer only to nodes
1923 # of the given faces, not to the faces itself.
1924 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1925 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1927 ## Move node with given id
1928 # @param NodeID id of the node
1929 # @param x displacing along the X axis
1930 # @param y displacing along the Y axis
1931 # @param z displacing along the Z axis
1932 def MoveNode(self, NodeID, x, y, z):
1933 return self.editor.MoveNode(NodeID, x, y, z)
1935 ## Replace two neighbour triangles sharing Node1-Node2 link
1936 # with ones built on the same 4 nodes but having other common link.
1937 # @param NodeID1 first node id
1938 # @param NodeID2 second node id
1939 # @return false if proper faces not found
1940 def InverseDiag(self, NodeID1, NodeID2):
1941 return self.editor.InverseDiag(NodeID1, NodeID2)
1943 ## Replace two neighbour triangles sharing Node1-Node2 link
1944 # with a quadrangle built on the same 4 nodes.
1945 # @param NodeID1 first node id
1946 # @param NodeID2 second node id
1947 # @return false if proper faces not found
1948 def DeleteDiag(self, NodeID1, NodeID2):
1949 return self.editor.DeleteDiag(NodeID1, NodeID2)
1951 ## Reorient elements by ids
1952 # @param IDsOfElements if undefined reorient all mesh elements
1953 def Reorient(self, IDsOfElements=None):
1954 if IDsOfElements == None:
1955 IDsOfElements = self.GetElementsId()
1956 return self.editor.Reorient(IDsOfElements)
1958 ## Reorient all elements of the object
1959 # @param theObject is mesh, submesh or group
1960 def ReorientObject(self, theObject):
1961 return self.editor.ReorientObject(theObject)
1963 ## Fuse neighbour triangles into quadrangles.
1964 # @param IDsOfElements The triangles to be fused,
1965 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1966 # @param MaxAngle is a max angle between element normals at which fusion
1967 # is still performed; theMaxAngle is mesured in radians.
1968 # @return TRUE in case of success, FALSE otherwise.
1969 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1970 if IDsOfElements == []:
1971 IDsOfElements = self.GetElementsId()
1972 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1974 ## Fuse neighbour triangles of the object into quadrangles
1975 # @param theObject is mesh, submesh or group
1976 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1977 # @param MaxAngle is a max angle between element normals at which fusion
1978 # is still performed; theMaxAngle is mesured in radians.
1979 # @return TRUE in case of success, FALSE otherwise.
1980 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1981 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1983 ## Split quadrangles into triangles.
1984 # @param IDsOfElements the faces to be splitted.
1985 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1986 # @param @return TRUE in case of success, FALSE otherwise.
1987 def QuadToTri (self, IDsOfElements, theCriterion):
1988 if IDsOfElements == []:
1989 IDsOfElements = self.GetElementsId()
1990 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
1992 ## Split quadrangles into triangles.
1993 # @param theObject object to taking list of elements from, is mesh, submesh or group
1994 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1995 def QuadToTriObject (self, theObject, theCriterion):
1996 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
1998 ## Split quadrangles into triangles.
1999 # @param theElems The faces to be splitted
2000 # @param the13Diag is used to choose a diagonal for splitting.
2001 # @return TRUE in case of success, FALSE otherwise.
2002 def SplitQuad (self, IDsOfElements, Diag13):
2003 if IDsOfElements == []:
2004 IDsOfElements = self.GetElementsId()
2005 return self.editor.SplitQuad(IDsOfElements, Diag13)
2007 ## Split quadrangles into triangles.
2008 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2009 def SplitQuadObject (self, theObject, Diag13):
2010 return self.editor.SplitQuadObject(theObject, Diag13)
2012 ## Find better splitting of the given quadrangle.
2013 # @param IDOfQuad ID of the quadrangle to be splitted.
2014 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2015 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2016 # diagonal is better, 0 if error occurs.
2017 def BestSplit (self, IDOfQuad, theCriterion):
2018 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2021 # @param IDsOfElements list if ids of elements to smooth
2022 # @param IDsOfFixedNodes list of ids of fixed nodes.
2023 # Note that nodes built on edges and boundary nodes are always fixed.
2024 # @param MaxNbOfIterations maximum number of iterations
2025 # @param MaxAspectRatio varies in range [1.0, inf]
2026 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2027 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2028 MaxNbOfIterations, MaxAspectRatio, Method):
2029 if IDsOfElements == []:
2030 IDsOfElements = self.GetElementsId()
2031 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2032 MaxNbOfIterations, MaxAspectRatio, Method)
2034 ## Smooth elements belong to given object
2035 # @param theObject object to smooth
2036 # @param IDsOfFixedNodes list of ids of fixed nodes.
2037 # Note that nodes built on edges and boundary nodes are always fixed.
2038 # @param MaxNbOfIterations maximum number of iterations
2039 # @param MaxAspectRatio varies in range [1.0, inf]
2040 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2041 def SmoothObject(self, theObject, IDsOfFixedNodes,
2042 MaxNbOfIterations, MaxxAspectRatio, Method):
2043 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2044 MaxNbOfIterations, MaxxAspectRatio, Method)
2046 ## Parametric smooth the given elements
2047 # @param IDsOfElements list if ids of elements to smooth
2048 # @param IDsOfFixedNodes list of ids of fixed nodes.
2049 # Note that nodes built on edges and boundary nodes are always fixed.
2050 # @param MaxNbOfIterations maximum number of iterations
2051 # @param MaxAspectRatio varies in range [1.0, inf]
2052 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2053 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2054 MaxNbOfIterations, MaxAspectRatio, Method):
2055 if IDsOfElements == []:
2056 IDsOfElements = self.GetElementsId()
2057 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2058 MaxNbOfIterations, MaxAspectRatio, Method)
2060 ## Parametric smooth elements belong to given object
2061 # @param theObject object to smooth
2062 # @param IDsOfFixedNodes list of ids of fixed nodes.
2063 # Note that nodes built on edges and boundary nodes are always fixed.
2064 # @param MaxNbOfIterations maximum number of iterations
2065 # @param MaxAspectRatio varies in range [1.0, inf]
2066 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2067 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2068 MaxNbOfIterations, MaxAspectRatio, Method):
2069 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2070 MaxNbOfIterations, MaxAspectRatio, Method)
2072 ## Converts all mesh to quadratic one, deletes old elements, replacing
2073 # them with quadratic ones with the same id.
2074 def ConvertToQuadratic(self, theForce3d):
2075 self.editor.ConvertToQuadratic(theForce3d)
2077 ## Converts all mesh from quadratic to ordinary ones,
2078 # deletes old quadratic elements, \n replacing
2079 # them with ordinary mesh elements with the same id.
2080 def ConvertFromQuadratic(self):
2081 return self.editor.ConvertFromQuadratic()
2083 ## Renumber mesh nodes
2084 def RenumberNodes(self):
2085 self.editor.RenumberNodes()
2087 ## Renumber mesh elements
2088 def RenumberElements(self):
2089 self.editor.RenumberElements()
2091 ## Generate new elements by rotation of the elements around the axis
2092 # @param IDsOfElements list of ids of elements to sweep
2093 # @param Axix axis of rotation, AxisStruct or line(geom object)
2094 # @param AngleInRadians angle of Rotation
2095 # @param NbOfSteps number of steps
2096 # @param Tolerance tolerance
2097 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2098 if IDsOfElements == []:
2099 IDsOfElements = self.GetElementsId()
2100 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2101 Axix = GetAxisStruct(Axix)
2102 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2104 ## Generate new elements by rotation of the elements of object around the axis
2105 # @param theObject object wich elements should be sweeped
2106 # @param Axix axis of rotation, AxisStruct or line(geom object)
2107 # @param AngleInRadians angle of Rotation
2108 # @param NbOfSteps number of steps
2109 # @param Tolerance tolerance
2110 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2111 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2112 Axix = GetAxisStruct(Axix)
2113 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2115 ## Generate new elements by extrusion of the elements with given ids
2116 # @param IDsOfElements list of elements ids for extrusion
2117 # @param StepVector vector, defining the direction and value of extrusion
2118 # @param NbOfSteps the number of steps
2119 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2120 if IDsOfElements == []:
2121 IDsOfElements = self.GetElementsId()
2122 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2123 StepVector = GetDirStruct(StepVector)
2124 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2126 ## Generate new elements by extrusion of the elements with given ids
2127 # @param IDsOfElements is ids of elements
2128 # @param StepVector vector, defining the direction and value of extrusion
2129 # @param NbOfSteps the number of steps
2130 # @param ExtrFlags set flags for performing extrusion
2131 # @param SewTolerance uses for comparing locations of nodes if flag
2132 # EXTRUSION_FLAG_SEW is set
2133 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2134 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2135 StepVector = GetDirStruct(StepVector)
2136 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2138 ## Generate new elements by extrusion of the elements belong to object
2139 # @param theObject object wich elements should be processed
2140 # @param StepVector vector, defining the direction and value of extrusion
2141 # @param NbOfSteps the number of steps
2142 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2143 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2144 StepVector = GetDirStruct(StepVector)
2145 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2147 ## Generate new elements by extrusion of the elements belong to object
2148 # @param theObject object wich elements should be processed
2149 # @param StepVector vector, defining the direction and value of extrusion
2150 # @param NbOfSteps the number of steps
2151 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2152 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2153 StepVector = GetDirStruct(StepVector)
2154 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2156 ## Generate new elements by extrusion of the elements belong to object
2157 # @param theObject object wich elements should be processed
2158 # @param StepVector vector, defining the direction and value of extrusion
2159 # @param NbOfSteps the number of steps
2160 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2161 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2162 StepVector = GetDirStruct(StepVector)
2163 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2165 ## Generate new elements by extrusion of the given elements
2166 # A path of extrusion must be a meshed edge.
2167 # @param IDsOfElements is ids of elements
2168 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2169 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2170 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2171 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2172 # @param Angles list of angles
2173 # @param HasRefPoint allows to use base point
2174 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2175 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2176 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2177 HasAngles, Angles, HasRefPoint, RefPoint):
2178 if IDsOfElements == []:
2179 IDsOfElements = self.GetElementsId()
2180 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2181 RefPoint = GetPointStruct(RefPoint)
2182 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2183 HasAngles, Angles, HasRefPoint, RefPoint)
2185 ## Generate new elements by extrusion of the elements belong to object
2186 # A path of extrusion must be a meshed edge.
2187 # @param IDsOfElements is ids of elements
2188 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2189 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2190 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2191 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2192 # @param Angles list of angles
2193 # @param HasRefPoint allows to use base point
2194 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2195 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2196 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2197 HasAngles, Angles, HasRefPoint, RefPoint):
2198 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2199 RefPoint = GetPointStruct(RefPoint)
2200 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2201 HasAngles, Angles, HasRefPoint, RefPoint)
2203 ## Symmetrical copy of mesh elements
2204 # @param IDsOfElements list of elements ids
2205 # @param Mirror is AxisStruct or geom object(point, line, plane)
2206 # @param theMirrorType is POINT, AXIS or PLANE
2207 # If the Mirror is geom object this parameter is unnecessary
2208 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2209 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2210 if IDsOfElements == []:
2211 IDsOfElements = self.GetElementsId()
2212 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2213 Mirror = GetAxisStruct(Mirror)
2214 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2216 ## Symmetrical copy of object
2217 # @param theObject mesh, submesh or group
2218 # @param Mirror is AxisStruct or geom object(point, line, plane)
2219 # @param theMirrorType is POINT, AXIS or PLANE
2220 # If the Mirror is geom object this parameter is unnecessary
2221 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2222 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2223 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2224 Mirror = GetAxisStruct(Mirror)
2225 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2227 ## Translates the elements
2228 # @param IDsOfElements list of elements ids
2229 # @param Vector direction of translation(DirStruct or vector)
2230 # @param Copy allows to copy the translated elements
2231 def Translate(self, IDsOfElements, Vector, Copy):
2232 if IDsOfElements == []:
2233 IDsOfElements = self.GetElementsId()
2234 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2235 Vector = GetDirStruct(Vector)
2236 self.editor.Translate(IDsOfElements, Vector, Copy)
2238 ## Translates the object
2239 # @param theObject object to translate(mesh, submesh, or group)
2240 # @param Vector direction of translation(DirStruct or geom vector)
2241 # @param Copy allows to copy the translated elements
2242 def TranslateObject(self, theObject, Vector, Copy):
2243 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2244 Vector = GetDirStruct(Vector)
2245 self.editor.TranslateObject(theObject, Vector, Copy)
2247 ## Rotates the elements
2248 # @param IDsOfElements list of elements ids
2249 # @param Axis axis of rotation(AxisStruct or geom line)
2250 # @param AngleInRadians angle of rotation(in radians)
2251 # @param Copy allows to copy the rotated elements
2252 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2253 if IDsOfElements == []:
2254 IDsOfElements = self.GetElementsId()
2255 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2256 Axis = GetAxisStruct(Axis)
2257 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2259 ## Rotates the object
2260 # @param theObject object to rotate(mesh, submesh, or group)
2261 # @param Axis axis of rotation(AxisStruct or geom line)
2262 # @param AngleInRadians angle of rotation(in radians)
2263 # @param Copy allows to copy the rotated elements
2264 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2265 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2267 ## Find group of nodes close to each other within Tolerance.
2268 # @param Tolerance tolerance value
2269 # @param list of group of nodes
2270 def FindCoincidentNodes (self, Tolerance):
2271 return self.editor.FindCoincidentNodes(Tolerance)
2274 # @param list of group of nodes
2275 def MergeNodes (self, GroupsOfNodes):
2276 self.editor.MergeNodes(GroupsOfNodes)
2278 ## Remove all but one of elements built on the same nodes.
2279 def MergeEqualElements(self):
2280 self.editor.MergeEqualElements()
2283 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2284 FirstNodeID2, SecondNodeID2, LastNodeID2,
2285 CreatePolygons, CreatePolyedrs):
2286 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2287 FirstNodeID2, SecondNodeID2, LastNodeID2,
2288 CreatePolygons, CreatePolyedrs)
2290 ## Sew conform free borders
2291 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2292 FirstNodeID2, SecondNodeID2):
2293 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2294 FirstNodeID2, SecondNodeID2)
2296 ## Sew border to side
2297 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2298 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2299 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2300 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2302 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2303 # merged with nodes of elements of Side2.
2304 # Number of elements in theSide1 and in theSide2 must be
2305 # equal and they should have similar node connectivity.
2306 # The nodes to merge should belong to sides borders and
2307 # the first node should be linked to the second.
2308 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2309 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2310 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2311 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2312 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2313 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2315 ## Set new nodes for given element.
2316 # @param ide the element id
2317 # @param newIDs nodes ids
2318 # @return If number of nodes is not corresponded to type of element - returns false
2319 def ChangeElemNodes(self, ide, newIDs):
2320 return self.editor.ChangeElemNodes(ide, newIDs)
2322 ## If during last operation of MeshEditor some nodes were
2323 # created this method returns list of it's IDs, \n
2324 # if new nodes not created - returns empty list
2325 def GetLastCreatedNodes(self):
2326 return self.editor.GetLastCreatedNodes()
2328 ## If during last operation of MeshEditor some elements were
2329 # created this method returns list of it's IDs, \n
2330 # if new elements not creared - returns empty list
2331 def GetLastCreatedElems(self):
2332 return self.editor.GetLastCreatedElems()