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 if algoType == MEFISTO:
580 self.Create(mesh, geom, "MEFISTO_2D")
581 elif algoType == BLSURF:
583 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
584 elif algoType == NETGEN:
586 print "Warning: NETGENPlugin module has not been imported."
587 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
588 self.algoType = algoType
590 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
591 # @param area for the maximum area of each triangles
592 def MaxElementArea(self, area):
593 if self.algoType == MEFISTO:
594 hyp = self.Hypothesis("MaxElementArea", [area])
595 hyp.SetMaxElementArea(area)
597 elif self.algoType == NETGEN:
598 print "Netgen 1D-2D algo doesn't support this hypothesis"
601 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
602 def LengthFromEdges(self):
603 if self.algoType == MEFISTO:
604 hyp = self.Hypothesis("LengthFromEdges")
606 elif self.algoType == NETGEN:
607 print "Netgen 1D-2D algo doesn't support this hypothesis"
610 ## Define "Netgen 2D Parameters" hypothesis
611 def Parameters(self):
612 if self.algoType == NETGEN:
613 self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
615 elif self.algoType == MEFISTO:
616 print "Mefisto algo doesn't support this hypothesis"
618 elif self.algoType == BLSURF:
619 self.params = self.Hypothesis("BLSURF_Parameters", [], "libBLSURFEngine.so")
623 def SetMaxSize(self, theSize):
626 self.params.SetMaxSize(theSize)
628 ## Set SecondOrder flag
629 def SetSecondOrder(seld, theVal):
632 self.params.SetSecondOrder(theVal)
635 def SetOptimize(self, theVal):
638 self.params.SetOptimize(theVal)
641 # @param theFineness is:
642 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
643 def SetFineness(self, theFineness):
646 self.params.SetFineness(theFineness)
649 def SetGrowthRate(self, theRate):
652 self.params.SetGrowthRate(theRate)
655 def SetNbSegPerEdge(self, theVal):
658 self.params.SetNbSegPerEdge(theVal)
660 ## Set NbSegPerRadius
661 def SetNbSegPerRadius(self, theVal):
664 self.params.SetNbSegPerRadius(theVal)
667 # @param thePhysicalMesh is:
668 # DefaultSize or Custom
669 def SetPhysicalMesh(self, thePhysicalMesh=1):
672 self.params.SetPhysicalMesh(thePhysicalMesh)
675 def SetPhySize(self, theVal):
678 self.params.SetPhySize(theVal)
681 # @param theGeometricMesh is:
682 # DefaultGeom or Custom
683 def SetGeometricMesh(self, theGeometricMesh=0):
686 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
687 self.params.SetGeometricMesh(theGeometricMesh)
689 ## Set AngleMeshS flag
690 def SetAngleMeshS(self, theVal=_angleMeshS):
693 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
694 self.params.SetAngleMeshS(theVal)
696 ## Set Gradation flag
697 def SetGradation(self, theVal=_gradation):
700 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
701 self.params.SetGradation(theVal)
703 ## Set QuadAllowed flag
704 def SetQuadAllowed(self, toAllow=False):
707 self.params.SetQuadAllowed(toAllow)
710 def SetDecimesh(self, toAllow=False):
713 self.params.SetDecimesh(toAllow)
715 # Public class: Mesh_Quadrangle
716 # -----------------------------
718 ## Class to define a quadrangle 2D algorithm
721 class Mesh_Quadrangle(Mesh_Algorithm):
723 ## Private constructor.
724 def __init__(self, mesh, geom=0):
725 self.Create(mesh, geom, "Quadrangle_2D")
727 ## Define "QuadranglePreference" hypothesis, forcing construction
728 # of quadrangles if the number of nodes on opposite edges is not the same
729 # in the case where the global number of nodes on edges is even
730 def QuadranglePreference(self):
731 hyp = self.Hypothesis("QuadranglePreference")
734 # Public class: Mesh_Tetrahedron
735 # ------------------------------
737 ## Class to define a tetrahedron 3D algorithm
740 class Mesh_Tetrahedron(Mesh_Algorithm):
745 ## Private constructor.
746 def __init__(self, mesh, algoType, geom=0):
747 if algoType == NETGEN:
748 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
749 elif algoType == GHS3D:
751 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
752 elif algoType == FULL_NETGEN:
754 print "Warning: NETGENPlugin module has not been imported."
755 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
756 self.algoType = algoType
758 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
759 # @param vol for the maximum volume of each tetrahedral
760 def MaxElementVolume(self, vol):
761 hyp = self.Hypothesis("MaxElementVolume", [vol])
762 hyp.SetMaxElementVolume(vol)
765 ## Define "Netgen 3D Parameters" hypothesis
766 def Parameters(self):
767 if (self.algoType == FULL_NETGEN):
768 self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
771 print "Algo doesn't support this hypothesis"
775 def SetMaxSize(self, theSize):
778 self.params.SetMaxSize(theSize)
780 ## Set SecondOrder flag
781 def SetSecondOrder(self, theVal):
784 self.params.SetSecondOrder(theVal)
787 def SetOptimize(self, theVal):
790 self.params.SetOptimize(theVal)
793 # @param theFineness is:
794 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
795 def SetFineness(self, theFineness):
798 self.params.SetFineness(theFineness)
801 def SetGrowthRate(self, theRate):
804 self.params.SetGrowthRate(theRate)
807 def SetNbSegPerEdge(self, theVal):
810 self.params.SetNbSegPerEdge(theVal)
812 ## Set NbSegPerRadius
813 def SetNbSegPerRadius(self, theVal):
816 self.params.SetNbSegPerRadius(theVal)
818 # Public class: Mesh_Hexahedron
819 # ------------------------------
821 ## Class to define a hexahedron 3D algorithm
824 class Mesh_Hexahedron(Mesh_Algorithm):
826 ## Private constructor.
827 ## def __init__(self, mesh, geom=0):
828 ## self.Create(mesh, geom, "Hexa_3D")
829 def __init__(self, mesh, algo, geom):
831 self.Create(mesh, geom, "Hexa_3D")
832 elif algo == Hexotic:
834 self.Create(mesh, geom, "Hexotic_3D" , "libHexoticEngine.so")
836 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
837 def MinMaxQuad(self, min=3, max=8, quad=True):
838 hyp = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so")
839 hyp.SetHexesMinLevel(min)
840 hyp.SetHexesMaxLevel(max)
841 hyp.SetHexoticQuadrangles(quad)
844 # Deprecated, only for compatibility!
845 # Public class: Mesh_Netgen
846 # ------------------------------
848 ## Class to define a NETGEN-based 2D or 3D algorithm
849 # that need no discrete boundary (i.e. independent)
851 # This class is deprecated, only for compatibility!
854 class Mesh_Netgen(Mesh_Algorithm):
858 ## Private constructor.
859 def __init__(self, mesh, is3D, geom=0):
861 print "Warning: NETGENPlugin module has not been imported."
865 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
867 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
869 ## Define hypothesis containing parameters of the algorithm
870 def Parameters(self):
872 hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
874 hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
877 # Public class: Mesh_Projection1D
878 # ------------------------------
880 ## Class to define a projection 1D algorithm
883 class Mesh_Projection1D(Mesh_Algorithm):
885 ## Private constructor.
886 def __init__(self, mesh, geom=0):
887 self.Create(mesh, geom, "Projection_1D")
889 ## Define "Source Edge" hypothesis, specifying a meshed edge to
890 # take a mesh pattern from, and optionally association of vertices
891 # between the source edge and a target one (where a hipothesis is assigned to)
892 # @param edge to take nodes distribution from
893 # @param mesh to take nodes distribution from (optional)
894 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
895 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
896 # to associate with \a srcV (optional)
897 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
898 hyp = self.Hypothesis("ProjectionSource1D")
899 hyp.SetSourceEdge( edge )
900 if not mesh is None and isinstance(mesh, Mesh):
901 mesh = mesh.GetMesh()
902 hyp.SetSourceMesh( mesh )
903 hyp.SetVertexAssociation( srcV, tgtV )
907 # Public class: Mesh_Projection2D
908 # ------------------------------
910 ## Class to define a projection 2D algorithm
913 class Mesh_Projection2D(Mesh_Algorithm):
915 ## Private constructor.
916 def __init__(self, mesh, geom=0):
917 self.Create(mesh, geom, "Projection_2D")
919 ## Define "Source Face" hypothesis, specifying a meshed face to
920 # take a mesh pattern from, and optionally association of vertices
921 # between the source face and a target one (where a hipothesis is assigned to)
922 # @param face to take mesh pattern from
923 # @param mesh to take mesh pattern from (optional)
924 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
925 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
926 # to associate with \a srcV1 (optional)
927 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
928 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
929 # to associate with \a srcV2 (optional)
931 # Note: association vertices must belong to one edge of a face
932 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
933 hyp = self.Hypothesis("ProjectionSource2D")
934 hyp.SetSourceFace( face )
935 if not mesh is None and isinstance(mesh, Mesh):
936 mesh = mesh.GetMesh()
937 hyp.SetSourceMesh( mesh )
938 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
941 # Public class: Mesh_Projection3D
942 # ------------------------------
944 ## Class to define a projection 3D algorithm
947 class Mesh_Projection3D(Mesh_Algorithm):
949 ## Private constructor.
950 def __init__(self, mesh, geom=0):
951 self.Create(mesh, geom, "Projection_3D")
953 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
954 # take a mesh pattern from, and optionally association of vertices
955 # between the source solid and a target one (where a hipothesis is assigned to)
956 # @param solid to take mesh pattern from
957 # @param mesh to take mesh pattern from (optional)
958 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
959 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
960 # to associate with \a srcV1 (optional)
961 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
962 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
963 # to associate with \a srcV2 (optional)
965 # Note: association vertices must belong to one edge of a solid
966 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
967 hyp = self.Hypothesis("ProjectionSource3D")
968 hyp.SetSource3DShape( solid )
969 if not mesh is None and isinstance(mesh, Mesh):
970 mesh = mesh.GetMesh()
971 hyp.SetSourceMesh( mesh )
972 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
976 # Public class: Mesh_Prism
977 # ------------------------
979 ## Class to define a Prism 3D algorithm
982 class Mesh_Prism3D(Mesh_Algorithm):
984 ## Private constructor.
985 def __init__(self, mesh, geom=0):
986 self.Create(mesh, geom, "Prism_3D")
988 # Public class: Mesh_RadialPrism
989 # -------------------------------
991 ## Class to define a Radial Prism 3D algorithm
994 class Mesh_RadialPrism3D(Mesh_Algorithm):
996 ## Private constructor.
997 def __init__(self, mesh, geom=0):
998 self.Create(mesh, geom, "RadialPrism_3D")
999 self.distribHyp = self.Hypothesis( "LayerDistribution" )
1000 self.nbLayers = None
1002 ## Return 3D hypothesis holding the 1D one
1003 def Get3DHypothesis(self):
1004 return self.distribHyp
1006 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1007 # hypothes. Returns the created hypothes
1008 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1009 if not self.nbLayers is None:
1010 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1011 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1012 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
1013 hyp = smesh.CreateHypothesis(hypType, so)
1014 SetCurrentStudy( study ) # anable publishing
1015 self.distribHyp.SetLayerDistribution( hyp )
1018 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1019 # prisms to build between the inner and outer shells
1020 def NumberOfLayers(self, n ):
1021 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1022 self.nbLayers = self.Hypothesis("NumberOfLayers")
1023 self.nbLayers.SetNumberOfLayers( n )
1024 return self.nbLayers
1026 ## Define "LocalLength" hypothesis, specifying segment length
1027 # to build between the inner and outer shells
1028 # @param l for the length of segments
1029 def LocalLength(self, l):
1030 hyp = self.OwnHypothesis("LocalLength", [l])
1034 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1035 # prisms to build between the inner and outer shells
1036 # @param n for the number of segments
1037 # @param s for the scale factor (optional)
1038 def NumberOfSegments(self, n, s=[]):
1040 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1042 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1043 hyp.SetDistrType( 1 )
1044 hyp.SetScaleFactor(s)
1045 hyp.SetNumberOfSegments(n)
1048 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1049 # to build between the inner and outer shells as arithmetic length increasing
1050 # @param start for the length of the first segment
1051 # @param end for the length of the last segment
1052 def Arithmetic1D(self, start, end):
1053 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1054 hyp.SetLength(start, 1)
1055 hyp.SetLength(end , 0)
1058 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1059 # to build between the inner and outer shells as geometric length increasing
1060 # @param start for the length of the first segment
1061 # @param end for the length of the last segment
1062 def StartEndLength(self, start, end):
1063 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1064 hyp.SetLength(start, 1)
1065 hyp.SetLength(end , 0)
1068 ## Define "AutomaticLength" hypothesis, specifying number of segments
1069 # to build between the inner and outer shells
1070 # @param fineness for the fineness [0-1]
1071 def AutomaticLength(self, fineness=0):
1072 hyp = self.OwnHypothesis("AutomaticLength")
1073 hyp.SetFineness( fineness )
1077 # Public class: Mesh
1078 # ==================
1080 ## Class to define a mesh
1082 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1092 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1093 # sets GUI name of this mesh to \a name.
1094 # @param obj Shape to be meshed or SMESH_Mesh object
1095 # @param name Study name of the mesh
1096 def __init__(self, obj=0, name=0):
1100 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1102 self.mesh = smesh.CreateMesh(self.geom)
1103 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1106 self.mesh = smesh.CreateEmptyMesh()
1108 SetName(self.mesh, name)
1110 SetName(self.mesh, GetName(obj))
1112 self.editor = self.mesh.GetMeshEditor()
1114 ## Method that inits the Mesh object from SMESH_Mesh interface
1115 # @param theMesh is SMESH_Mesh object
1116 def SetMesh(self, theMesh):
1118 self.geom = self.mesh.GetShapeToMesh()
1120 ## Method that returns the mesh
1121 # @return SMESH_Mesh object
1127 name = GetName(self.GetMesh())
1131 def SetName(self, name):
1132 SetName(self.GetMesh(), name)
1134 ## Get the subMesh object associated to a subShape. The subMesh object
1135 # gives access to nodes and elements IDs.
1136 # \n SubMesh will be used instead of SubShape in a next idl version to
1137 # adress a specific subMesh...
1138 def GetSubMesh(self, theSubObject, name):
1139 submesh = self.mesh.GetSubMesh(theSubObject, name)
1142 ## Method that returns the shape associated to the mesh
1143 # @return GEOM_Object
1147 ## Method that associates given shape to the mesh(entails the mesh recreation)
1148 # @param geom shape to be meshed(GEOM_Object)
1149 def SetShape(self, geom):
1150 self.mesh = smesh.CreateMesh(geom)
1152 ## Return true if hypotheses are defined well
1153 # @param theMesh is an instance of Mesh class
1154 # @param theSubObject subshape of a mesh shape
1155 def IsReadyToCompute(self, theSubObject):
1156 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1158 ## Return errors of hypotheses definintion
1159 # error list is empty if everything is OK
1160 # @param theMesh is an instance of Mesh class
1161 # @param theSubObject subshape of a mesh shape
1162 # @return a list of errors
1163 def GetAlgoState(self, theSubObject):
1164 return smesh.GetAlgoState(self.mesh, theSubObject)
1166 ## Return geometrical object the given element is built on.
1167 # The returned geometrical object, if not nil, is either found in the
1168 # study or is published by this method with the given name
1169 # @param theMesh is an instance of Mesh class
1170 # @param theElementID an id of the mesh element
1171 # @param theGeomName user defined name of geometrical object
1172 # @return GEOM::GEOM_Object instance
1173 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1174 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1176 ## Returns mesh dimension depending on shape one
1177 def MeshDimension(self):
1178 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1179 if len( shells ) > 0 :
1181 elif geompy.NumberOfFaces( self.geom ) > 0 :
1183 elif geompy.NumberOfEdges( self.geom ) > 0 :
1189 ## Creates a segment discretization 1D algorithm.
1190 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1191 # If the optional \a geom parameter is not sets, this algorithm is global.
1192 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1193 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1194 # @param geom If defined, subshape to be meshed
1195 def Segment(self, algo=REGULAR, geom=0):
1196 ## if Segment(geom) is called by mistake
1197 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1198 algo, geom = geom, algo
1201 return Mesh_Segment(self, geom)
1202 elif algo == PYTHON:
1203 return Mesh_Segment_Python(self, geom)
1205 return Mesh_Segment(self, geom)
1207 ## Creates a triangle 2D algorithm for faces.
1208 # If the optional \a geom parameter is not sets, this algorithm is global.
1209 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1210 # @param algo values are: smesh.MEFISTO or smesh.NETGEN
1211 # @param geom If defined, subshape to be meshed
1212 def Triangle(self, algo=MEFISTO, geom=0):
1213 ## if Triangle(geom) is called by mistake
1214 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1218 return Mesh_Triangle(self, algo, geom)
1220 ## Creates a quadrangle 2D algorithm for faces.
1221 # If the optional \a geom parameter is not sets, this algorithm is global.
1222 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1223 # @param geom If defined, subshape to be meshed
1224 def Quadrangle(self, geom=0):
1225 return Mesh_Quadrangle(self, geom)
1227 ## Creates a tetrahedron 3D algorithm for solids.
1228 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1229 # If the optional \a geom parameter is not sets, this algorithm is global.
1230 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1231 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1232 # @param geom If defined, subshape to be meshed
1233 def Tetrahedron(self, algo=NETGEN, geom=0):
1234 ## if Tetrahedron(geom) is called by mistake
1235 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1236 algo, geom = geom, algo
1238 return Mesh_Tetrahedron(self, algo, geom)
1240 ## Creates a hexahedron 3D algorithm for solids.
1241 # If the optional \a geom parameter is not sets, this algorithm is global.
1242 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1243 # @param geom If defined, subshape to be meshed
1244 ## def Hexahedron(self, geom=0):
1245 ## return Mesh_Hexahedron(self, geom)
1246 def Hexahedron(self, algo=Hexa, geom=0):
1247 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1248 if ( isinstance(algo, geompy.GEOM._objref_GEOM_Object) ):
1249 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
1250 elif geom == 0: algo, geom = Hexa, algo
1251 return Mesh_Hexahedron(self, algo, geom)
1253 ## Deprecated, only for compatibility!
1254 def Netgen(self, is3D, geom=0):
1255 return Mesh_Netgen(self, is3D, geom)
1257 ## Creates a projection 1D algorithm for edges.
1258 # If the optional \a geom parameter is not sets, this algorithm is global.
1259 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1260 # @param geom If defined, subshape to be meshed
1261 def Projection1D(self, geom=0):
1262 return Mesh_Projection1D(self, geom)
1264 ## Creates a projection 2D algorithm for faces.
1265 # If the optional \a geom parameter is not sets, this algorithm is global.
1266 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1267 # @param geom If defined, subshape to be meshed
1268 def Projection2D(self, geom=0):
1269 return Mesh_Projection2D(self, geom)
1271 ## Creates a projection 3D algorithm for solids.
1272 # If the optional \a geom parameter is not sets, this algorithm is global.
1273 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1274 # @param geom If defined, subshape to be meshed
1275 def Projection3D(self, geom=0):
1276 return Mesh_Projection3D(self, geom)
1278 ## Creates a Prism 3D or RadialPrism 3D algorithm for solids.
1279 # If the optional \a geom parameter is not sets, this algorithm is global.
1280 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1281 # @param geom If defined, subshape to be meshed
1282 def Prism(self, geom=0):
1286 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1287 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1288 if nbSolids == 0 or nbSolids == nbShells:
1289 return Mesh_Prism3D(self, geom)
1290 return Mesh_RadialPrism3D(self, geom)
1292 ## Compute the mesh and return the status of the computation
1293 def Compute(self, geom=0):
1294 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1296 print "Compute impossible: mesh is not constructed on geom shape."
1300 ok = smesh.Compute(self.mesh, geom)
1302 errors = smesh.GetAlgoState( self.mesh, geom )
1305 if err.isGlobalAlgo:
1310 dim = str(err.algoDim)
1311 if err.name == MISSING_ALGO:
1312 reason = glob + dim + "D algorithm is missing"
1313 elif err.name == MISSING_HYPO:
1314 name = '"' + err.algoName + '"'
1315 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1316 elif err.name == NOT_CONFORM_MESH:
1317 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1318 elif err.name == BAD_PARAM_VALUE:
1319 name = '"' + err.algoName + '"'
1320 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1321 " has a bad parameter value"
1323 reason = "For unknown reason."+\
1324 " Revise Mesh.Compute() implementation in smesh.py!"
1326 if allReasons != "":
1329 allReasons += reason
1331 if allReasons != "":
1332 print '"' + GetName(self.mesh) + '"',"not computed:"
1336 if salome.sg.hasDesktop():
1337 smeshgui = salome.ImportComponentGUI("SMESH")
1338 smeshgui.Init(salome.myStudyId)
1339 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok )
1340 salome.sg.updateObjBrowser(1)
1344 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1345 # The parameter \a fineness [0,-1] defines mesh fineness
1346 def AutomaticTetrahedralization(self, fineness=0):
1347 dim = self.MeshDimension()
1349 self.RemoveGlobalHypotheses()
1350 self.Segment().AutomaticLength(fineness)
1352 self.Triangle().LengthFromEdges()
1355 self.Tetrahedron(NETGEN)
1357 return self.Compute()
1359 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1360 # The parameter \a fineness [0,-1] defines mesh fineness
1361 def AutomaticHexahedralization(self, fineness=0):
1362 dim = self.MeshDimension()
1364 self.RemoveGlobalHypotheses()
1365 self.Segment().AutomaticLength(fineness)
1372 return self.Compute()
1374 ## Get the list of hypothesis added on a geom
1375 # @param geom is subhape of mesh geometry
1376 def GetHypothesisList(self, geom):
1377 return self.mesh.GetHypothesisList( geom )
1379 ## Removes all global hypotheses
1380 def RemoveGlobalHypotheses(self):
1381 current_hyps = self.mesh.GetHypothesisList( self.geom )
1382 for hyp in current_hyps:
1383 self.mesh.RemoveHypothesis( self.geom, hyp )
1387 ## Create a mesh group based on geometric object \a grp
1388 # and give a \a name, \n if this parameter is not defined
1389 # the name is the same as the geometric group name \n
1390 # Note: Works like GroupOnGeom().
1391 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1392 # @param name is the name of the mesh group
1393 # @return SMESH_GroupOnGeom
1394 def Group(self, grp, name=""):
1395 return self.GroupOnGeom(grp, name)
1397 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1398 # Export the mesh in a file with the MED format and choice the \a version of MED format
1399 # @param f is the file name
1400 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1401 def ExportToMED(self, f, version, opt=0):
1402 self.mesh.ExportToMED(f, opt, version)
1404 ## Export the mesh in a file with the MED format
1405 # @param f is the file name
1406 # @param auto_groups boolean parameter for creating/not creating
1407 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1408 # the typical use is auto_groups=false.
1409 # @param version MED format version(MED_V2_1 or MED_V2_2)
1410 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1411 self.mesh.ExportToMED(f, auto_groups, version)
1413 ## Export the mesh in a file with the DAT format
1414 # @param f is the file name
1415 def ExportDAT(self, f):
1416 self.mesh.ExportDAT(f)
1418 ## Export the mesh in a file with the UNV format
1419 # @param f is the file name
1420 def ExportUNV(self, f):
1421 self.mesh.ExportUNV(f)
1423 ## Export the mesh in a file with the STL format
1424 # @param f is the file name
1425 # @param ascii defined the kind of file contents
1426 def ExportSTL(self, f, ascii=1):
1427 self.mesh.ExportSTL(f, ascii)
1430 # Operations with groups:
1431 # ----------------------
1433 ## Creates an empty mesh group
1434 # @param elementType is the type of elements in the group
1435 # @param name is the name of the mesh group
1436 # @return SMESH_Group
1437 def CreateEmptyGroup(self, elementType, name):
1438 return self.mesh.CreateGroup(elementType, name)
1440 ## Creates a mesh group based on geometric object \a grp
1441 # and give a \a name, \n if this parameter is not defined
1442 # the name is the same as the geometric group name
1443 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1444 # @param name is the name of the mesh group
1445 # @return SMESH_GroupOnGeom
1446 def GroupOnGeom(self, grp, name="", type=None):
1448 name = grp.GetName()
1451 tgeo = str(grp.GetShapeType())
1452 if tgeo == "VERTEX":
1454 elif tgeo == "EDGE":
1456 elif tgeo == "FACE":
1458 elif tgeo == "SOLID":
1460 elif tgeo == "SHELL":
1462 elif tgeo == "COMPOUND":
1463 if len( geompy.GetObjectIDs( grp )) == 0:
1464 print "Mesh.Group: empty geometric group", GetName( grp )
1466 tgeo = geompy.GetType(grp)
1467 if tgeo == geompy.ShapeType["VERTEX"]:
1469 elif tgeo == geompy.ShapeType["EDGE"]:
1471 elif tgeo == geompy.ShapeType["FACE"]:
1473 elif tgeo == geompy.ShapeType["SOLID"]:
1477 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1480 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1482 ## Create a mesh group by the given ids of elements
1483 # @param groupName is the name of the mesh group
1484 # @param elementType is the type of elements in the group
1485 # @param elemIDs is the list of ids
1486 # @return SMESH_Group
1487 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1488 group = self.mesh.CreateGroup(elementType, groupName)
1492 ## Create a mesh group by the given conditions
1493 # @param groupName is the name of the mesh group
1494 # @param elementType is the type of elements in the group
1495 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1496 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1497 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1498 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1499 # @return SMESH_Group
1503 CritType=FT_Undefined,
1506 UnaryOp=FT_Undefined):
1507 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1508 group = self.MakeGroupByCriterion(groupName, aCriterion)
1511 ## Create a mesh group by the given criterion
1512 # @param groupName is the name of the mesh group
1513 # @param Criterion is the instance of Criterion class
1514 # @return SMESH_Group
1515 def MakeGroupByCriterion(self, groupName, Criterion):
1516 aFilterMgr = smesh.CreateFilterManager()
1517 aFilter = aFilterMgr.CreateFilter()
1519 aCriteria.append(Criterion)
1520 aFilter.SetCriteria(aCriteria)
1521 group = self.MakeGroupByFilter(groupName, aFilter)
1524 ## Create a mesh group by the given criteria(list of criterions)
1525 # @param groupName is the name of the mesh group
1526 # @param Criteria is the list of criterions
1527 # @return SMESH_Group
1528 def MakeGroupByCriteria(self, groupName, theCriteria):
1529 aFilterMgr = smesh.CreateFilterManager()
1530 aFilter = aFilterMgr.CreateFilter()
1531 aFilter.SetCriteria(theCriteria)
1532 group = self.MakeGroupByFilter(groupName, aFilter)
1535 ## Create a mesh group by the given filter
1536 # @param groupName is the name of the mesh group
1537 # @param Criterion is the instance of Filter class
1538 # @return SMESH_Group
1539 def MakeGroupByFilter(self, groupName, theFilter):
1540 anIds = theFilter.GetElementsId(self.mesh)
1541 anElemType = theFilter.GetElementType()
1542 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1545 ## Pass mesh elements through the given filter and return ids
1546 # @param theFilter is SMESH_Filter
1547 # @return list of ids
1548 def GetIdsFromFilter(self, theFilter):
1549 return theFilter.GetElementsId(self.mesh)
1551 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1552 # Returns list of special structures(borders).
1553 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1554 def GetFreeBorders(self):
1555 aFilterMgr = smesh.CreateFilterManager()
1556 aPredicate = aFilterMgr.CreateFreeEdges()
1557 aPredicate.SetMesh(self.mesh)
1558 aBorders = aPredicate.GetBorders()
1562 def RemoveGroup(self, group):
1563 self.mesh.RemoveGroup(group)
1565 ## Remove group with its contents
1566 def RemoveGroupWithContents(self, group):
1567 self.mesh.RemoveGroupWithContents(group)
1569 ## Get the list of groups existing in the mesh
1570 def GetGroups(self):
1571 return self.mesh.GetGroups()
1573 ## Get the list of names of groups existing in the mesh
1574 def GetGroupNames(self):
1575 groups = self.GetGroups()
1577 for group in groups:
1578 names.append(group.GetName())
1581 ## Union of two groups
1582 # New group is created. All mesh elements that are
1583 # present in initial groups are added to the new one
1584 def UnionGroups(self, group1, group2, name):
1585 return self.mesh.UnionGroups(group1, group2, name)
1587 ## Intersection of two groups
1588 # New group is created. All mesh elements that are
1589 # present in both initial groups are added to the new one.
1590 def IntersectGroups(self, group1, group2, name):
1591 return self.mesh.IntersectGroups(group1, group2, name)
1593 ## Cut of two groups
1594 # New group is created. All mesh elements that are present in
1595 # main group but do not present in tool group are added to the new one
1596 def CutGroups(self, mainGroup, toolGroup, name):
1597 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1600 # Get some info about mesh:
1601 # ------------------------
1603 ## Get the log of nodes and elements added or removed since previous
1605 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1606 # @return list of log_block structures:
1611 def GetLog(self, clearAfterGet):
1612 return self.mesh.GetLog(clearAfterGet)
1614 ## Clear the log of nodes and elements added or removed since previous
1615 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1617 self.mesh.ClearLog()
1619 ## Get the internal Id
1621 return self.mesh.GetId()
1624 def GetStudyId(self):
1625 return self.mesh.GetStudyId()
1627 ## Check group names for duplications.
1628 # Consider maximum group name length stored in MED file.
1629 def HasDuplicatedGroupNamesMED(self):
1630 return self.mesh.GetStudyId()
1632 ## Obtain instance of SMESH_MeshEditor
1633 def GetMeshEditor(self):
1634 return self.mesh.GetMeshEditor()
1637 def GetMEDMesh(self):
1638 return self.mesh.GetMEDMesh()
1641 # Get informations about mesh contents:
1642 # ------------------------------------
1644 ## Returns number of nodes in mesh
1646 return self.mesh.NbNodes()
1648 ## Returns number of elements in mesh
1649 def NbElements(self):
1650 return self.mesh.NbElements()
1652 ## Returns number of edges in mesh
1654 return self.mesh.NbEdges()
1656 ## Returns number of edges with given order in mesh
1657 # @param elementOrder is order of elements:
1658 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1659 def NbEdgesOfOrder(self, elementOrder):
1660 return self.mesh.NbEdgesOfOrder(elementOrder)
1662 ## Returns number of faces in mesh
1664 return self.mesh.NbFaces()
1666 ## Returns number of faces with given order in mesh
1667 # @param elementOrder is order of elements:
1668 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1669 def NbFacesOfOrder(self, elementOrder):
1670 return self.mesh.NbFacesOfOrder(elementOrder)
1672 ## Returns number of triangles in mesh
1673 def NbTriangles(self):
1674 return self.mesh.NbTriangles()
1676 ## Returns number of triangles with given order in mesh
1677 # @param elementOrder is order of elements:
1678 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1679 def NbTrianglesOfOrder(self, elementOrder):
1680 return self.mesh.NbTrianglesOfOrder(elementOrder)
1682 ## Returns number of quadrangles in mesh
1683 def NbQuadrangles(self):
1684 return self.mesh.NbQuadrangles()
1686 ## Returns number of quadrangles with given order in mesh
1687 # @param elementOrder is order of elements:
1688 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1689 def NbQuadranglesOfOrder(self, elementOrder):
1690 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1692 ## Returns number of polygons in mesh
1693 def NbPolygons(self):
1694 return self.mesh.NbPolygons()
1696 ## Returns number of volumes in mesh
1697 def NbVolumes(self):
1698 return self.mesh.NbVolumes()
1700 ## Returns number of volumes with given order in mesh
1701 # @param elementOrder is order of elements:
1702 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1703 def NbVolumesOfOrder(self, elementOrder):
1704 return self.mesh.NbVolumesOfOrder(elementOrder)
1706 ## Returns number of tetrahedrons in mesh
1708 return self.mesh.NbTetras()
1710 ## Returns number of tetrahedrons with given order in mesh
1711 # @param elementOrder is order of elements:
1712 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1713 def NbTetrasOfOrder(self, elementOrder):
1714 return self.mesh.NbTetrasOfOrder(elementOrder)
1716 ## Returns number of hexahedrons in mesh
1718 return self.mesh.NbHexas()
1720 ## Returns number of hexahedrons with given order in mesh
1721 # @param elementOrder is order of elements:
1722 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1723 def NbHexasOfOrder(self, elementOrder):
1724 return self.mesh.NbHexasOfOrder(elementOrder)
1726 ## Returns number of pyramids in mesh
1727 def NbPyramids(self):
1728 return self.mesh.NbPyramids()
1730 ## Returns number of pyramids with given order in mesh
1731 # @param elementOrder is order of elements:
1732 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1733 def NbPyramidsOfOrder(self, elementOrder):
1734 return self.mesh.NbPyramidsOfOrder(elementOrder)
1736 ## Returns number of prisms in mesh
1738 return self.mesh.NbPrisms()
1740 ## Returns number of prisms with given order in mesh
1741 # @param elementOrder is order of elements:
1742 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1743 def NbPrismsOfOrder(self, elementOrder):
1744 return self.mesh.NbPrismsOfOrder(elementOrder)
1746 ## Returns number of polyhedrons in mesh
1747 def NbPolyhedrons(self):
1748 return self.mesh.NbPolyhedrons()
1750 ## Returns number of submeshes in mesh
1751 def NbSubMesh(self):
1752 return self.mesh.NbSubMesh()
1754 ## Returns list of mesh elements ids
1755 def GetElementsId(self):
1756 return self.mesh.GetElementsId()
1758 ## Returns list of ids of mesh elements with given type
1759 # @param elementType is required type of elements
1760 def GetElementsByType(self, elementType):
1761 return self.mesh.GetElementsByType(elementType)
1763 ## Returns list of mesh nodes ids
1764 def GetNodesId(self):
1765 return self.mesh.GetNodesId()
1767 # Get informations about mesh elements:
1768 # ------------------------------------
1770 ## Returns type of mesh element
1771 def GetElementType(self, id, iselem):
1772 return self.mesh.GetElementType(id, iselem)
1774 ## Returns list of submesh elements ids
1775 # @param shapeID is geom object(subshape) IOR
1776 def GetSubMeshElementsId(self, shapeID):
1777 return self.mesh.GetSubMeshElementsId(shapeID)
1779 ## Returns list of submesh nodes ids
1780 # @param shapeID is geom object(subshape) IOR
1781 def GetSubMeshNodesId(self, shapeID, all):
1782 return self.mesh.GetSubMeshNodesId(shapeID, all)
1784 ## Returns list of ids of submesh elements with given type
1785 # @param shapeID is geom object(subshape) IOR
1786 def GetSubMeshElementType(self, shapeID):
1787 return self.mesh.GetSubMeshElementType(shapeID)
1789 ## Get mesh description
1791 return self.mesh.Dump()
1794 # Get information about nodes and elements of mesh by its ids:
1795 # -----------------------------------------------------------
1797 ## Get XYZ coordinates of node as list of double
1798 # \n If there is not node for given ID - returns empty list
1799 def GetNodeXYZ(self, id):
1800 return self.mesh.GetNodeXYZ(id)
1802 ## For given node returns list of IDs of inverse elements
1803 # \n If there is not node for given ID - returns empty list
1804 def GetNodeInverseElements(self, id):
1805 return self.mesh.GetNodeInverseElements(id)
1807 ## If given element is node returns IDs of shape from position
1808 # \n If there is not node for given ID - returns -1
1809 def GetShapeID(self, id):
1810 return self.mesh.GetShapeID(id)
1812 ## For given element returns ID of result shape after
1813 # FindShape() from SMESH_MeshEditor
1814 # \n If there is not element for given ID - returns -1
1815 def GetShapeIDForElem(id):
1816 return self.mesh.GetShapeIDForElem(id)
1818 ## Returns number of nodes for given element
1819 # \n If there is not element for given ID - returns -1
1820 def GetElemNbNodes(self, id):
1821 return self.mesh.GetElemNbNodes(id)
1823 ## Returns ID of node by given index for given element
1824 # \n If there is not element for given ID - returns -1
1825 # \n If there is not node for given index - returns -2
1826 def GetElemNode(self, id, index):
1827 return self.mesh.GetElemNode(id, index)
1829 ## Returns true if given node is medium node
1830 # in given quadratic element
1831 def IsMediumNode(self, elementID, nodeID):
1832 return self.mesh.IsMediumNode(elementID, nodeID)
1834 ## Returns true if given node is medium node
1835 # in one of quadratic elements
1836 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1837 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1839 ## Returns number of edges for given element
1840 def ElemNbEdges(self, id):
1841 return self.mesh.ElemNbEdges(id)
1843 ## Returns number of faces for given element
1844 def ElemNbFaces(self, id):
1845 return self.mesh.ElemNbFaces(id)
1847 ## Returns true if given element is polygon
1848 def IsPoly(self, id):
1849 return self.mesh.IsPoly(id)
1851 ## Returns true if given element is quadratic
1852 def IsQuadratic(self, id):
1853 return self.mesh.IsQuadratic(id)
1855 ## Returns XYZ coordinates of bary center for given element
1857 # \n If there is not element for given ID - returns empty list
1858 def BaryCenter(self, id):
1859 return self.mesh.BaryCenter(id)
1862 # Mesh edition (SMESH_MeshEditor functionality):
1863 # ---------------------------------------------
1865 ## Removes elements from mesh by ids
1866 # @param IDsOfElements is list of ids of elements to remove
1867 def RemoveElements(self, IDsOfElements):
1868 return self.editor.RemoveElements(IDsOfElements)
1870 ## Removes nodes from mesh by ids
1871 # @param IDsOfNodes is list of ids of nodes to remove
1872 def RemoveNodes(self, IDsOfNodes):
1873 return self.editor.RemoveNodes(IDsOfNodes)
1875 ## Add node to mesh by coordinates
1876 def AddNode(self, x, y, z):
1877 return self.editor.AddNode( x, y, z)
1880 ## Create edge both similar and quadratic (this is determed
1881 # by number of given nodes).
1882 # @param IdsOfNodes List of node IDs for creation of element.
1883 # Needed order of nodes in this list corresponds to description
1884 # of MED. \n This description is located by the following link:
1885 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1886 def AddEdge(self, IDsOfNodes):
1887 return self.editor.AddEdge(IDsOfNodes)
1889 ## Create face both similar and quadratic (this is determed
1890 # by number of given nodes).
1891 # @param IdsOfNodes List of node IDs for creation of element.
1892 # Needed order of nodes in this list corresponds to description
1893 # of MED. \n This description is located by the following link:
1894 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1895 def AddFace(self, IDsOfNodes):
1896 return self.editor.AddFace(IDsOfNodes)
1898 ## Add polygonal face to mesh by list of nodes ids
1899 def AddPolygonalFace(self, IdsOfNodes):
1900 return self.editor.AddPolygonalFace(IdsOfNodes)
1902 ## Create volume both similar and quadratic (this is determed
1903 # by number of given nodes).
1904 # @param IdsOfNodes List of node IDs for creation of element.
1905 # Needed order of nodes in this list corresponds to description
1906 # of MED. \n This description is located by the following link:
1907 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1908 def AddVolume(self, IDsOfNodes):
1909 return self.editor.AddVolume(IDsOfNodes)
1911 ## Create volume of many faces, giving nodes for each face.
1912 # @param IdsOfNodes List of node IDs for volume creation face by face.
1913 # @param Quantities List of integer values, Quantities[i]
1914 # gives quantity of nodes in face number i.
1915 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1916 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1918 ## Create volume of many faces, giving IDs of existing faces.
1919 # @param IdsOfFaces List of face IDs for volume creation.
1921 # Note: The created volume will refer only to nodes
1922 # of the given faces, not to the faces itself.
1923 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1924 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1926 ## Move node with given id
1927 # @param NodeID id of the node
1928 # @param x displacing along the X axis
1929 # @param y displacing along the Y axis
1930 # @param z displacing along the Z axis
1931 def MoveNode(self, NodeID, x, y, z):
1932 return self.editor.MoveNode(NodeID, x, y, z)
1934 ## Replace two neighbour triangles sharing Node1-Node2 link
1935 # with ones built on the same 4 nodes but having other common link.
1936 # @param NodeID1 first node id
1937 # @param NodeID2 second node id
1938 # @return false if proper faces not found
1939 def InverseDiag(self, NodeID1, NodeID2):
1940 return self.editor.InverseDiag(NodeID1, NodeID2)
1942 ## Replace two neighbour triangles sharing Node1-Node2 link
1943 # with a quadrangle built on the same 4 nodes.
1944 # @param NodeID1 first node id
1945 # @param NodeID2 second node id
1946 # @return false if proper faces not found
1947 def DeleteDiag(self, NodeID1, NodeID2):
1948 return self.editor.DeleteDiag(NodeID1, NodeID2)
1950 ## Reorient elements by ids
1951 # @param IDsOfElements if undefined reorient all mesh elements
1952 def Reorient(self, IDsOfElements=None):
1953 if IDsOfElements == None:
1954 IDsOfElements = self.GetElementsId()
1955 return self.editor.Reorient(IDsOfElements)
1957 ## Reorient all elements of the object
1958 # @param theObject is mesh, submesh or group
1959 def ReorientObject(self, theObject):
1960 return self.editor.ReorientObject(theObject)
1962 ## Fuse neighbour triangles into quadrangles.
1963 # @param IDsOfElements The triangles to be fused,
1964 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1965 # @param MaxAngle is a max angle between element normals at which fusion
1966 # is still performed; theMaxAngle is mesured in radians.
1967 # @return TRUE in case of success, FALSE otherwise.
1968 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1969 if IDsOfElements == []:
1970 IDsOfElements = self.GetElementsId()
1971 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1973 ## Fuse neighbour triangles of the object into quadrangles
1974 # @param theObject is mesh, submesh or group
1975 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1976 # @param MaxAngle is a max angle between element normals at which fusion
1977 # is still performed; theMaxAngle is mesured in radians.
1978 # @return TRUE in case of success, FALSE otherwise.
1979 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1980 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1982 ## Split quadrangles into triangles.
1983 # @param IDsOfElements the faces to be splitted.
1984 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1985 # @param @return TRUE in case of success, FALSE otherwise.
1986 def QuadToTri (self, IDsOfElements, theCriterion):
1987 if IDsOfElements == []:
1988 IDsOfElements = self.GetElementsId()
1989 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
1991 ## Split quadrangles into triangles.
1992 # @param theObject object to taking list of elements from, is mesh, submesh or group
1993 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1994 def QuadToTriObject (self, theObject, theCriterion):
1995 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
1997 ## Split quadrangles into triangles.
1998 # @param theElems The faces to be splitted
1999 # @param the13Diag is used to choose a diagonal for splitting.
2000 # @return TRUE in case of success, FALSE otherwise.
2001 def SplitQuad (self, IDsOfElements, Diag13):
2002 if IDsOfElements == []:
2003 IDsOfElements = self.GetElementsId()
2004 return self.editor.SplitQuad(IDsOfElements, Diag13)
2006 ## Split quadrangles into triangles.
2007 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2008 def SplitQuadObject (self, theObject, Diag13):
2009 return self.editor.SplitQuadObject(theObject, Diag13)
2011 ## Find better splitting of the given quadrangle.
2012 # @param IDOfQuad ID of the quadrangle to be splitted.
2013 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2014 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2015 # diagonal is better, 0 if error occurs.
2016 def BestSplit (self, IDOfQuad, theCriterion):
2017 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2020 # @param IDsOfElements list if ids of elements to smooth
2021 # @param IDsOfFixedNodes list of ids of fixed nodes.
2022 # Note that nodes built on edges and boundary nodes are always fixed.
2023 # @param MaxNbOfIterations maximum number of iterations
2024 # @param MaxAspectRatio varies in range [1.0, inf]
2025 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2026 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2027 MaxNbOfIterations, MaxAspectRatio, Method):
2028 if IDsOfElements == []:
2029 IDsOfElements = self.GetElementsId()
2030 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2031 MaxNbOfIterations, MaxAspectRatio, Method)
2033 ## Smooth elements belong to given object
2034 # @param theObject object to smooth
2035 # @param IDsOfFixedNodes list of ids of fixed nodes.
2036 # Note that nodes built on edges and boundary nodes are always fixed.
2037 # @param MaxNbOfIterations maximum number of iterations
2038 # @param MaxAspectRatio varies in range [1.0, inf]
2039 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2040 def SmoothObject(self, theObject, IDsOfFixedNodes,
2041 MaxNbOfIterations, MaxxAspectRatio, Method):
2042 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2043 MaxNbOfIterations, MaxxAspectRatio, Method)
2045 ## Parametric smooth the given elements
2046 # @param IDsOfElements list if ids of elements to smooth
2047 # @param IDsOfFixedNodes list of ids of fixed nodes.
2048 # Note that nodes built on edges and boundary nodes are always fixed.
2049 # @param MaxNbOfIterations maximum number of iterations
2050 # @param MaxAspectRatio varies in range [1.0, inf]
2051 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2052 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2053 MaxNbOfIterations, MaxAspectRatio, Method):
2054 if IDsOfElements == []:
2055 IDsOfElements = self.GetElementsId()
2056 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2057 MaxNbOfIterations, MaxAspectRatio, Method)
2059 ## Parametric smooth elements belong to given object
2060 # @param theObject object to smooth
2061 # @param IDsOfFixedNodes list of ids of fixed nodes.
2062 # Note that nodes built on edges and boundary nodes are always fixed.
2063 # @param MaxNbOfIterations maximum number of iterations
2064 # @param MaxAspectRatio varies in range [1.0, inf]
2065 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2066 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2067 MaxNbOfIterations, MaxAspectRatio, Method):
2068 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2069 MaxNbOfIterations, MaxAspectRatio, Method)
2071 ## Converts all mesh to quadratic one, deletes old elements, replacing
2072 # them with quadratic ones with the same id.
2073 def ConvertToQuadratic(self, theForce3d):
2074 self.editor.ConvertToQuadratic(theForce3d)
2076 ## Converts all mesh from quadratic to ordinary ones,
2077 # deletes old quadratic elements, \n replacing
2078 # them with ordinary mesh elements with the same id.
2079 def ConvertFromQuadratic(self):
2080 return self.editor.ConvertFromQuadratic()
2082 ## Renumber mesh nodes
2083 def RenumberNodes(self):
2084 self.editor.RenumberNodes()
2086 ## Renumber mesh elements
2087 def RenumberElements(self):
2088 self.editor.RenumberElements()
2090 ## Generate new elements by rotation of the elements around the axis
2091 # @param IDsOfElements list of ids of elements to sweep
2092 # @param Axix axis of rotation, AxisStruct or line(geom object)
2093 # @param AngleInRadians angle of Rotation
2094 # @param NbOfSteps number of steps
2095 # @param Tolerance tolerance
2096 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2097 if IDsOfElements == []:
2098 IDsOfElements = self.GetElementsId()
2099 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2100 Axix = GetAxisStruct(Axix)
2101 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2103 ## Generate new elements by rotation of the elements of object around the axis
2104 # @param theObject object wich elements should be sweeped
2105 # @param Axix axis of rotation, AxisStruct or line(geom object)
2106 # @param AngleInRadians angle of Rotation
2107 # @param NbOfSteps number of steps
2108 # @param Tolerance tolerance
2109 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2110 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2111 Axix = GetAxisStruct(Axix)
2112 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2114 ## Generate new elements by extrusion of the elements with given ids
2115 # @param IDsOfElements list of elements ids for extrusion
2116 # @param StepVector vector, defining the direction and value of extrusion
2117 # @param NbOfSteps the number of steps
2118 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2119 if IDsOfElements == []:
2120 IDsOfElements = self.GetElementsId()
2121 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2122 StepVector = GetDirStruct(StepVector)
2123 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2125 ## Generate new elements by extrusion of the elements with given ids
2126 # @param IDsOfElements is ids of elements
2127 # @param StepVector vector, defining the direction and value of extrusion
2128 # @param NbOfSteps the number of steps
2129 # @param ExtrFlags set flags for performing extrusion
2130 # @param SewTolerance uses for comparing locations of nodes if flag
2131 # EXTRUSION_FLAG_SEW is set
2132 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2133 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2134 StepVector = GetDirStruct(StepVector)
2135 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2137 ## Generate new elements by extrusion of the elements belong to object
2138 # @param theObject object wich elements should be processed
2139 # @param StepVector vector, defining the direction and value of extrusion
2140 # @param NbOfSteps the number of steps
2141 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2142 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2143 StepVector = GetDirStruct(StepVector)
2144 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2146 ## Generate new elements by extrusion of the elements belong to object
2147 # @param theObject object wich elements should be processed
2148 # @param StepVector vector, defining the direction and value of extrusion
2149 # @param NbOfSteps the number of steps
2150 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2151 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2152 StepVector = GetDirStruct(StepVector)
2153 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2155 ## Generate new elements by extrusion of the elements belong to object
2156 # @param theObject object wich elements should be processed
2157 # @param StepVector vector, defining the direction and value of extrusion
2158 # @param NbOfSteps the number of steps
2159 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2160 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2161 StepVector = GetDirStruct(StepVector)
2162 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2164 ## Generate new elements by extrusion of the given elements
2165 # A path of extrusion must be a meshed edge.
2166 # @param IDsOfElements is ids of elements
2167 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2168 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2169 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2170 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2171 # @param Angles list of angles
2172 # @param HasRefPoint allows to use base point
2173 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2174 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2175 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2176 HasAngles, Angles, HasRefPoint, RefPoint):
2177 if IDsOfElements == []:
2178 IDsOfElements = self.GetElementsId()
2179 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2180 RefPoint = GetPointStruct(RefPoint)
2181 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2182 HasAngles, Angles, HasRefPoint, RefPoint)
2184 ## Generate new elements by extrusion of the elements belong to object
2185 # A path of extrusion must be a meshed edge.
2186 # @param IDsOfElements is ids of elements
2187 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2188 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2189 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2190 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2191 # @param Angles list of angles
2192 # @param HasRefPoint allows to use base point
2193 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2194 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2195 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2196 HasAngles, Angles, HasRefPoint, RefPoint):
2197 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2198 RefPoint = GetPointStruct(RefPoint)
2199 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2200 HasAngles, Angles, HasRefPoint, RefPoint)
2202 ## Symmetrical copy of mesh elements
2203 # @param IDsOfElements list of elements ids
2204 # @param Mirror is AxisStruct or geom object(point, line, plane)
2205 # @param theMirrorType is POINT, AXIS or PLANE
2206 # If the Mirror is geom object this parameter is unnecessary
2207 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2208 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2209 if IDsOfElements == []:
2210 IDsOfElements = self.GetElementsId()
2211 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2212 Mirror = GetAxisStruct(Mirror)
2213 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2215 ## Symmetrical copy of object
2216 # @param theObject mesh, submesh or group
2217 # @param Mirror is AxisStruct or geom object(point, line, plane)
2218 # @param theMirrorType is POINT, AXIS or PLANE
2219 # If the Mirror is geom object this parameter is unnecessary
2220 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2221 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2222 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2223 Mirror = GetAxisStruct(Mirror)
2224 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2226 ## Translates the elements
2227 # @param IDsOfElements list of elements ids
2228 # @param Vector direction of translation(DirStruct or vector)
2229 # @param Copy allows to copy the translated elements
2230 def Translate(self, IDsOfElements, Vector, Copy):
2231 if IDsOfElements == []:
2232 IDsOfElements = self.GetElementsId()
2233 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2234 Vector = GetDirStruct(Vector)
2235 self.editor.Translate(IDsOfElements, Vector, Copy)
2237 ## Translates the object
2238 # @param theObject object to translate(mesh, submesh, or group)
2239 # @param Vector direction of translation(DirStruct or geom vector)
2240 # @param Copy allows to copy the translated elements
2241 def TranslateObject(self, theObject, Vector, Copy):
2242 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2243 Vector = GetDirStruct(Vector)
2244 self.editor.TranslateObject(theObject, Vector, Copy)
2246 ## Rotates the elements
2247 # @param IDsOfElements list of elements ids
2248 # @param Axis axis of rotation(AxisStruct or geom line)
2249 # @param AngleInRadians angle of rotation(in radians)
2250 # @param Copy allows to copy the rotated elements
2251 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2252 if IDsOfElements == []:
2253 IDsOfElements = self.GetElementsId()
2254 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2255 Axis = GetAxisStruct(Axis)
2256 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2258 ## Rotates the object
2259 # @param theObject object to rotate(mesh, submesh, or group)
2260 # @param Axis axis of rotation(AxisStruct or geom line)
2261 # @param AngleInRadians angle of rotation(in radians)
2262 # @param Copy allows to copy the rotated elements
2263 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2264 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2266 ## Find group of nodes close to each other within Tolerance.
2267 # @param Tolerance tolerance value
2268 # @param list of group of nodes
2269 def FindCoincidentNodes (self, Tolerance):
2270 return self.editor.FindCoincidentNodes(Tolerance)
2273 # @param list of group of nodes
2274 def MergeNodes (self, GroupsOfNodes):
2275 self.editor.MergeNodes(GroupsOfNodes)
2277 ## Remove all but one of elements built on the same nodes.
2278 def MergeEqualElements(self):
2279 self.editor.MergeEqualElements()
2282 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2283 FirstNodeID2, SecondNodeID2, LastNodeID2,
2284 CreatePolygons, CreatePolyedrs):
2285 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2286 FirstNodeID2, SecondNodeID2, LastNodeID2,
2287 CreatePolygons, CreatePolyedrs)
2289 ## Sew conform free borders
2290 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2291 FirstNodeID2, SecondNodeID2):
2292 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2293 FirstNodeID2, SecondNodeID2)
2295 ## Sew border to side
2296 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2297 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2298 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2299 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2301 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2302 # merged with nodes of elements of Side2.
2303 # Number of elements in theSide1 and in theSide2 must be
2304 # equal and they should have similar node connectivity.
2305 # The nodes to merge should belong to sides borders and
2306 # the first node should be linked to the second.
2307 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2308 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2309 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2310 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2311 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2312 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2314 ## Set new nodes for given element.
2315 # @param ide the element id
2316 # @param newIDs nodes ids
2317 # @return If number of nodes is not corresponded to type of element - returns false
2318 def ChangeElemNodes(self, ide, newIDs):
2319 return self.editor.ChangeElemNodes(ide, newIDs)
2321 ## If during last operation of MeshEditor some nodes were
2322 # created this method returns list of it's IDs, \n
2323 # if new nodes not created - returns empty list
2324 def GetLastCreatedNodes(self):
2325 return self.editor.GetLastCreatedNodes()
2327 ## If during last operation of MeshEditor some elements were
2328 # created this method returns list of it's IDs, \n
2329 # if new elements not creared - returns empty list
2330 def GetLastCreatedElems(self):
2331 return self.editor.GetLastCreatedElems()