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
54 # MirrorType enumeration
55 POINT = SMESH_MeshEditor.POINT
56 AXIS = SMESH_MeshEditor.AXIS
57 PLANE = SMESH_MeshEditor.PLANE
59 # Smooth_Method enumeration
60 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
61 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
63 # Fineness enumeration(for NETGEN)
75 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
76 smesh.SetCurrentStudy(salome.myStudy)
82 ior = salome.orb.object_to_string(obj)
83 sobj = salome.myStudy.FindObjectIOR(ior)
87 attr = sobj.FindAttribute("AttributeName")[1]
90 ## Sets name to object
91 def SetName(obj, name):
92 ior = salome.orb.object_to_string(obj)
93 sobj = salome.myStudy.FindObjectIOR(ior)
95 attr = sobj.FindAttribute("AttributeName")[1]
98 ## Returns long value from enumeration
99 # Uses for SMESH.FunctorType enumeration
100 def EnumToLong(theItem):
103 ## Get PointStruct from vertex
104 # @param theVertex is GEOM object(vertex)
105 # @return SMESH.PointStruct
106 def GetPointStruct(theVertex):
107 [x, y, z] = geompy.PointCoordinates(theVertex)
108 return PointStruct(x,y,z)
110 ## Get DirStruct from vector
111 # @param theVector is GEOM object(vector)
112 # @return SMESH.DirStruct
113 def GetDirStruct(theVector):
114 vertices = geompy.SubShapeAll( theVector, geompy.ShapeType["VERTEX"] )
115 if(len(vertices) != 2):
116 print "Error: vector object is incorrect."
118 p1 = geompy.PointCoordinates(vertices[0])
119 p2 = geompy.PointCoordinates(vertices[1])
120 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
124 ## Get AxisStruct from object
125 # @param theObj is GEOM object(line or plane)
126 # @return SMESH.AxisStruct
127 def GetAxisStruct(theObj):
128 edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
130 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
131 vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
132 vertex1 = geompy.PointCoordinates(vertex1)
133 vertex2 = geompy.PointCoordinates(vertex2)
134 vertex3 = geompy.PointCoordinates(vertex3)
135 vertex4 = geompy.PointCoordinates(vertex4)
136 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
137 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
138 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] ]
139 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
141 elif len(edges) == 1:
142 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
143 p1 = geompy.PointCoordinates( vertex1 )
144 p2 = geompy.PointCoordinates( vertex2 )
145 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
149 # From SMESH_Gen interface:
150 # ------------------------
152 ## Set the current mode
153 def SetEmbeddedMode( theMode ):
154 smesh.SetEmbeddedMode(theMode)
156 ## Get the current mode
157 def IsEmbeddedMode():
158 return smesh.IsEmbeddedMode()
160 ## Set the current study
161 def SetCurrentStudy( theStudy ):
162 smesh.SetCurrentStudy(theStudy)
164 ## Get the current study
165 def GetCurrentStudy():
166 return smesh.GetCurrentStudy()
168 ## Create Mesh object importing data from given UNV file
169 # @return an instance of Mesh class
170 def CreateMeshesFromUNV( theFileName ):
171 aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
172 aMesh = Mesh(aSmeshMesh)
175 ## Create Mesh object(s) importing data from given MED file
176 # @return a list of Mesh class instances
177 def CreateMeshesFromMED( theFileName ):
178 aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
180 for iMesh in range(len(aSmeshMeshes)) :
181 aMesh = Mesh(aSmeshMeshes[iMesh])
182 aMeshes.append(aMesh)
183 return aMeshes, aStatus
185 ## Create Mesh object importing data from given STL file
186 # @return an instance of Mesh class
187 def CreateMeshesFromSTL( theFileName ):
188 aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
189 aMesh = Mesh(aSmeshMesh)
192 ## From SMESH_Gen interface
193 def GetSubShapesId( theMainObject, theListOfSubObjects ):
194 return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
196 ## From SMESH_Gen interface. Creates pattern
198 return smesh.GetPattern()
202 # Filtering. Auxiliary functions:
203 # ------------------------------
205 ## Creates an empty criterion
206 # @return SMESH.Filter.Criterion
207 def GetEmptyCriterion():
208 Type = EnumToLong(FT_Undefined)
209 Compare = EnumToLong(FT_Undefined)
213 UnaryOp = EnumToLong(FT_Undefined)
214 BinaryOp = EnumToLong(FT_Undefined)
217 Precision = -1 ##@1e-07
218 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
219 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
221 ## Creates a criterion by given parameters
222 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
223 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
224 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
225 # @param Treshold is threshold value (range of ids as string, shape, numeric)
226 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
227 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
228 # FT_Undefined(must be for the last criterion in criteria)
229 # @return SMESH.Filter.Criterion
230 def GetCriterion(elementType,
232 Compare = FT_EqualTo,
234 UnaryOp=FT_Undefined,
235 BinaryOp=FT_Undefined):
236 aCriterion = GetEmptyCriterion()
237 aCriterion.TypeOfElement = elementType
238 aCriterion.Type = EnumToLong(CritType)
242 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
243 aCriterion.Compare = EnumToLong(Compare)
244 elif Compare == "=" or Compare == "==":
245 aCriterion.Compare = EnumToLong(FT_EqualTo)
247 aCriterion.Compare = EnumToLong(FT_LessThan)
249 aCriterion.Compare = EnumToLong(FT_MoreThan)
251 aCriterion.Compare = EnumToLong(FT_EqualTo)
254 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
255 FT_BelongToCylinder, FT_LyingOnGeom]:
257 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
258 aCriterion.ThresholdStr = GetName(aTreshold)
259 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
261 print "Error: Treshold should be a shape."
263 elif CritType == FT_RangeOfIds:
265 if isinstance(aTreshold, str):
266 aCriterion.ThresholdStr = aTreshold
268 print "Error: Treshold should be a string."
270 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
271 # Here we don't need treshold
272 if aTreshold == FT_LogicalNOT:
273 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
274 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
275 aCriterion.BinaryOp = aTreshold
279 aTreshold = float(aTreshold)
280 aCriterion.Threshold = aTreshold
282 print "Error: Treshold should be a number."
285 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
286 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
288 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
289 aCriterion.BinaryOp = EnumToLong(Treshold)
291 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
292 aCriterion.BinaryOp = EnumToLong(UnaryOp)
294 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
295 aCriterion.BinaryOp = EnumToLong(BinaryOp)
299 ## Creates filter by given parameters of criterion
300 # @param elementType is the type of elements in the group
301 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
302 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
303 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
304 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
305 # @return SMESH_Filter
306 def GetFilter(elementType,
307 CritType=FT_Undefined,
310 UnaryOp=FT_Undefined):
311 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
312 aFilterMgr = smesh.CreateFilterManager()
313 aFilter = aFilterMgr.CreateFilter()
315 aCriteria.append(aCriterion)
316 aFilter.SetCriteria(aCriteria)
319 ## Creates numerical functor by its type
320 # @param theCrierion is FT_...; functor type
321 # @return SMESH_NumericalFunctor
322 def GetFunctor(theCriterion):
323 aFilterMgr = smesh.CreateFilterManager()
324 if theCriterion == FT_AspectRatio:
325 return aFilterMgr.CreateAspectRatio()
326 elif theCriterion == FT_AspectRatio3D:
327 return aFilterMgr.CreateAspectRatio3D()
328 elif theCriterion == FT_Warping:
329 return aFilterMgr.CreateWarping()
330 elif theCriterion == FT_MinimumAngle:
331 return aFilterMgr.CreateMinimumAngle()
332 elif theCriterion == FT_Taper:
333 return aFilterMgr.CreateTaper()
334 elif theCriterion == FT_Skew:
335 return aFilterMgr.CreateSkew()
336 elif theCriterion == FT_Area:
337 return aFilterMgr.CreateArea()
338 elif theCriterion == FT_Volume3D:
339 return aFilterMgr.CreateVolume3D()
340 elif theCriterion == FT_MultiConnection:
341 return aFilterMgr.CreateMultiConnection()
342 elif theCriterion == FT_MultiConnection2D:
343 return aFilterMgr.CreateMultiConnection2D()
344 elif theCriterion == FT_Length:
345 return aFilterMgr.CreateLength()
346 elif theCriterion == FT_Length2D:
347 return aFilterMgr.CreateLength2D()
349 print "Error: given parameter is not numerucal functor type."
354 ## Mother class to define algorithm, recommended to don't use directly.
357 class Mesh_Algorithm:
358 # @class Mesh_Algorithm
359 # @brief Class Mesh_Algorithm
366 ## If the algorithm is global, return 0; \n
367 # else return the submesh associated to this algorithm.
368 def GetSubMesh(self):
371 ## Return the wrapped mesher.
372 def GetAlgorithm(self):
375 ## Get list of hypothesis that can be used with this algorithm
376 def GetCompatibleHypothesis(self):
379 list = self.algo.GetCompatibleHypothesis()
387 def SetName(self, name):
388 SetName(self.algo, name)
392 return self.algo.GetId()
394 ## Private method. Print error message if a hypothesis was not assigned.
395 def TreatHypoStatus(self, status, hypName, geomName, isAlgo):
397 hypType = "algorithm"
399 hypType = "hypothesis"
400 if status == HYP_UNKNOWN_FATAL :
401 reason = "for unknown reason"
402 elif status == HYP_INCOMPATIBLE :
403 reason = "this hypothesis mismatches algorithm"
404 elif status == HYP_NOTCONFORM :
405 reason = "not conform mesh would be built"
406 elif status == HYP_ALREADY_EXIST :
407 reason = hypType + " of the same dimension already assigned to this shape"
408 elif status == HYP_BAD_DIM :
409 reason = hypType + " mismatches shape"
410 elif status == HYP_CONCURENT :
411 reason = "there are concurrent hypotheses on sub-shapes"
412 elif status == HYP_BAD_SUBSHAPE :
413 reason = "shape is neither the main one, nor its subshape, nor a valid group"
414 elif status == HYP_BAD_GEOMETRY:
415 reason = "geometry mismatches algorithm's expectation"
418 hypName = '"' + hypName + '"'
419 geomName= '"' + geomName+ '"'
420 if status < HYP_UNKNOWN_FATAL:
421 print hypName, "was assigned to", geomName,"but", reason
423 print hypName, "was not assigned to",geomName,":", reason
427 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
429 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
434 name = GetName(piece)
439 name = geompy.SubShapeName(geom, piece)
440 geompy.addToStudyInFather(piece, geom, name)
441 self.subm = mesh.mesh.GetSubMesh(geom, hypo)
443 self.algo = smesh.CreateHypothesis(hypo, so)
444 SetName(self.algo, name + "/" + hypo)
445 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
446 self.TreatHypoStatus( status, hypo, name, 1 )
449 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
450 hypo = smesh.CreateHypothesis(hyp, so)
456 a = a + s + str(args[i])
459 name = GetName(self.geom)
460 SetName(hypo, name + "/" + hyp + a)
461 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
462 self.TreatHypoStatus( status, hyp, name, 0 )
466 # Public class: Mesh_Segment
467 # --------------------------
469 ## Class to define a segment 1D algorithm for discretization
472 class Mesh_Segment(Mesh_Algorithm):
474 ## Private constructor.
475 def __init__(self, mesh, geom=0):
476 self.Create(mesh, geom, "Regular_1D")
478 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
479 # @param l for the length of segments that cut an edge
480 def LocalLength(self, l):
481 hyp = self.Hypothesis("LocalLength", [l])
485 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
486 # @param n for the number of segments that cut an edge
487 # @param s for the scale factor (optional)
488 def NumberOfSegments(self, n, s=[]):
490 hyp = self.Hypothesis("NumberOfSegments", [n])
492 hyp = self.Hypothesis("NumberOfSegments", [n,s])
493 hyp.SetDistrType( 1 )
494 hyp.SetScaleFactor(s)
495 hyp.SetNumberOfSegments(n)
498 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
499 # @param start for the length of the first segment
500 # @param end for the length of the last segment
501 def Arithmetic1D(self, start, end):
502 hyp = self.Hypothesis("Arithmetic1D", [start, end])
503 hyp.SetLength(start, 1)
504 hyp.SetLength(end , 0)
507 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
508 # @param start for the length of the first segment
509 # @param end for the length of the last segment
510 def StartEndLength(self, start, end):
511 hyp = self.Hypothesis("StartEndLength", [start, end])
512 hyp.SetLength(start, 1)
513 hyp.SetLength(end , 0)
516 ## Define "Deflection1D" hypothesis
517 # @param d for the deflection
518 def Deflection1D(self, d):
519 hyp = self.Hypothesis("Deflection1D", [d])
523 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
524 # the opposite side in the case of quadrangular faces
525 def Propagation(self):
526 return self.Hypothesis("Propagation")
528 ## Define "AutomaticLength" hypothesis
529 # @param fineness for the fineness [0-1]
530 def AutomaticLength(self, fineness=0):
531 hyp = self.Hypothesis("AutomaticLength")
532 hyp.SetFineness( fineness )
535 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
536 # If the 2D mesher sees that all boundary edges are quadratic ones,
537 # it generates quadratic faces, else it generates linear faces using
538 # medium nodes as if they were vertex ones.
539 # The 3D mesher generates quadratic volumes only if all boundary faces
540 # are quadratic ones, else it fails.
541 def QuadraticMesh(self):
542 hyp = self.Hypothesis("QuadraticMesh")
545 # Public class: Mesh_Segment_Python
546 # ---------------------------------
548 ## Class to define a segment 1D algorithm for discretization with python function
551 class Mesh_Segment_Python(Mesh_Segment):
553 ## Private constructor.
554 def __init__(self, mesh, geom=0):
555 import Python1dPlugin
556 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
558 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
559 # @param n for the number of segments that cut an edge
560 # @param func for the python function that calculate the length of all segments
561 def PythonSplit1D(self, n, func):
562 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
563 hyp.SetNumberOfSegments(n)
564 hyp.SetPythonLog10RatioFunction(func)
567 # Public class: Mesh_Triangle
568 # ---------------------------
570 ## Class to define a triangle 2D algorithm
573 class Mesh_Triangle(Mesh_Algorithm):
578 ## Private constructor.
579 def __init__(self, mesh, algoType, geom=0):
580 if algoType == MEFISTO:
581 self.Create(mesh, geom, "MEFISTO_2D")
582 elif algoType == NETGEN:
584 print "Warning: NETGENPlugin module has not been imported."
585 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
586 self.algoType = algoType
588 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
589 # @param area for the maximum area of each triangles
590 def MaxElementArea(self, area):
591 if self.algoType == MEFISTO:
592 hyp = self.Hypothesis("MaxElementArea", [area])
593 hyp.SetMaxElementArea(area)
595 elif self.algoType == NETGEN:
596 print "Netgen 1D-2D algo doesn't support this hypothesis"
599 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
600 def LengthFromEdges(self):
601 if self.algoType == MEFISTO:
602 hyp = self.Hypothesis("LengthFromEdges")
604 elif self.algoType == NETGEN:
605 print "Netgen 1D-2D algo doesn't support this hypothesis"
608 ## Define "Netgen 2D Parameters" hypothesis
609 def Parameters(self):
610 if self.algoType == NETGEN:
611 self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
613 elif self.algoType == MEFISTO:
614 print "Mefisto algo doesn't support this hypothesis"
618 def SetMaxSize(self, theSize):
621 self.params.SetMaxSize(theSize)
623 ## Set SecondOrder flag
624 def SetSecondOrder(seld, theVal):
627 self.params.SetSecondOrder(theVal)
630 def SetOptimize(self, theVal):
633 self.params.SetOptimize(theVal)
636 # @param theFineness is:
637 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
638 def SetFineness(self, theFineness):
641 self.params.SetFineness(theFineness)
644 def SetGrowthRate(self, theRate):
647 self.params.SetGrowthRate(theRate)
650 def SetNbSegPerEdge(self, theVal):
653 self.params.SetNbSegPerEdge(theVal)
655 ## Set NbSegPerRadius
656 def SetNbSegPerRadius(self, theVal):
659 self.params.SetNbSegPerRadius(theVal)
661 ## Set QuadAllowed flag
662 def SetQuadAllowed(self, toAllow):
665 self.params.SetQuadAllowed(toAllow)
668 # Public class: Mesh_Quadrangle
669 # -----------------------------
671 ## Class to define a quadrangle 2D algorithm
674 class Mesh_Quadrangle(Mesh_Algorithm):
676 ## Private constructor.
677 def __init__(self, mesh, geom=0):
678 self.Create(mesh, geom, "Quadrangle_2D")
680 ## Define "QuadranglePreference" hypothesis, forcing construction
681 # of quadrangles if the number of nodes on opposite edges is not the same
682 # in the case where the global number of nodes on edges is even
683 def QuadranglePreference(self):
684 hyp = self.Hypothesis("QuadranglePreference")
687 # Public class: Mesh_Tetrahedron
688 # ------------------------------
690 ## Class to define a tetrahedron 3D algorithm
693 class Mesh_Tetrahedron(Mesh_Algorithm):
698 ## Private constructor.
699 def __init__(self, mesh, algoType, geom=0):
700 if algoType == NETGEN:
701 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
702 elif algoType == GHS3D:
704 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
705 elif algoType == FULL_NETGEN:
707 print "Warning: NETGENPlugin module has not been imported."
708 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
709 self.algoType = algoType
711 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
712 # @param vol for the maximum volume of each tetrahedral
713 def MaxElementVolume(self, vol):
714 hyp = self.Hypothesis("MaxElementVolume", [vol])
715 hyp.SetMaxElementVolume(vol)
718 ## Define "Netgen 3D Parameters" hypothesis
719 def Parameters(self):
720 if (self.algoType == FULL_NETGEN):
721 self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
724 print "Algo doesn't support this hypothesis"
728 def SetMaxSize(self, theSize):
731 self.params.SetMaxSize(theSize)
733 ## Set SecondOrder flag
734 def SetSecondOrder(self, theVal):
737 self.params.SetSecondOrder(theVal)
740 def SetOptimize(self, theVal):
743 self.params.SetOptimize(theVal)
746 # @param theFineness is:
747 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
748 def SetFineness(self, theFineness):
751 self.params.SetFineness(theFineness)
754 def SetGrowthRate(self, theRate):
757 self.params.SetGrowthRate(theRate)
760 def SetNbSegPerEdge(self, theVal):
763 self.params.SetNbSegPerEdge(theVal)
765 ## Set NbSegPerRadius
766 def SetNbSegPerRadius(self, theVal):
769 self.params.SetNbSegPerRadius(theVal)
771 # Public class: Mesh_Hexahedron
772 # ------------------------------
774 ## Class to define a hexahedron 3D algorithm
777 class Mesh_Hexahedron(Mesh_Algorithm):
779 ## Private constructor.
780 def __init__(self, mesh, geom=0):
781 self.Create(mesh, geom, "Hexa_3D")
783 # Deprecated, only for compatibility!
784 # Public class: Mesh_Netgen
785 # ------------------------------
787 ## Class to define a NETGEN-based 2D or 3D algorithm
788 # that need no discrete boundary (i.e. independent)
790 # This class is deprecated, only for compatibility!
793 class Mesh_Netgen(Mesh_Algorithm):
797 ## Private constructor.
798 def __init__(self, mesh, is3D, geom=0):
800 print "Warning: NETGENPlugin module has not been imported."
804 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
806 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
808 ## Define hypothesis containing parameters of the algorithm
809 def Parameters(self):
811 hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
813 hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
816 # Public class: Mesh_Projection1D
817 # ------------------------------
819 ## Class to define a projection 1D algorithm
822 class Mesh_Projection1D(Mesh_Algorithm):
824 ## Private constructor.
825 def __init__(self, mesh, geom=0):
826 self.Create(mesh, geom, "Projection_1D")
828 ## Define "Source Edge" hypothesis, specifying a meshed edge to
829 # take a mesh pattern from, and optionally association of vertices
830 # between the source edge and a target one (where a hipothesis is assigned to)
831 # @param edge to take nodes distribution from
832 # @param mesh to take nodes distribution from (optional)
833 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
834 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
835 # to associate with \a srcV (optional)
836 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
837 hyp = self.Hypothesis("ProjectionSource1D")
838 hyp.SetSourceEdge( edge )
839 if not mesh is None and isinstance(mesh, Mesh):
840 mesh = mesh.GetMesh()
841 hyp.SetSourceMesh( mesh )
842 hyp.SetVertexAssociation( srcV, tgtV )
846 # Public class: Mesh_Projection2D
847 # ------------------------------
849 ## Class to define a projection 2D algorithm
852 class Mesh_Projection2D(Mesh_Algorithm):
854 ## Private constructor.
855 def __init__(self, mesh, geom=0):
856 self.Create(mesh, geom, "Projection_2D")
858 ## Define "Source Face" hypothesis, specifying a meshed face to
859 # take a mesh pattern from, and optionally association of vertices
860 # between the source face and a target one (where a hipothesis is assigned to)
861 # @param face to take mesh pattern from
862 # @param mesh to take mesh pattern from (optional)
863 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
864 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
865 # to associate with \a srcV1 (optional)
866 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
867 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
868 # to associate with \a srcV2 (optional)
870 # Note: association vertices must belong to one edge of a face
871 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
872 hyp = self.Hypothesis("ProjectionSource2D")
873 hyp.SetSourceFace( face )
874 if not mesh is None and isinstance(mesh, Mesh):
875 mesh = mesh.GetMesh()
876 hyp.SetSourceMesh( mesh )
877 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
880 # Public class: Mesh_Projection3D
881 # ------------------------------
883 ## Class to define a projection 3D algorithm
886 class Mesh_Projection3D(Mesh_Algorithm):
888 ## Private constructor.
889 def __init__(self, mesh, geom=0):
890 self.Create(mesh, geom, "Projection_3D")
892 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
893 # take a mesh pattern from, and optionally association of vertices
894 # between the source solid and a target one (where a hipothesis is assigned to)
895 # @param solid to take mesh pattern from
896 # @param mesh to take mesh pattern from (optional)
897 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
898 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
899 # to associate with \a srcV1 (optional)
900 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
901 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
902 # to associate with \a srcV2 (optional)
904 # Note: association vertices must belong to one edge of a solid
905 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
906 hyp = self.Hypothesis("ProjectionSource3D")
907 hyp.SetSource3DShape( solid )
908 if not mesh is None and isinstance(mesh, Mesh):
909 mesh = mesh.GetMesh()
910 hyp.SetSourceMesh( mesh )
911 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
915 # Public class: Mesh_Prism
916 # ------------------------
918 ## Class to define a Prism 3D algorithm
921 class Mesh_Prism3D(Mesh_Algorithm):
923 ## Private constructor.
924 def __init__(self, mesh, geom=0):
925 self.Create(mesh, geom, "Prism_3D")
927 # Public class: Mesh_RadialPrism
928 # -------------------------------
930 ## Class to define a Radial Prism 3D algorithm
933 class Mesh_RadialPrism3D(Mesh_Algorithm):
935 ## Private constructor.
936 def __init__(self, mesh, geom=0):
937 self.Create(mesh, geom, "RadialPrism_3D")
938 self.distribHyp = self.Hypothesis( "LayerDistribution" )
941 ## Return 3D hypothesis holding the 1D one
942 def Get3DHypothesis(self):
943 return self.distribHyp
945 ## Private method creating 1D hypothes and storing it in the LayerDistribution
946 # hypothes. Returns the created hypothes
947 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
948 if not self.nbLayers is None:
949 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
950 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
951 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
952 hyp = smesh.CreateHypothesis(hypType, so)
953 SetCurrentStudy( study ) # anable publishing
954 self.distribHyp.SetLayerDistribution( hyp )
957 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
958 # prisms to build between the inner and outer shells
959 def NumberOfLayers(self, n ):
960 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
961 self.nbLayers = self.Hypothesis("NumberOfLayers")
962 self.nbLayers.SetNumberOfLayers( n )
965 ## Define "LocalLength" hypothesis, specifying segment length
966 # to build between the inner and outer shells
967 # @param l for the length of segments
968 def LocalLength(self, l):
969 hyp = self.OwnHypothesis("LocalLength", [l])
973 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
974 # prisms to build between the inner and outer shells
975 # @param n for the number of segments
976 # @param s for the scale factor (optional)
977 def NumberOfSegments(self, n, s=[]):
979 hyp = self.OwnHypothesis("NumberOfSegments", [n])
981 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
982 hyp.SetDistrType( 1 )
983 hyp.SetScaleFactor(s)
984 hyp.SetNumberOfSegments(n)
987 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
988 # to build between the inner and outer shells as arithmetic length increasing
989 # @param start for the length of the first segment
990 # @param end for the length of the last segment
991 def Arithmetic1D(self, start, end):
992 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
993 hyp.SetLength(start, 1)
994 hyp.SetLength(end , 0)
997 ## Define "StartEndLength" hypothesis, specifying distribution of segments
998 # to build between the inner and outer shells as geometric length increasing
999 # @param start for the length of the first segment
1000 # @param end for the length of the last segment
1001 def StartEndLength(self, start, end):
1002 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1003 hyp.SetLength(start, 1)
1004 hyp.SetLength(end , 0)
1007 ## Define "AutomaticLength" hypothesis, specifying number of segments
1008 # to build between the inner and outer shells
1009 # @param fineness for the fineness [0-1]
1010 def AutomaticLength(self, fineness=0):
1011 hyp = self.OwnHypothesis("AutomaticLength")
1012 hyp.SetFineness( fineness )
1016 # Public class: Mesh
1017 # ==================
1019 ## Class to define a mesh
1021 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1031 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1032 # sets GUI name of this mesh to \a name.
1033 # @param obj Shape to be meshed or SMESH_Mesh object
1034 # @param name Study name of the mesh
1035 def __init__(self, obj=0, name=0):
1039 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1041 self.mesh = smesh.CreateMesh(self.geom)
1042 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1045 self.mesh = smesh.CreateEmptyMesh()
1047 SetName(self.mesh, name)
1049 SetName(self.mesh, GetName(obj))
1051 self.editor = self.mesh.GetMeshEditor()
1053 ## Method that inits the Mesh object from SMESH_Mesh interface
1054 # @param theMesh is SMESH_Mesh object
1055 def SetMesh(self, theMesh):
1057 self.geom = self.mesh.GetShapeToMesh()
1059 ## Method that returns the mesh
1060 # @return SMESH_Mesh object
1066 name = GetName(self.GetMesh())
1070 def SetName(self, name):
1071 SetName(self.GetMesh(), name)
1073 ## Get the subMesh object associated to a subShape. The subMesh object
1074 # gives access to nodes and elements IDs.
1075 # \n SubMesh will be used instead of SubShape in a next idl version to
1076 # adress a specific subMesh...
1077 def GetSubMesh(self, theSubObject, name):
1078 submesh = self.mesh.GetSubMesh(theSubObject, name)
1081 ## Method that returns the shape associated to the mesh
1082 # @return GEOM_Object
1086 ## Method that associates given shape to the mesh(entails the mesh recreation)
1087 # @param geom shape to be meshed(GEOM_Object)
1088 def SetShape(self, geom):
1089 self.mesh = smesh.CreateMesh(geom)
1091 ## Return true if hypotheses are defined well
1092 # @param theMesh is an instance of Mesh class
1093 # @param theSubObject subshape of a mesh shape
1094 def IsReadyToCompute(self, theSubObject):
1095 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1097 ## Return errors of hypotheses definintion
1098 # error list is empty if everything is OK
1099 # @param theMesh is an instance of Mesh class
1100 # @param theSubObject subshape of a mesh shape
1101 # @return a list of errors
1102 def GetAlgoState(self, theSubObject):
1103 return smesh.GetAlgoState(self.mesh, theSubObject)
1105 ## Return geometrical object the given element is built on.
1106 # The returned geometrical object, if not nil, is either found in the
1107 # study or is published by this method with the given name
1108 # @param theMesh is an instance of Mesh class
1109 # @param theElementID an id of the mesh element
1110 # @param theGeomName user defined name of geometrical object
1111 # @return GEOM::GEOM_Object instance
1112 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1113 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1115 ## Returns mesh dimension depending on shape one
1116 def MeshDimension(self):
1117 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1118 if len( shells ) > 0 :
1120 elif geompy.NumberOfFaces( self.geom ) > 0 :
1122 elif geompy.NumberOfEdges( self.geom ) > 0 :
1128 ## Creates a segment discretization 1D algorithm.
1129 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1130 # If the optional \a geom parameter is not sets, this algorithm is global.
1131 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1132 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1133 # @param geom If defined, subshape to be meshed
1134 def Segment(self, algo=REGULAR, geom=0):
1135 ## if Segment(geom) is called by mistake
1136 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1137 algo, geom = geom, algo
1140 return Mesh_Segment(self, geom)
1141 elif algo == PYTHON:
1142 return Mesh_Segment_Python(self, geom)
1144 return Mesh_Segment(self, geom)
1146 ## Creates a triangle 2D algorithm for faces.
1147 # If the optional \a geom parameter is not sets, this algorithm is global.
1148 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1149 # @param algo values are: smesh.MEFISTO or smesh.NETGEN
1150 # @param geom If defined, subshape to be meshed
1151 def Triangle(self, algo=MEFISTO, geom=0):
1152 ## if Triangle(geom) is called by mistake
1153 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1157 return Mesh_Triangle(self, algo, geom)
1159 ## Creates a quadrangle 2D algorithm for faces.
1160 # If the optional \a geom parameter is not sets, this algorithm is global.
1161 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1162 # @param geom If defined, subshape to be meshed
1163 def Quadrangle(self, geom=0):
1164 return Mesh_Quadrangle(self, geom)
1166 ## Creates a tetrahedron 3D algorithm for solids.
1167 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1168 # If the optional \a geom parameter is not sets, this algorithm is global.
1169 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1170 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1171 # @param geom If defined, subshape to be meshed
1172 def Tetrahedron(self, algo=NETGEN, geom=0):
1173 ## if Tetrahedron(geom) is called by mistake
1174 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1175 algo, geom = geom, algo
1177 return Mesh_Tetrahedron(self, algo, geom)
1179 ## Creates a hexahedron 3D algorithm for solids.
1180 # If the optional \a geom parameter is not sets, this algorithm is global.
1181 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1182 # @param geom If defined, subshape to be meshed
1183 def Hexahedron(self, geom=0):
1184 return Mesh_Hexahedron(self, geom)
1186 ## Deprecated, only for compatibility!
1187 def Netgen(self, is3D, geom=0):
1188 return Mesh_Netgen(self, is3D, geom)
1190 ## Creates a projection 1D algorithm for edges.
1191 # If the optional \a geom parameter is not sets, this algorithm is global.
1192 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1193 # @param geom If defined, subshape to be meshed
1194 def Projection1D(self, geom=0):
1195 return Mesh_Projection1D(self, geom)
1197 ## Creates a projection 2D algorithm for faces.
1198 # If the optional \a geom parameter is not sets, this algorithm is global.
1199 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1200 # @param geom If defined, subshape to be meshed
1201 def Projection2D(self, geom=0):
1202 return Mesh_Projection2D(self, geom)
1204 ## Creates a projection 3D algorithm for solids.
1205 # If the optional \a geom parameter is not sets, this algorithm is global.
1206 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1207 # @param geom If defined, subshape to be meshed
1208 def Projection3D(self, geom=0):
1209 return Mesh_Projection3D(self, geom)
1211 ## Creates a Prism 3D or RadialPrism 3D algorithm for solids.
1212 # If the optional \a geom parameter is not sets, this algorithm is global.
1213 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1214 # @param geom If defined, subshape to be meshed
1215 def Prism(self, geom=0):
1219 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1220 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1221 if nbSolids == 0 or nbSolids == nbShells:
1222 return Mesh_Prism3D(self, geom)
1223 return Mesh_RadialPrism3D(self, geom)
1225 ## Compute the mesh and return the status of the computation
1226 def Compute(self, geom=0):
1227 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1229 print "Compute impossible: mesh is not constructed on geom shape."
1233 ok = smesh.Compute(self.mesh, geom)
1235 errors = smesh.GetAlgoState( self.mesh, geom )
1238 if err.isGlobalAlgo:
1243 dim = str(err.algoDim)
1244 if err.name == MISSING_ALGO:
1245 reason = glob + dim + "D algorithm is missing"
1246 elif err.name == MISSING_HYPO:
1247 name = '"' + err.algoName + '"'
1248 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1249 elif err.name == NOT_CONFORM_MESH:
1250 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1251 elif err.name == BAD_PARAM_VALUE:
1252 name = '"' + err.algoName + '"'
1253 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1254 " has a bad parameter value"
1256 reason = "For unknown reason."+\
1257 " Revise Mesh.Compute() implementation in smesh.py!"
1259 if allReasons != "":
1262 allReasons += reason
1264 if allReasons != "":
1265 print '"' + GetName(self.mesh) + '"',"not computed:"
1269 if salome.sg.hasDesktop():
1270 smeshgui = salome.ImportComponentGUI("SMESH")
1271 smeshgui.Init(salome.myStudyId)
1272 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok )
1273 salome.sg.updateObjBrowser(1)
1277 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1278 # The parameter \a fineness [0,-1] defines mesh fineness
1279 def AutomaticTetrahedralization(self, fineness=0):
1280 dim = self.MeshDimension()
1282 self.RemoveGlobalHypotheses()
1283 self.Segment().AutomaticLength(fineness)
1285 self.Triangle().LengthFromEdges()
1288 self.Tetrahedron(NETGEN)
1290 return self.Compute()
1292 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1293 # The parameter \a fineness [0,-1] defines mesh fineness
1294 def AutomaticHexahedralization(self, fineness=0):
1295 dim = self.MeshDimension()
1297 self.RemoveGlobalHypotheses()
1298 self.Segment().AutomaticLength(fineness)
1305 return self.Compute()
1307 ## Get the list of hypothesis added on a geom
1308 # @param geom is subhape of mesh geometry
1309 def GetHypothesisList(self, geom):
1310 return self.mesh.GetHypothesisList( geom )
1312 ## Removes all global hypotheses
1313 def RemoveGlobalHypotheses(self):
1314 current_hyps = self.mesh.GetHypothesisList( self.geom )
1315 for hyp in current_hyps:
1316 self.mesh.RemoveHypothesis( self.geom, hyp )
1320 ## Create a mesh group based on geometric object \a grp
1321 # and give a \a name, \n if this parameter is not defined
1322 # the name is the same as the geometric group name \n
1323 # Note: Works like GroupOnGeom().
1324 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1325 # @param name is the name of the mesh group
1326 # @return SMESH_GroupOnGeom
1327 def Group(self, grp, name=""):
1328 return self.GroupOnGeom(grp, name)
1330 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1331 # Export the mesh in a file with the MED format and choice the \a version of MED format
1332 # @param f is the file name
1333 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1334 def ExportToMED(self, f, version, opt=0):
1335 self.mesh.ExportToMED(f, opt, version)
1337 ## Export the mesh in a file with the MED format
1338 # @param f is the file name
1339 # @param auto_groups boolean parameter for creating/not creating
1340 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1341 # the typical use is auto_groups=false.
1342 # @param version MED format version(MED_V2_1 or MED_V2_2)
1343 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1344 self.mesh.ExportToMED(f, auto_groups, version)
1346 ## Export the mesh in a file with the DAT format
1347 # @param f is the file name
1348 def ExportDAT(self, f):
1349 self.mesh.ExportDAT(f)
1351 ## Export the mesh in a file with the UNV format
1352 # @param f is the file name
1353 def ExportUNV(self, f):
1354 self.mesh.ExportUNV(f)
1356 ## Export the mesh in a file with the STL format
1357 # @param f is the file name
1358 # @param ascii defined the kind of file contents
1359 def ExportSTL(self, f, ascii=1):
1360 self.mesh.ExportSTL(f, ascii)
1363 # Operations with groups:
1364 # ----------------------
1366 ## Creates an empty mesh group
1367 # @param elementType is the type of elements in the group
1368 # @param name is the name of the mesh group
1369 # @return SMESH_Group
1370 def CreateEmptyGroup(self, elementType, name):
1371 return self.mesh.CreateGroup(elementType, name)
1373 ## Creates a mesh group based on geometric object \a grp
1374 # and give a \a name, \n if this parameter is not defined
1375 # the name is the same as the geometric group name
1376 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1377 # @param name is the name of the mesh group
1378 # @return SMESH_GroupOnGeom
1379 def GroupOnGeom(self, grp, name="", type=None):
1381 name = grp.GetName()
1384 tgeo = str(grp.GetShapeType())
1385 if tgeo == "VERTEX":
1387 elif tgeo == "EDGE":
1389 elif tgeo == "FACE":
1391 elif tgeo == "SOLID":
1393 elif tgeo == "SHELL":
1395 elif tgeo == "COMPOUND":
1396 if len( geompy.GetObjectIDs( grp )) == 0:
1397 print "Mesh.Group: empty geometric group", GetName( grp )
1399 tgeo = geompy.GetType(grp)
1400 if tgeo == geompy.ShapeType["VERTEX"]:
1402 elif tgeo == geompy.ShapeType["EDGE"]:
1404 elif tgeo == geompy.ShapeType["FACE"]:
1406 elif tgeo == geompy.ShapeType["SOLID"]:
1410 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1413 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1415 ## Create a mesh group by the given ids of elements
1416 # @param groupName is the name of the mesh group
1417 # @param elementType is the type of elements in the group
1418 # @param elemIDs is the list of ids
1419 # @return SMESH_Group
1420 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1421 group = self.mesh.CreateGroup(elementType, groupName)
1425 ## Create a mesh group by the given conditions
1426 # @param groupName is the name of the mesh group
1427 # @param elementType is the type of elements in the group
1428 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1429 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1430 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1431 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1432 # @return SMESH_Group
1436 CritType=FT_Undefined,
1439 UnaryOp=FT_Undefined):
1440 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1441 group = self.MakeGroupByCriterion(groupName, aCriterion)
1444 ## Create a mesh group by the given criterion
1445 # @param groupName is the name of the mesh group
1446 # @param Criterion is the instance of Criterion class
1447 # @return SMESH_Group
1448 def MakeGroupByCriterion(self, groupName, Criterion):
1449 aFilterMgr = smesh.CreateFilterManager()
1450 aFilter = aFilterMgr.CreateFilter()
1452 aCriteria.append(Criterion)
1453 aFilter.SetCriteria(aCriteria)
1454 group = self.MakeGroupByFilter(groupName, aFilter)
1457 ## Create a mesh group by the given criteria(list of criterions)
1458 # @param groupName is the name of the mesh group
1459 # @param Criteria is the list of criterions
1460 # @return SMESH_Group
1461 def MakeGroupByCriteria(self, groupName, theCriteria):
1462 aFilterMgr = smesh.CreateFilterManager()
1463 aFilter = aFilterMgr.CreateFilter()
1464 aFilter.SetCriteria(theCriteria)
1465 group = self.MakeGroupByFilter(groupName, aFilter)
1468 ## Create a mesh group by the given filter
1469 # @param groupName is the name of the mesh group
1470 # @param Criterion is the instance of Filter class
1471 # @return SMESH_Group
1472 def MakeGroupByFilter(self, groupName, theFilter):
1473 anIds = theFilter.GetElementsId(self.mesh)
1474 anElemType = theFilter.GetElementType()
1475 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1478 ## Pass mesh elements through the given filter and return ids
1479 # @param theFilter is SMESH_Filter
1480 # @return list of ids
1481 def GetIdsFromFilter(self, theFilter):
1482 return theFilter.GetElementsId(self.mesh)
1484 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1485 # Returns list of special structures(borders).
1486 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1487 def GetFreeBorders(self):
1488 aFilterMgr = smesh.CreateFilterManager()
1489 aPredicate = aFilterMgr.CreateFreeEdges()
1490 aPredicate.SetMesh(self.mesh)
1491 aBorders = aPredicate.GetBorders()
1495 def RemoveGroup(self, group):
1496 self.mesh.RemoveGroup(group)
1498 ## Remove group with its contents
1499 def RemoveGroupWithContents(self, group):
1500 self.mesh.RemoveGroupWithContents(group)
1502 ## Get the list of groups existing in the mesh
1503 def GetGroups(self):
1504 return self.mesh.GetGroups()
1506 ## Get the list of names of groups existing in the mesh
1507 def GetGroupNames(self):
1508 groups = self.GetGroups()
1510 for group in groups:
1511 names.append(group.GetName())
1514 ## Union of two groups
1515 # New group is created. All mesh elements that are
1516 # present in initial groups are added to the new one
1517 def UnionGroups(self, group1, group2, name):
1518 return self.mesh.UnionGroups(group1, group2, name)
1520 ## Intersection of two groups
1521 # New group is created. All mesh elements that are
1522 # present in both initial groups are added to the new one.
1523 def IntersectGroups(self, group1, group2, name):
1524 return self.mesh.IntersectGroups(group1, group2, name)
1526 ## Cut of two groups
1527 # New group is created. All mesh elements that are present in
1528 # main group but do not present in tool group are added to the new one
1529 def CutGroups(self, mainGroup, toolGroup, name):
1530 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1533 # Get some info about mesh:
1534 # ------------------------
1536 ## Get the log of nodes and elements added or removed since previous
1538 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1539 # @return list of log_block structures:
1544 def GetLog(self, clearAfterGet):
1545 return self.mesh.GetLog(clearAfterGet)
1547 ## Clear the log of nodes and elements added or removed since previous
1548 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1550 self.mesh.ClearLog()
1552 ## Get the internal Id
1554 return self.mesh.GetId()
1557 def GetStudyId(self):
1558 return self.mesh.GetStudyId()
1560 ## Check group names for duplications.
1561 # Consider maximum group name length stored in MED file.
1562 def HasDuplicatedGroupNamesMED(self):
1563 return self.mesh.GetStudyId()
1565 ## Obtain instance of SMESH_MeshEditor
1566 def GetMeshEditor(self):
1567 return self.mesh.GetMeshEditor()
1570 def GetMEDMesh(self):
1571 return self.mesh.GetMEDMesh()
1574 # Get informations about mesh contents:
1575 # ------------------------------------
1577 ## Returns number of nodes in mesh
1579 return self.mesh.NbNodes()
1581 ## Returns number of elements in mesh
1582 def NbElements(self):
1583 return self.mesh.NbElements()
1585 ## Returns number of edges in mesh
1587 return self.mesh.NbEdges()
1589 ## Returns number of edges with given order in mesh
1590 # @param elementOrder is order of elements:
1591 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1592 def NbEdgesOfOrder(self, elementOrder):
1593 return self.mesh.NbEdgesOfOrder(elementOrder)
1595 ## Returns number of faces in mesh
1597 return self.mesh.NbFaces()
1599 ## Returns number of faces with given order in mesh
1600 # @param elementOrder is order of elements:
1601 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1602 def NbFacesOfOrder(self, elementOrder):
1603 return self.mesh.NbFacesOfOrder(elementOrder)
1605 ## Returns number of triangles in mesh
1606 def NbTriangles(self):
1607 return self.mesh.NbTriangles()
1609 ## Returns number of triangles with given order in mesh
1610 # @param elementOrder is order of elements:
1611 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1612 def NbTrianglesOfOrder(self, elementOrder):
1613 return self.mesh.NbTrianglesOfOrder(elementOrder)
1615 ## Returns number of quadrangles in mesh
1616 def NbQuadrangles(self):
1617 return self.mesh.NbQuadrangles()
1619 ## Returns number of quadrangles with given order in mesh
1620 # @param elementOrder is order of elements:
1621 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1622 def NbQuadranglesOfOrder(self, elementOrder):
1623 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1625 ## Returns number of polygons in mesh
1626 def NbPolygons(self):
1627 return self.mesh.NbPolygons()
1629 ## Returns number of volumes in mesh
1630 def NbVolumes(self):
1631 return self.mesh.NbVolumes()
1633 ## Returns number of volumes with given order in mesh
1634 # @param elementOrder is order of elements:
1635 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1636 def NbVolumesOfOrder(self, elementOrder):
1637 return self.mesh.NbVolumesOfOrder(elementOrder)
1639 ## Returns number of tetrahedrons in mesh
1641 return self.mesh.NbTetras()
1643 ## Returns number of tetrahedrons with given order in mesh
1644 # @param elementOrder is order of elements:
1645 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1646 def NbTetrasOfOrder(self, elementOrder):
1647 return self.mesh.NbTetrasOfOrder(elementOrder)
1649 ## Returns number of hexahedrons in mesh
1651 return self.mesh.NbHexas()
1653 ## Returns number of hexahedrons with given order in mesh
1654 # @param elementOrder is order of elements:
1655 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1656 def NbHexasOfOrder(self, elementOrder):
1657 return self.mesh.NbHexasOfOrder(elementOrder)
1659 ## Returns number of pyramids in mesh
1660 def NbPyramids(self):
1661 return self.mesh.NbPyramids()
1663 ## Returns number of pyramids with given order in mesh
1664 # @param elementOrder is order of elements:
1665 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1666 def NbPyramidsOfOrder(self, elementOrder):
1667 return self.mesh.NbPyramidsOfOrder(elementOrder)
1669 ## Returns number of prisms in mesh
1671 return self.mesh.NbPrisms()
1673 ## Returns number of prisms with given order in mesh
1674 # @param elementOrder is order of elements:
1675 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1676 def NbPrismsOfOrder(self, elementOrder):
1677 return self.mesh.NbPrismsOfOrder(elementOrder)
1679 ## Returns number of polyhedrons in mesh
1680 def NbPolyhedrons(self):
1681 return self.mesh.NbPolyhedrons()
1683 ## Returns number of submeshes in mesh
1684 def NbSubMesh(self):
1685 return self.mesh.NbSubMesh()
1687 ## Returns list of mesh elements ids
1688 def GetElementsId(self):
1689 return self.mesh.GetElementsId()
1691 ## Returns list of ids of mesh elements with given type
1692 # @param elementType is required type of elements
1693 def GetElementsByType(self, elementType):
1694 return self.mesh.GetElementsByType(elementType)
1696 ## Returns list of mesh nodes ids
1697 def GetNodesId(self):
1698 return self.mesh.GetNodesId()
1700 # Get informations about mesh elements:
1701 # ------------------------------------
1703 ## Returns type of mesh element
1704 def GetElementType(self, id, iselem):
1705 return self.mesh.GetElementType(id, iselem)
1707 ## Returns list of submesh elements ids
1708 # @param shapeID is geom object(subshape) IOR
1709 def GetSubMeshElementsId(self, shapeID):
1710 return self.mesh.GetSubMeshElementsId(shapeID)
1712 ## Returns list of submesh nodes ids
1713 # @param shapeID is geom object(subshape) IOR
1714 def GetSubMeshNodesId(self, shapeID, all):
1715 return self.mesh.GetSubMeshNodesId(shapeID, all)
1717 ## Returns list of ids of submesh elements with given type
1718 # @param shapeID is geom object(subshape) IOR
1719 def GetSubMeshElementType(self, shapeID):
1720 return self.mesh.GetSubMeshElementType(shapeID)
1722 ## Get mesh description
1724 return self.mesh.Dump()
1727 # Get information about nodes and elements of mesh by its ids:
1728 # -----------------------------------------------------------
1730 ## Get XYZ coordinates of node as list of double
1731 # \n If there is not node for given ID - returns empty list
1732 def GetNodeXYZ(self, id):
1733 return self.mesh.GetNodeXYZ(id)
1735 ## For given node returns list of IDs of inverse elements
1736 # \n If there is not node for given ID - returns empty list
1737 def GetNodeInverseElements(self, id):
1738 return self.mesh.GetNodeInverseElements(id)
1740 ## If given element is node returns IDs of shape from position
1741 # \n If there is not node for given ID - returns -1
1742 def GetShapeID(self, id):
1743 return self.mesh.GetShapeID(id)
1745 ## For given element returns ID of result shape after
1746 # FindShape() from SMESH_MeshEditor
1747 # \n If there is not element for given ID - returns -1
1748 def GetShapeIDForElem(id):
1749 return self.mesh.GetShapeIDForElem(id)
1751 ## Returns number of nodes for given element
1752 # \n If there is not element for given ID - returns -1
1753 def GetElemNbNodes(self, id):
1754 return self.mesh.GetElemNbNodes(id)
1756 ## Returns ID of node by given index for given element
1757 # \n If there is not element for given ID - returns -1
1758 # \n If there is not node for given index - returns -2
1759 def GetElemNode(self, id, index):
1760 return self.mesh.GetElemNode(id, index)
1762 ## Returns true if given node is medium node
1763 # in given quadratic element
1764 def IsMediumNode(self, elementID, nodeID):
1765 return self.mesh.IsMediumNode(elementID, nodeID)
1767 ## Returns true if given node is medium node
1768 # in one of quadratic elements
1769 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1770 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1772 ## Returns number of edges for given element
1773 def ElemNbEdges(self, id):
1774 return self.mesh.ElemNbEdges(id)
1776 ## Returns number of faces for given element
1777 def ElemNbFaces(self, id):
1778 return self.mesh.ElemNbFaces(id)
1780 ## Returns true if given element is polygon
1781 def IsPoly(self, id):
1782 return self.mesh.IsPoly(id)
1784 ## Returns true if given element is quadratic
1785 def IsQuadratic(self, id):
1786 return self.mesh.IsQuadratic(id)
1788 ## Returns XYZ coordinates of bary center for given element
1790 # \n If there is not element for given ID - returns empty list
1791 def BaryCenter(self, id):
1792 return self.mesh.BaryCenter(id)
1795 # Mesh edition (SMESH_MeshEditor functionality):
1796 # ---------------------------------------------
1798 ## Removes elements from mesh by ids
1799 # @param IDsOfElements is list of ids of elements to remove
1800 def RemoveElements(self, IDsOfElements):
1801 return self.editor.RemoveElements(IDsOfElements)
1803 ## Removes nodes from mesh by ids
1804 # @param IDsOfNodes is list of ids of nodes to remove
1805 def RemoveNodes(self, IDsOfNodes):
1806 return self.editor.RemoveNodes(IDsOfNodes)
1808 ## Add node to mesh by coordinates
1809 def AddNode(self, x, y, z):
1810 return self.editor.AddNode( x, y, z)
1813 ## Create edge both similar and quadratic (this is determed
1814 # by number of given nodes).
1815 # @param IdsOfNodes List of node IDs for creation of element.
1816 # Needed order of nodes in this list corresponds to description
1817 # of MED. \n This description is located by the following link:
1818 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1819 def AddEdge(self, IDsOfNodes):
1820 return self.editor.AddEdge(IDsOfNodes)
1822 ## Create face both similar and quadratic (this is determed
1823 # by number of given nodes).
1824 # @param IdsOfNodes List of node IDs for creation of element.
1825 # Needed order of nodes in this list corresponds to description
1826 # of MED. \n This description is located by the following link:
1827 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1828 def AddFace(self, IDsOfNodes):
1829 return self.editor.AddFace(IDsOfNodes)
1831 ## Add polygonal face to mesh by list of nodes ids
1832 def AddPolygonalFace(self, IdsOfNodes):
1833 return self.editor.AddPolygonalFace(IdsOfNodes)
1835 ## Create volume both similar and quadratic (this is determed
1836 # by number of given nodes).
1837 # @param IdsOfNodes List of node IDs for creation of element.
1838 # Needed order of nodes in this list corresponds to description
1839 # of MED. \n This description is located by the following link:
1840 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1841 def AddVolume(self, IDsOfNodes):
1842 return self.editor.AddVolume(IDsOfNodes)
1844 ## Create volume of many faces, giving nodes for each face.
1845 # @param IdsOfNodes List of node IDs for volume creation face by face.
1846 # @param Quantities List of integer values, Quantities[i]
1847 # gives quantity of nodes in face number i.
1848 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1849 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1851 ## Create volume of many faces, giving IDs of existing faces.
1852 # @param IdsOfFaces List of face IDs for volume creation.
1854 # Note: The created volume will refer only to nodes
1855 # of the given faces, not to the faces itself.
1856 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1857 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1859 ## Move node with given id
1860 # @param NodeID id of the node
1861 # @param x displacing along the X axis
1862 # @param y displacing along the Y axis
1863 # @param z displacing along the Z axis
1864 def MoveNode(self, NodeID, x, y, z):
1865 return self.editor.MoveNode(NodeID, x, y, z)
1867 ## Replace two neighbour triangles sharing Node1-Node2 link
1868 # with ones built on the same 4 nodes but having other common link.
1869 # @param NodeID1 first node id
1870 # @param NodeID2 second node id
1871 # @return false if proper faces not found
1872 def InverseDiag(self, NodeID1, NodeID2):
1873 return self.editor.InverseDiag(NodeID1, NodeID2)
1875 ## Replace two neighbour triangles sharing Node1-Node2 link
1876 # with a quadrangle built on the same 4 nodes.
1877 # @param NodeID1 first node id
1878 # @param NodeID2 second node id
1879 # @return false if proper faces not found
1880 def DeleteDiag(self, NodeID1, NodeID2):
1881 return self.editor.DeleteDiag(NodeID1, NodeID2)
1883 ## Reorient elements by ids
1884 # @param IDsOfElements if undefined reorient all mesh elements
1885 def Reorient(self, IDsOfElements=None):
1886 if IDsOfElements == None:
1887 IDsOfElements = self.GetElementsId()
1888 return self.editor.Reorient(IDsOfElements)
1890 ## Reorient all elements of the object
1891 # @param theObject is mesh, submesh or group
1892 def ReorientObject(self, theObject):
1893 return self.editor.ReorientObject(theObject)
1895 ## Fuse neighbour triangles into quadrangles.
1896 # @param IDsOfElements The triangles to be fused,
1897 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1898 # @param MaxAngle is a max angle between element normals at which fusion
1899 # is still performed; theMaxAngle is mesured in radians.
1900 # @return TRUE in case of success, FALSE otherwise.
1901 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1902 if IDsOfElements == []:
1903 IDsOfElements = self.GetElementsId()
1904 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1906 ## Fuse neighbour triangles of the object into quadrangles
1907 # @param theObject is mesh, submesh or group
1908 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1909 # @param MaxAngle is a max angle between element normals at which fusion
1910 # is still performed; theMaxAngle is mesured in radians.
1911 # @return TRUE in case of success, FALSE otherwise.
1912 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1913 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1915 ## Split quadrangles into triangles.
1916 # @param IDsOfElements the faces to be splitted.
1917 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1918 # @param @return TRUE in case of success, FALSE otherwise.
1919 def QuadToTri (self, IDsOfElements, theCriterion):
1920 if IDsOfElements == []:
1921 IDsOfElements = self.GetElementsId()
1922 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
1924 ## Split quadrangles into triangles.
1925 # @param theObject object to taking list of elements from, is mesh, submesh or group
1926 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1927 def QuadToTriObject (self, theObject, theCriterion):
1928 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
1930 ## Split quadrangles into triangles.
1931 # @param theElems The faces to be splitted
1932 # @param the13Diag is used to choose a diagonal for splitting.
1933 # @return TRUE in case of success, FALSE otherwise.
1934 def SplitQuad (self, IDsOfElements, Diag13):
1935 if IDsOfElements == []:
1936 IDsOfElements = self.GetElementsId()
1937 return self.editor.SplitQuad(IDsOfElements, Diag13)
1939 ## Split quadrangles into triangles.
1940 # @param theObject is object to taking list of elements from, is mesh, submesh or group
1941 def SplitQuadObject (self, theObject, Diag13):
1942 return self.editor.SplitQuadObject(theObject, Diag13)
1944 ## Find better splitting of the given quadrangle.
1945 # @param IDOfQuad ID of the quadrangle to be splitted.
1946 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
1947 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1948 # diagonal is better, 0 if error occurs.
1949 def BestSplit (self, IDOfQuad, theCriterion):
1950 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
1953 # @param IDsOfElements list if ids of elements to smooth
1954 # @param IDsOfFixedNodes list of ids of fixed nodes.
1955 # Note that nodes built on edges and boundary nodes are always fixed.
1956 # @param MaxNbOfIterations maximum number of iterations
1957 # @param MaxAspectRatio varies in range [1.0, inf]
1958 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1959 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1960 MaxNbOfIterations, MaxAspectRatio, Method):
1961 if IDsOfElements == []:
1962 IDsOfElements = self.GetElementsId()
1963 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1964 MaxNbOfIterations, MaxAspectRatio, Method)
1966 ## Smooth elements belong to given object
1967 # @param theObject object to smooth
1968 # @param IDsOfFixedNodes list of ids of fixed nodes.
1969 # Note that nodes built on edges and boundary nodes are always fixed.
1970 # @param MaxNbOfIterations maximum number of iterations
1971 # @param MaxAspectRatio varies in range [1.0, inf]
1972 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1973 def SmoothObject(self, theObject, IDsOfFixedNodes,
1974 MaxNbOfIterations, MaxxAspectRatio, Method):
1975 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1976 MaxNbOfIterations, MaxxAspectRatio, Method)
1978 ## Parametric smooth the given elements
1979 # @param IDsOfElements list if ids of elements to smooth
1980 # @param IDsOfFixedNodes list of ids of fixed nodes.
1981 # Note that nodes built on edges and boundary nodes are always fixed.
1982 # @param MaxNbOfIterations maximum number of iterations
1983 # @param MaxAspectRatio varies in range [1.0, inf]
1984 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1985 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1986 MaxNbOfIterations, MaxAspectRatio, Method):
1987 if IDsOfElements == []:
1988 IDsOfElements = self.GetElementsId()
1989 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1990 MaxNbOfIterations, MaxAspectRatio, Method)
1992 ## Parametric smooth elements belong to given object
1993 # @param theObject object to smooth
1994 # @param IDsOfFixedNodes list of ids of fixed nodes.
1995 # Note that nodes built on edges and boundary nodes are always fixed.
1996 # @param MaxNbOfIterations maximum number of iterations
1997 # @param MaxAspectRatio varies in range [1.0, inf]
1998 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1999 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2000 MaxNbOfIterations, MaxAspectRatio, Method):
2001 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2002 MaxNbOfIterations, MaxAspectRatio, Method)
2004 ## Converts all mesh to quadratic one, deletes old elements, replacing
2005 # them with quadratic ones with the same id.
2006 def ConvertToQuadratic(self, theForce3d):
2007 self.editor.ConvertToQuadratic(theForce3d)
2009 ## Converts all mesh from quadratic to ordinary ones,
2010 # deletes old quadratic elements, \n replacing
2011 # them with ordinary mesh elements with the same id.
2012 def ConvertFromQuadratic(self):
2013 return self.editor.ConvertFromQuadratic()
2015 ## Renumber mesh nodes
2016 def RenumberNodes(self):
2017 self.editor.RenumberNodes()
2019 ## Renumber mesh elements
2020 def RenumberElements(self):
2021 self.editor.RenumberElements()
2023 ## Generate new elements by rotation of the elements around the axis
2024 # @param IDsOfElements list of ids of elements to sweep
2025 # @param Axix axis of rotation, AxisStruct or line(geom object)
2026 # @param AngleInRadians angle of Rotation
2027 # @param NbOfSteps number of steps
2028 # @param Tolerance tolerance
2029 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2030 if IDsOfElements == []:
2031 IDsOfElements = self.GetElementsId()
2032 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2033 Axix = GetAxisStruct(Axix)
2034 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2036 ## Generate new elements by rotation of the elements of object around the axis
2037 # @param theObject object wich elements should be sweeped
2038 # @param Axix axis of rotation, AxisStruct or line(geom object)
2039 # @param AngleInRadians angle of Rotation
2040 # @param NbOfSteps number of steps
2041 # @param Tolerance tolerance
2042 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2043 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2044 Axix = GetAxisStruct(Axix)
2045 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2047 ## Generate new elements by extrusion of the elements with given ids
2048 # @param IDsOfElements list of elements ids for extrusion
2049 # @param StepVector vector, defining the direction and value of extrusion
2050 # @param NbOfSteps the number of steps
2051 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2052 if IDsOfElements == []:
2053 IDsOfElements = self.GetElementsId()
2054 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2055 StepVector = GetDirStruct(StepVector)
2056 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2058 ## Generate new elements by extrusion of the elements with given ids
2059 # @param IDsOfElements is ids of elements
2060 # @param StepVector vector, defining the direction and value of extrusion
2061 # @param NbOfSteps the number of steps
2062 # @param ExtrFlags set flags for performing extrusion
2063 # @param SewTolerance uses for comparing locations of nodes if flag
2064 # EXTRUSION_FLAG_SEW is set
2065 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2066 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2067 StepVector = GetDirStruct(StepVector)
2068 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2070 ## Generate new elements by extrusion of the elements belong to object
2071 # @param theObject object wich elements should be processed
2072 # @param StepVector vector, defining the direction and value of extrusion
2073 # @param NbOfSteps the number of steps
2074 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2075 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2076 StepVector = GetDirStruct(StepVector)
2077 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2079 ## Generate new elements by extrusion of the elements belong to object
2080 # @param theObject object wich elements should be processed
2081 # @param StepVector vector, defining the direction and value of extrusion
2082 # @param NbOfSteps the number of steps
2083 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2084 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2085 StepVector = GetDirStruct(StepVector)
2086 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2088 ## Generate new elements by extrusion of the elements belong to object
2089 # @param theObject object wich elements should be processed
2090 # @param StepVector vector, defining the direction and value of extrusion
2091 # @param NbOfSteps the number of steps
2092 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2093 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2094 StepVector = GetDirStruct(StepVector)
2095 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2097 ## Generate new elements by extrusion of the given elements
2098 # A path of extrusion must be a meshed edge.
2099 # @param IDsOfElements is ids of elements
2100 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2101 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2102 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2103 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2104 # @param Angles list of angles
2105 # @param HasRefPoint allows to use base point
2106 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2107 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2108 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2109 HasAngles, Angles, HasRefPoint, RefPoint):
2110 if IDsOfElements == []:
2111 IDsOfElements = self.GetElementsId()
2112 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2113 RefPoint = GetPointStruct(RefPoint)
2114 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2115 HasAngles, Angles, HasRefPoint, RefPoint)
2117 ## Generate new elements by extrusion of the elements belong to object
2118 # A path of extrusion must be a meshed edge.
2119 # @param IDsOfElements is ids of elements
2120 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2121 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2122 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2123 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2124 # @param Angles list of angles
2125 # @param HasRefPoint allows to use base point
2126 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2127 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2128 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2129 HasAngles, Angles, HasRefPoint, RefPoint):
2130 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2131 RefPoint = GetPointStruct(RefPoint)
2132 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2133 HasAngles, Angles, HasRefPoint, RefPoint)
2135 ## Symmetrical copy of mesh elements
2136 # @param IDsOfElements list of elements ids
2137 # @param Mirror is AxisStruct or geom object(point, line, plane)
2138 # @param theMirrorType is POINT, AXIS or PLANE
2139 # If the Mirror is geom object this parameter is unnecessary
2140 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2141 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2142 if IDsOfElements == []:
2143 IDsOfElements = self.GetElementsId()
2144 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2145 Mirror = GetAxisStruct(Mirror)
2146 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2148 ## Symmetrical copy of object
2149 # @param theObject mesh, submesh or group
2150 # @param Mirror is AxisStruct or geom object(point, line, plane)
2151 # @param theMirrorType is POINT, AXIS or PLANE
2152 # If the Mirror is geom object this parameter is unnecessary
2153 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2154 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2155 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2156 Mirror = GetAxisStruct(Mirror)
2157 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2159 ## Translates the elements
2160 # @param IDsOfElements list of elements ids
2161 # @param Vector direction of translation(DirStruct or vector)
2162 # @param Copy allows to copy the translated elements
2163 def Translate(self, IDsOfElements, Vector, Copy):
2164 if IDsOfElements == []:
2165 IDsOfElements = self.GetElementsId()
2166 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2167 Vector = GetDirStruct(Vector)
2168 self.editor.Translate(IDsOfElements, Vector, Copy)
2170 ## Translates the object
2171 # @param theObject object to translate(mesh, submesh, or group)
2172 # @param Vector direction of translation(DirStruct or geom vector)
2173 # @param Copy allows to copy the translated elements
2174 def TranslateObject(self, theObject, Vector, Copy):
2175 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2176 Vector = GetDirStruct(Vector)
2177 self.editor.TranslateObject(theObject, Vector, Copy)
2179 ## Rotates the elements
2180 # @param IDsOfElements list of elements ids
2181 # @param Axis axis of rotation(AxisStruct or geom line)
2182 # @param AngleInRadians angle of rotation(in radians)
2183 # @param Copy allows to copy the rotated elements
2184 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2185 if IDsOfElements == []:
2186 IDsOfElements = self.GetElementsId()
2187 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2188 Axis = GetAxisStruct(Axis)
2189 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2191 ## Rotates the object
2192 # @param theObject object to rotate(mesh, submesh, or group)
2193 # @param Axis axis of rotation(AxisStruct or geom line)
2194 # @param AngleInRadians angle of rotation(in radians)
2195 # @param Copy allows to copy the rotated elements
2196 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2197 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2199 ## Find group of nodes close to each other within Tolerance.
2200 # @param Tolerance tolerance value
2201 # @param list of group of nodes
2202 def FindCoincidentNodes (self, Tolerance):
2203 return self.editor.FindCoincidentNodes(Tolerance)
2206 # @param list of group of nodes
2207 def MergeNodes (self, GroupsOfNodes):
2208 self.editor.MergeNodes(GroupsOfNodes)
2210 ## Remove all but one of elements built on the same nodes.
2211 def MergeEqualElements(self):
2212 self.editor.MergeEqualElements()
2215 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2216 FirstNodeID2, SecondNodeID2, LastNodeID2,
2217 CreatePolygons, CreatePolyedrs):
2218 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2219 FirstNodeID2, SecondNodeID2, LastNodeID2,
2220 CreatePolygons, CreatePolyedrs)
2222 ## Sew conform free borders
2223 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2224 FirstNodeID2, SecondNodeID2):
2225 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2226 FirstNodeID2, SecondNodeID2)
2228 ## Sew border to side
2229 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2230 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2231 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2232 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2234 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2235 # merged with nodes of elements of Side2.
2236 # Number of elements in theSide1 and in theSide2 must be
2237 # equal and they should have similar node connectivity.
2238 # The nodes to merge should belong to sides borders and
2239 # the first node should be linked to the second.
2240 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2241 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2242 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2243 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2244 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2245 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2247 ## Set new nodes for given element.
2248 # @param ide the element id
2249 # @param newIDs nodes ids
2250 # @return If number of nodes is not corresponded to type of element - returns false
2251 def ChangeElemNodes(self, ide, newIDs):
2252 return self.editor.ChangeElemNodes(ide, newIDs)
2254 ## If during last operation of MeshEditor some nodes were
2255 # created this method returns list of it's IDs, \n
2256 # if new nodes not created - returns empty list
2257 def GetLastCreatedNodes(self):
2258 return self.editor.GetLastCreatedNodes()
2260 ## If during last operation of MeshEditor some elements were
2261 # created this method returns list of it's IDs, \n
2262 # if new elements not creared - returns empty list
2263 def GetLastCreatedElems(self):
2264 return self.editor.GetLastCreatedElems()