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)
245 aCriterion.Compare = EnumToLong(FT_EqualTo)
248 if CritType in [FT_BelongToGeom, FT_BelongToPlane,
249 FT_BelongToCylinder, FT_LyingOnGeom]:
251 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
252 aCriterion.ThresholdStr = GetName(aTreshold)
253 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
255 print "Error: Treshold should be a shape."
257 elif CritType == FT_RangeOfIds:
259 if isinstance(aTreshold, str):
260 aCriterion.ThresholdStr = aTreshold
262 print "Error: Treshold should be a string."
264 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
265 # Here we don't need treshold
266 if aTreshold == FT_LogicalNOT:
267 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
268 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
269 aCriterion.BinaryOp = aTreshold
273 aTreshold = float(aTreshold)
274 aCriterion.Threshold = aTreshold
276 print "Error: Treshold should be a number."
279 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
280 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
282 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
283 aCriterion.BinaryOp = EnumToLong(Treshold)
285 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
286 aCriterion.BinaryOp = EnumToLong(UnaryOp)
288 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
289 aCriterion.BinaryOp = EnumToLong(BinaryOp)
293 ## Creates filter by given parameters of criterion
294 # @param elementType is the type of elements in the group
295 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
296 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
297 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
298 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
299 # @return SMESH_Filter
300 def GetFilter(elementType,
301 CritType=FT_Undefined,
304 UnaryOp=FT_Undefined):
305 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
306 aFilterMgr = smesh.CreateFilterManager()
307 aFilter = aFilterMgr.CreateFilter()
309 aCriteria.append(aCriterion)
310 aFilter.SetCriteria(aCriteria)
313 ## Creates numerical functor by its type
314 # @param theCrierion is FT_...; functor type
315 # @return SMESH_NumericalFunctor
316 def GetFunctor(theCriterion):
317 aFilterMgr = smesh.CreateFilterManager()
318 if theCriterion == FT_AspectRatio:
319 return aFilterMgr.CreateAspectRatio()
320 elif theCriterion == FT_AspectRatio3D:
321 return aFilterMgr.CreateAspectRatio3D()
322 elif theCriterion == FT_Warping:
323 return aFilterMgr.CreateWarping()
324 elif theCriterion == FT_MinimumAngle:
325 return aFilterMgr.CreateMinimumAngle()
326 elif theCriterion == FT_Taper:
327 return aFilterMgr.CreateTaper()
328 elif theCriterion == FT_Skew:
329 return aFilterMgr.CreateSkew()
330 elif theCriterion == FT_Area:
331 return aFilterMgr.CreateArea()
332 elif theCriterion == FT_Volume3D:
333 return aFilterMgr.CreateVolume3D()
334 elif theCriterion == FT_MultiConnection:
335 return aFilterMgr.CreateMultiConnection()
336 elif theCriterion == FT_MultiConnection2D:
337 return aFilterMgr.CreateMultiConnection2D()
338 elif theCriterion == FT_Length:
339 return aFilterMgr.CreateLength()
340 elif theCriterion == FT_Length2D:
341 return aFilterMgr.CreateLength2D()
343 print "Error: given parameter is not numerucal functor type."
348 ## Mother class to define algorithm, recommended to don't use directly.
351 class Mesh_Algorithm:
352 # @class Mesh_Algorithm
353 # @brief Class Mesh_Algorithm
360 ## If the algorithm is global, return 0; \n
361 # else return the submesh associated to this algorithm.
362 def GetSubMesh(self):
365 ## Return the wrapped mesher.
366 def GetAlgorithm(self):
369 ## Get list of hypothesis that can be used with this algorithm
370 def GetCompatibleHypothesis(self):
373 list = self.algo.GetCompatibleHypothesis()
381 def SetName(self, name):
382 SetName(self.algo, name)
386 return self.algo.GetId()
388 ## Private method. Print error message if a hypothesis was not assigned.
389 def TreatHypoStatus(self, status, hypName, geomName, isAlgo):
391 hypType = "algorithm"
393 hypType = "hypothesis"
394 if status == HYP_UNKNOWN_FATAL :
395 reason = "for unknown reason"
396 elif status == HYP_INCOMPATIBLE :
397 reason = "this hypothesis mismatches algorithm"
398 elif status == HYP_NOTCONFORM :
399 reason = "not conform mesh would be built"
400 elif status == HYP_ALREADY_EXIST :
401 reason = hypType + " of the same dimension already assigned to this shape"
402 elif status == HYP_BAD_DIM :
403 reason = hypType + " mismatches shape"
404 elif status == HYP_CONCURENT :
405 reason = "there are concurrent hypotheses on sub-shapes"
406 elif status == HYP_BAD_SUBSHAPE :
407 reason = "shape is neither the main one, nor its subshape, nor a valid group"
408 elif status == HYP_BAD_GEOMETRY:
409 reason = "geometry mismatches algorithm's expectation"
412 hypName = '"' + hypName + '"'
413 geomName= '"' + geomName+ '"'
414 if status < HYP_UNKNOWN_FATAL:
415 print hypName, "was assigned to", geomName,"but", reason
417 print hypName, "was not assigned to",geomName,":", reason
421 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
423 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
428 name = GetName(piece)
433 name = geompy.SubShapeName(geom, piece)
434 geompy.addToStudyInFather(piece, geom, name)
435 self.subm = mesh.mesh.GetSubMesh(geom, hypo)
437 self.algo = smesh.CreateHypothesis(hypo, so)
438 SetName(self.algo, name + "/" + hypo)
439 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
440 self.TreatHypoStatus( status, hypo, name, 1 )
443 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
444 hypo = smesh.CreateHypothesis(hyp, so)
450 a = a + s + str(args[i])
453 name = GetName(self.geom)
454 SetName(hypo, name + "/" + hyp + a)
455 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
456 self.TreatHypoStatus( status, hyp, name, 0 )
460 # Public class: Mesh_Segment
461 # --------------------------
463 ## Class to define a segment 1D algorithm for discretization
466 class Mesh_Segment(Mesh_Algorithm):
468 ## Private constructor.
469 def __init__(self, mesh, geom=0):
470 self.Create(mesh, geom, "Regular_1D")
472 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
473 # @param l for the length of segments that cut an edge
474 def LocalLength(self, l):
475 hyp = self.Hypothesis("LocalLength", [l])
479 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
480 # @param n for the number of segments that cut an edge
481 # @param s for the scale factor (optional)
482 def NumberOfSegments(self, n, s=[]):
484 hyp = self.Hypothesis("NumberOfSegments", [n])
486 hyp = self.Hypothesis("NumberOfSegments", [n,s])
487 hyp.SetDistrType( 1 )
488 hyp.SetScaleFactor(s)
489 hyp.SetNumberOfSegments(n)
492 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
493 # @param start for the length of the first segment
494 # @param end for the length of the last segment
495 def Arithmetic1D(self, start, end):
496 hyp = self.Hypothesis("Arithmetic1D", [start, end])
497 hyp.SetLength(start, 1)
498 hyp.SetLength(end , 0)
501 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
502 # @param start for the length of the first segment
503 # @param end for the length of the last segment
504 def StartEndLength(self, start, end):
505 hyp = self.Hypothesis("StartEndLength", [start, end])
506 hyp.SetLength(start, 1)
507 hyp.SetLength(end , 0)
510 ## Define "Deflection1D" hypothesis
511 # @param d for the deflection
512 def Deflection1D(self, d):
513 hyp = self.Hypothesis("Deflection1D", [d])
517 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
518 # the opposite side in the case of quadrangular faces
519 def Propagation(self):
520 return self.Hypothesis("Propagation")
522 ## Define "AutomaticLength" hypothesis
523 # @param fineness for the fineness [0-1]
524 def AutomaticLength(self, fineness=0):
525 hyp = self.Hypothesis("AutomaticLength")
526 hyp.SetFineness( fineness )
529 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
530 # If the 2D mesher sees that all boundary edges are quadratic ones,
531 # it generates quadratic faces, else it generates linear faces using
532 # medium nodes as if they were vertex ones.
533 # The 3D mesher generates quadratic volumes only if all boundary faces
534 # are quadratic ones, else it fails.
535 def QuadraticMesh(self):
536 hyp = self.Hypothesis("QuadraticMesh")
539 # Public class: Mesh_Segment_Python
540 # ---------------------------------
542 ## Class to define a segment 1D algorithm for discretization with python function
545 class Mesh_Segment_Python(Mesh_Segment):
547 ## Private constructor.
548 def __init__(self, mesh, geom=0):
549 import Python1dPlugin
550 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
552 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
553 # @param n for the number of segments that cut an edge
554 # @param func for the python function that calculate the length of all segments
555 def PythonSplit1D(self, n, func):
556 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
557 hyp.SetNumberOfSegments(n)
558 hyp.SetPythonLog10RatioFunction(func)
561 # Public class: Mesh_Triangle
562 # ---------------------------
564 ## Class to define a triangle 2D algorithm
567 class Mesh_Triangle(Mesh_Algorithm):
572 ## Private constructor.
573 def __init__(self, mesh, algoType, geom=0):
574 if algoType == MEFISTO:
575 self.Create(mesh, geom, "MEFISTO_2D")
576 elif algoType == NETGEN:
578 print "Warning: NETGENPlugin module has not been imported."
579 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
580 self.algoType = algoType
582 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
583 # @param area for the maximum area of each triangles
584 def MaxElementArea(self, area):
585 if self.algoType == MEFISTO:
586 hyp = self.Hypothesis("MaxElementArea", [area])
587 hyp.SetMaxElementArea(area)
589 elif self.algoType == NETGEN:
590 print "Netgen 1D-2D algo doesn't support this hypothesis"
593 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
594 def LengthFromEdges(self):
595 if self.algoType == MEFISTO:
596 hyp = self.Hypothesis("LengthFromEdges")
598 elif self.algoType == NETGEN:
599 print "Netgen 1D-2D algo doesn't support this hypothesis"
602 ## Define "Netgen 2D Parameters" hypothesis
603 def Parameters(self):
604 if self.algoType == NETGEN:
605 self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
607 elif self.algoType == MEFISTO:
608 print "Mefisto algo doesn't support this hypothesis"
612 def SetMaxSize(self, theSize):
615 self.params.SetMaxSize(theSize)
617 ## Set SecondOrder flag
618 def SetSecondOrder(seld, theVal):
621 self.params.SetSecondOrder(theVal)
624 def SetOptimize(self, theVal):
627 self.params.SetOptimize(theVal)
630 # @param theFineness is:
631 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
632 def SetFineness(self, theFineness):
635 self.params.SetFineness(theFineness)
638 def SetGrowthRate(self, theRate):
641 self.params.SetGrowthRate(theRate)
644 def SetNbSegPerEdge(self, theVal):
647 self.params.SetNbSegPerEdge(theVal)
649 ## Set NbSegPerRadius
650 def SetNbSegPerRadius(self, theVal):
653 self.params.SetNbSegPerRadius(theVal)
655 ## Set QuadAllowed flag
656 def SetQuadAllowed(self, toAllow):
659 self.params.SetQuadAllowed(toAllow)
662 # Public class: Mesh_Quadrangle
663 # -----------------------------
665 ## Class to define a quadrangle 2D algorithm
668 class Mesh_Quadrangle(Mesh_Algorithm):
670 ## Private constructor.
671 def __init__(self, mesh, geom=0):
672 self.Create(mesh, geom, "Quadrangle_2D")
674 ## Define "QuadranglePreference" hypothesis, forcing construction
675 # of quadrangles if the number of nodes on opposite edges is not the same
676 # in the case where the global number of nodes on edges is even
677 def QuadranglePreference(self):
678 hyp = self.Hypothesis("QuadranglePreference")
681 # Public class: Mesh_Tetrahedron
682 # ------------------------------
684 ## Class to define a tetrahedron 3D algorithm
687 class Mesh_Tetrahedron(Mesh_Algorithm):
692 ## Private constructor.
693 def __init__(self, mesh, algoType, geom=0):
694 if algoType == NETGEN:
695 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
696 elif algoType == GHS3D:
698 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
699 elif algoType == FULL_NETGEN:
701 print "Warning: NETGENPlugin module has not been imported."
702 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
703 self.algoType = algoType
705 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
706 # @param vol for the maximum volume of each tetrahedral
707 def MaxElementVolume(self, vol):
708 hyp = self.Hypothesis("MaxElementVolume", [vol])
709 hyp.SetMaxElementVolume(vol)
712 ## Define "Netgen 3D Parameters" hypothesis
713 def Parameters(self):
714 if (self.algoType == FULL_NETGEN):
715 self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
718 print "Algo doesn't support this hypothesis"
722 def SetMaxSize(self, theSize):
725 self.params.SetMaxSize(theSize)
727 ## Set SecondOrder flag
728 def SetSecondOrder(self, theVal):
731 self.params.SetSecondOrder(theVal)
734 def SetOptimize(self, theVal):
737 self.params.SetOptimize(theVal)
740 # @param theFineness is:
741 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
742 def SetFineness(self, theFineness):
745 self.params.SetFineness(theFineness)
748 def SetGrowthRate(self, theRate):
751 self.params.SetGrowthRate(theRate)
754 def SetNbSegPerEdge(self, theVal):
757 self.params.SetNbSegPerEdge(theVal)
759 ## Set NbSegPerRadius
760 def SetNbSegPerRadius(self, theVal):
763 self.params.SetNbSegPerRadius(theVal)
765 # Public class: Mesh_Hexahedron
766 # ------------------------------
768 ## Class to define a hexahedron 3D algorithm
771 class Mesh_Hexahedron(Mesh_Algorithm):
773 ## Private constructor.
774 def __init__(self, mesh, geom=0):
775 self.Create(mesh, geom, "Hexa_3D")
777 # Deprecated, only for compatibility!
778 # Public class: Mesh_Netgen
779 # ------------------------------
781 ## Class to define a NETGEN-based 2D or 3D algorithm
782 # that need no discrete boundary (i.e. independent)
784 # This class is deprecated, only for compatibility!
787 class Mesh_Netgen(Mesh_Algorithm):
791 ## Private constructor.
792 def __init__(self, mesh, is3D, geom=0):
794 print "Warning: NETGENPlugin module has not been imported."
798 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
800 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
802 ## Define hypothesis containing parameters of the algorithm
803 def Parameters(self):
805 hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
807 hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
810 # Public class: Mesh_Projection1D
811 # ------------------------------
813 ## Class to define a projection 1D algorithm
816 class Mesh_Projection1D(Mesh_Algorithm):
818 ## Private constructor.
819 def __init__(self, mesh, geom=0):
820 self.Create(mesh, geom, "Projection_1D")
822 ## Define "Source Edge" hypothesis, specifying a meshed edge to
823 # take a mesh pattern from, and optionally association of vertices
824 # between the source edge and a target one (where a hipothesis is assigned to)
825 # @param edge to take nodes distribution from
826 # @param mesh to take nodes distribution from (optional)
827 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
828 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
829 # to associate with \a srcV (optional)
830 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
831 hyp = self.Hypothesis("ProjectionSource1D")
832 hyp.SetSourceEdge( edge )
833 if not mesh is None and isinstance(mesh, Mesh):
834 mesh = mesh.GetMesh()
835 hyp.SetSourceMesh( mesh )
836 hyp.SetVertexAssociation( srcV, tgtV )
840 # Public class: Mesh_Projection2D
841 # ------------------------------
843 ## Class to define a projection 2D algorithm
846 class Mesh_Projection2D(Mesh_Algorithm):
848 ## Private constructor.
849 def __init__(self, mesh, geom=0):
850 self.Create(mesh, geom, "Projection_2D")
852 ## Define "Source Face" hypothesis, specifying a meshed face to
853 # take a mesh pattern from, and optionally association of vertices
854 # between the source face and a target one (where a hipothesis is assigned to)
855 # @param face to take mesh pattern from
856 # @param mesh to take mesh pattern from (optional)
857 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
858 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
859 # to associate with \a srcV1 (optional)
860 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
861 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
862 # to associate with \a srcV2 (optional)
864 # Note: association vertices must belong to one edge of a face
865 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
866 hyp = self.Hypothesis("ProjectionSource2D")
867 hyp.SetSourceFace( face )
868 if not mesh is None and isinstance(mesh, Mesh):
869 mesh = mesh.GetMesh()
870 hyp.SetSourceMesh( mesh )
871 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
874 # Public class: Mesh_Projection3D
875 # ------------------------------
877 ## Class to define a projection 3D algorithm
880 class Mesh_Projection3D(Mesh_Algorithm):
882 ## Private constructor.
883 def __init__(self, mesh, geom=0):
884 self.Create(mesh, geom, "Projection_3D")
886 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
887 # take a mesh pattern from, and optionally association of vertices
888 # between the source solid and a target one (where a hipothesis is assigned to)
889 # @param solid to take mesh pattern from
890 # @param mesh to take mesh pattern from (optional)
891 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
892 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
893 # to associate with \a srcV1 (optional)
894 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
895 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
896 # to associate with \a srcV2 (optional)
898 # Note: association vertices must belong to one edge of a solid
899 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
900 hyp = self.Hypothesis("ProjectionSource3D")
901 hyp.SetSource3DShape( solid )
902 if not mesh is None and isinstance(mesh, Mesh):
903 mesh = mesh.GetMesh()
904 hyp.SetSourceMesh( mesh )
905 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
909 # Public class: Mesh_Prism
910 # ------------------------
912 ## Class to define a Prism 3D algorithm
915 class Mesh_Prism3D(Mesh_Algorithm):
917 ## Private constructor.
918 def __init__(self, mesh, geom=0):
919 self.Create(mesh, geom, "Prism_3D")
921 # Public class: Mesh_RadialPrism
922 # -------------------------------
924 ## Class to define a Radial Prism 3D algorithm
927 class Mesh_RadialPrism3D(Mesh_Algorithm):
929 ## Private constructor.
930 def __init__(self, mesh, geom=0):
931 self.Create(mesh, geom, "RadialPrism_3D")
932 self.distribHyp = self.Hypothesis( "LayerDistribution" )
935 ## Return 3D hypothesis holding the 1D one
936 def Get3DHypothesis(self):
937 return self.distribHyp
939 ## Private method creating 1D hypothes and storing it in the LayerDistribution
940 # hypothes. Returns the created hypothes
941 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
942 if not self.nbLayers is None:
943 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
944 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
945 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
946 hyp = smesh.CreateHypothesis(hypType, so)
947 SetCurrentStudy( study ) # anable publishing
948 self.distribHyp.SetLayerDistribution( hyp )
951 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
952 # prisms to build between the inner and outer shells
953 def NumberOfLayers(self, n ):
954 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
955 self.nbLayers = self.Hypothesis("NumberOfLayers")
956 self.nbLayers.SetNumberOfLayers( n )
959 ## Define "LocalLength" hypothesis, specifying segment length
960 # to build between the inner and outer shells
961 # @param l for the length of segments
962 def LocalLength(self, l):
963 hyp = self.OwnHypothesis("LocalLength", [l])
967 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
968 # prisms to build between the inner and outer shells
969 # @param n for the number of segments
970 # @param s for the scale factor (optional)
971 def NumberOfSegments(self, n, s=[]):
973 hyp = self.OwnHypothesis("NumberOfSegments", [n])
975 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
976 hyp.SetDistrType( 1 )
977 hyp.SetScaleFactor(s)
978 hyp.SetNumberOfSegments(n)
981 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
982 # to build between the inner and outer shells as arithmetic length increasing
983 # @param start for the length of the first segment
984 # @param end for the length of the last segment
985 def Arithmetic1D(self, start, end):
986 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
987 hyp.SetLength(start, 1)
988 hyp.SetLength(end , 0)
991 ## Define "StartEndLength" hypothesis, specifying distribution of segments
992 # to build between the inner and outer shells as geometric length increasing
993 # @param start for the length of the first segment
994 # @param end for the length of the last segment
995 def StartEndLength(self, start, end):
996 hyp = self.OwnHypothesis("StartEndLength", [start, end])
997 hyp.SetLength(start, 1)
998 hyp.SetLength(end , 0)
1001 ## Define "AutomaticLength" hypothesis, specifying number of segments
1002 # to build between the inner and outer shells
1003 # @param fineness for the fineness [0-1]
1004 def AutomaticLength(self, fineness=0):
1005 hyp = self.OwnHypothesis("AutomaticLength")
1006 hyp.SetFineness( fineness )
1010 # Public class: Mesh
1011 # ==================
1013 ## Class to define a mesh
1015 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1025 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1026 # sets GUI name of this mesh to \a name.
1027 # @param obj Shape to be meshed or SMESH_Mesh object
1028 # @param name Study name of the mesh
1029 def __init__(self, obj=0, name=0):
1033 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1035 self.mesh = smesh.CreateMesh(self.geom)
1036 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1039 self.mesh = smesh.CreateEmptyMesh()
1041 SetName(self.mesh, name)
1043 SetName(self.mesh, GetName(obj))
1045 self.editor = self.mesh.GetMeshEditor()
1047 ## Method that inits the Mesh object from SMESH_Mesh interface
1048 # @param theMesh is SMESH_Mesh object
1049 def SetMesh(self, theMesh):
1051 self.geom = self.mesh.GetShapeToMesh()
1053 ## Method that returns the mesh
1054 # @return SMESH_Mesh object
1060 name = GetName(self.GetMesh())
1064 def SetName(self, name):
1065 SetName(self.GetMesh(), name)
1067 ## Get the subMesh object associated to a subShape. The subMesh object
1068 # gives access to nodes and elements IDs.
1069 # \n SubMesh will be used instead of SubShape in a next idl version to
1070 # adress a specific subMesh...
1071 def GetSubMesh(self, theSubObject, name):
1072 submesh = self.mesh.GetSubMesh(theSubObject, name)
1075 ## Method that returns the shape associated to the mesh
1076 # @return GEOM_Object
1080 ## Method that associates given shape to the mesh(entails the mesh recreation)
1081 # @param geom shape to be meshed(GEOM_Object)
1082 def SetShape(self, geom):
1083 self.mesh = smesh.CreateMesh(geom)
1085 ## Return true if hypotheses are defined well
1086 # @param theMesh is an instance of Mesh class
1087 # @param theSubObject subshape of a mesh shape
1088 def IsReadyToCompute(self, theSubObject):
1089 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1091 ## Return errors of hypotheses definintion
1092 # error list is empty if everything is OK
1093 # @param theMesh is an instance of Mesh class
1094 # @param theSubObject subshape of a mesh shape
1095 # @return a list of errors
1096 def GetAlgoState(self, theSubObject):
1097 return smesh.GetAlgoState(self.mesh, theSubObject)
1099 ## Return geometrical object the given element is built on.
1100 # The returned geometrical object, if not nil, is either found in the
1101 # study or is published by this method with the given name
1102 # @param theMesh is an instance of Mesh class
1103 # @param theElementID an id of the mesh element
1104 # @param theGeomName user defined name of geometrical object
1105 # @return GEOM::GEOM_Object instance
1106 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1107 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1109 ## Returns mesh dimension depending on shape one
1110 def MeshDimension(self):
1111 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1112 if len( shells ) > 0 :
1114 elif geompy.NumberOfFaces( self.geom ) > 0 :
1116 elif geompy.NumberOfEdges( self.geom ) > 0 :
1122 ## Creates a segment discretization 1D algorithm.
1123 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1124 # If the optional \a geom parameter is not sets, this algorithm is global.
1125 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1126 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1127 # @param geom If defined, subshape to be meshed
1128 def Segment(self, algo=REGULAR, geom=0):
1129 ## if Segment(geom) is called by mistake
1130 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1131 algo, geom = geom, algo
1134 return Mesh_Segment(self, geom)
1135 elif algo == PYTHON:
1136 return Mesh_Segment_Python(self, geom)
1138 return Mesh_Segment(self, geom)
1140 ## Creates a triangle 2D algorithm for faces.
1141 # If the optional \a geom parameter is not sets, this algorithm is global.
1142 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1143 # @param algo values are: smesh.MEFISTO or smesh.NETGEN
1144 # @param geom If defined, subshape to be meshed
1145 def Triangle(self, algo=MEFISTO, geom=0):
1146 ## if Triangle(geom) is called by mistake
1147 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1151 return Mesh_Triangle(self, algo, geom)
1153 ## Creates a quadrangle 2D algorithm for faces.
1154 # If the optional \a geom parameter is not sets, this algorithm is global.
1155 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1156 # @param geom If defined, subshape to be meshed
1157 def Quadrangle(self, geom=0):
1158 return Mesh_Quadrangle(self, geom)
1160 ## Creates a tetrahedron 3D algorithm for solids.
1161 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1162 # If the optional \a geom parameter is not sets, this algorithm is global.
1163 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1164 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1165 # @param geom If defined, subshape to be meshed
1166 def Tetrahedron(self, algo=NETGEN, geom=0):
1167 ## if Tetrahedron(geom) is called by mistake
1168 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1169 algo, geom = geom, algo
1171 return Mesh_Tetrahedron(self, algo, geom)
1173 ## Creates a hexahedron 3D algorithm for solids.
1174 # If the optional \a geom parameter is not sets, this algorithm is global.
1175 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1176 # @param geom If defined, subshape to be meshed
1177 def Hexahedron(self, geom=0):
1178 return Mesh_Hexahedron(self, geom)
1180 ## Deprecated, only for compatibility!
1181 def Netgen(self, is3D, geom=0):
1182 return Mesh_Netgen(self, is3D, geom)
1184 ## Creates a projection 1D algorithm for edges.
1185 # If the optional \a geom parameter is not sets, this algorithm is global.
1186 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1187 # @param geom If defined, subshape to be meshed
1188 def Projection1D(self, geom=0):
1189 return Mesh_Projection1D(self, geom)
1191 ## Creates a projection 2D algorithm for faces.
1192 # If the optional \a geom parameter is not sets, this algorithm is global.
1193 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1194 # @param geom If defined, subshape to be meshed
1195 def Projection2D(self, geom=0):
1196 return Mesh_Projection2D(self, geom)
1198 ## Creates a projection 3D algorithm for solids.
1199 # If the optional \a geom parameter is not sets, this algorithm is global.
1200 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1201 # @param geom If defined, subshape to be meshed
1202 def Projection3D(self, geom=0):
1203 return Mesh_Projection3D(self, geom)
1205 ## Creates a Prism 3D or RadialPrism 3D algorithm for solids.
1206 # If the optional \a geom parameter is not sets, this algorithm is global.
1207 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1208 # @param geom If defined, subshape to be meshed
1209 def Prism(self, geom=0):
1213 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1214 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1215 if nbSolids == 0 or nbSolids == nbShells:
1216 return Mesh_Prism3D(self, geom)
1217 return Mesh_RadialPrism3D(self, geom)
1219 ## Compute the mesh and return the status of the computation
1220 def Compute(self, geom=0):
1221 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1223 print "Compute impossible: mesh is not constructed on geom shape."
1227 ok = smesh.Compute(self.mesh, geom)
1229 errors = smesh.GetAlgoState( self.mesh, geom )
1232 if err.isGlobalAlgo:
1237 dim = str(err.algoDim)
1238 if err.name == MISSING_ALGO:
1239 reason = glob + dim + "D algorithm is missing"
1240 elif err.name == MISSING_HYPO:
1241 name = '"' + err.algoName + '"'
1242 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1243 elif err.name == NOT_CONFORM_MESH:
1244 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1245 elif err.name == BAD_PARAM_VALUE:
1246 name = '"' + err.algoName + '"'
1247 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1248 " has a bad parameter value"
1250 reason = "For unknown reason."+\
1251 " Revise Mesh.Compute() implementation in smesh.py!"
1253 if allReasons != "":
1256 allReasons += reason
1258 if allReasons != "":
1259 print '"' + GetName(self.mesh) + '"',"not computed:"
1263 if salome.sg.hasDesktop():
1264 smeshgui = salome.ImportComponentGUI("SMESH")
1265 smeshgui.Init(salome.myStudyId)
1266 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok )
1267 salome.sg.updateObjBrowser(1)
1271 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1272 # The parameter \a fineness [0,-1] defines mesh fineness
1273 def AutomaticTetrahedralization(self, fineness=0):
1274 dim = self.MeshDimension()
1276 self.RemoveGlobalHypotheses()
1277 self.Segment().AutomaticLength(fineness)
1279 self.Triangle().LengthFromEdges()
1282 self.Tetrahedron(NETGEN)
1284 return self.Compute()
1286 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1287 # The parameter \a fineness [0,-1] defines mesh fineness
1288 def AutomaticHexahedralization(self, fineness=0):
1289 dim = self.MeshDimension()
1291 self.RemoveGlobalHypotheses()
1292 self.Segment().AutomaticLength(fineness)
1299 return self.Compute()
1301 ## Get the list of hypothesis added on a geom
1302 # @param geom is subhape of mesh geometry
1303 def GetHypothesisList(self, geom):
1304 return self.mesh.GetHypothesisList( geom )
1306 ## Removes all global hypotheses
1307 def RemoveGlobalHypotheses(self):
1308 current_hyps = self.mesh.GetHypothesisList( self.geom )
1309 for hyp in current_hyps:
1310 self.mesh.RemoveHypothesis( self.geom, hyp )
1314 ## Create a mesh group based on geometric object \a grp
1315 # and give a \a name, \n if this parameter is not defined
1316 # the name is the same as the geometric group name \n
1317 # Note: Works like GroupOnGeom().
1318 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1319 # @param name is the name of the mesh group
1320 # @return SMESH_GroupOnGeom
1321 def Group(self, grp, name=""):
1322 return self.GroupOnGeom(grp, name)
1324 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1325 # Export the mesh in a file with the MED format and choice the \a version of MED format
1326 # @param f is the file name
1327 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1328 def ExportToMED(self, f, version, opt=0):
1329 self.mesh.ExportToMED(f, opt, version)
1331 ## Export the mesh in a file with the MED format
1332 # @param f is the file name
1333 # @param auto_groups boolean parameter for creating/not creating
1334 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1335 # the typical use is auto_groups=false.
1336 # @param version MED format version(MED_V2_1 or MED_V2_2)
1337 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1338 self.mesh.ExportToMED(f, auto_groups, version)
1340 ## Export the mesh in a file with the DAT format
1341 # @param f is the file name
1342 def ExportDAT(self, f):
1343 self.mesh.ExportDAT(f)
1345 ## Export the mesh in a file with the UNV format
1346 # @param f is the file name
1347 def ExportUNV(self, f):
1348 self.mesh.ExportUNV(f)
1350 ## Export the mesh in a file with the STL format
1351 # @param f is the file name
1352 # @param ascii defined the kind of file contents
1353 def ExportSTL(self, f, ascii=1):
1354 self.mesh.ExportSTL(f, ascii)
1357 # Operations with groups:
1358 # ----------------------
1360 ## Creates an empty mesh group
1361 # @param elementType is the type of elements in the group
1362 # @param name is the name of the mesh group
1363 # @return SMESH_Group
1364 def CreateEmptyGroup(self, elementType, name):
1365 return self.mesh.CreateGroup(elementType, name)
1367 ## Creates a mesh group based on geometric object \a grp
1368 # and give a \a name, \n if this parameter is not defined
1369 # the name is the same as the geometric group name
1370 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1371 # @param name is the name of the mesh group
1372 # @return SMESH_GroupOnGeom
1373 def GroupOnGeom(self, grp, name="", type=None):
1375 name = grp.GetName()
1378 tgeo = str(grp.GetShapeType())
1379 if tgeo == "VERTEX":
1381 elif tgeo == "EDGE":
1383 elif tgeo == "FACE":
1385 elif tgeo == "SOLID":
1387 elif tgeo == "SHELL":
1389 elif tgeo == "COMPOUND":
1390 if len( geompy.GetObjectIDs( grp )) == 0:
1391 print "Mesh.Group: empty geometric group", GetName( grp )
1393 tgeo = geompy.GetType(grp)
1394 if tgeo == geompy.ShapeType["VERTEX"]:
1396 elif tgeo == geompy.ShapeType["EDGE"]:
1398 elif tgeo == geompy.ShapeType["FACE"]:
1400 elif tgeo == geompy.ShapeType["SOLID"]:
1404 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1407 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1409 ## Create a mesh group by the given ids of elements
1410 # @param groupName is the name of the mesh group
1411 # @param elementType is the type of elements in the group
1412 # @param elemIDs is the list of ids
1413 # @return SMESH_Group
1414 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1415 group = self.mesh.CreateGroup(elementType, groupName)
1419 ## Create a mesh group by the given conditions
1420 # @param groupName is the name of the mesh group
1421 # @param elementType is the type of elements in the group
1422 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1423 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1424 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1425 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1426 # @return SMESH_Group
1430 CritType=FT_Undefined,
1433 UnaryOp=FT_Undefined):
1434 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1435 group = self.MakeGroupByCriterion(groupName, aCriterion)
1438 ## Create a mesh group by the given criterion
1439 # @param groupName is the name of the mesh group
1440 # @param Criterion is the instance of Criterion class
1441 # @return SMESH_Group
1442 def MakeGroupByCriterion(self, groupName, Criterion):
1443 aFilterMgr = smesh.CreateFilterManager()
1444 aFilter = aFilterMgr.CreateFilter()
1446 aCriteria.append(Criterion)
1447 aFilter.SetCriteria(aCriteria)
1448 group = self.MakeGroupByFilter(groupName, aFilter)
1451 ## Create a mesh group by the given criteria(list of criterions)
1452 # @param groupName is the name of the mesh group
1453 # @param Criteria is the list of criterions
1454 # @return SMESH_Group
1455 def MakeGroupByCriteria(self, groupName, theCriteria):
1456 aFilterMgr = smesh.CreateFilterManager()
1457 aFilter = aFilterMgr.CreateFilter()
1458 aFilter.SetCriteria(theCriteria)
1459 group = self.MakeGroupByFilter(groupName, aFilter)
1462 ## Create a mesh group by the given filter
1463 # @param groupName is the name of the mesh group
1464 # @param Criterion is the instance of Filter class
1465 # @return SMESH_Group
1466 def MakeGroupByFilter(self, groupName, theFilter):
1467 anIds = theFilter.GetElementsId(self.mesh)
1468 anElemType = theFilter.GetElementType()
1469 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1472 ## Pass mesh elements through the given filter and return ids
1473 # @param theFilter is SMESH_Filter
1474 # @return list of ids
1475 def GetIdsFromFilter(self, theFilter):
1476 return theFilter.GetElementsId(self.mesh)
1478 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1479 # Returns list of special structures(borders).
1480 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1481 def GetFreeBorders(self):
1482 aFilterMgr = smesh.CreateFilterManager()
1483 aPredicate = aFilterMgr.CreateFreeEdges()
1484 aPredicate.SetMesh(self.mesh)
1485 aBorders = aPredicate.GetBorders()
1489 def RemoveGroup(self, group):
1490 self.mesh.RemoveGroup(group)
1492 ## Remove group with its contents
1493 def RemoveGroupWithContents(self, group):
1494 self.mesh.RemoveGroupWithContents(group)
1496 ## Get the list of groups existing in the mesh
1497 def GetGroups(self):
1498 return self.mesh.GetGroups()
1500 ## Get the list of names of groups existing in the mesh
1501 def GetGroupNames(self):
1502 groups = self.GetGroups()
1504 for group in groups:
1505 names.append(group.GetName())
1508 ## Union of two groups
1509 # New group is created. All mesh elements that are
1510 # present in initial groups are added to the new one
1511 def UnionGroups(self, group1, group2, name):
1512 return self.mesh.UnionGroups(group1, group2, name)
1514 ## Intersection of two groups
1515 # New group is created. All mesh elements that are
1516 # present in both initial groups are added to the new one.
1517 def IntersectGroups(self, group1, group2, name):
1518 return self.mesh.IntersectGroups(group1, group2, name)
1520 ## Cut of two groups
1521 # New group is created. All mesh elements that are present in
1522 # main group but do not present in tool group are added to the new one
1523 def CutGroups(self, mainGroup, toolGroup, name):
1524 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1527 # Get some info about mesh:
1528 # ------------------------
1530 ## Get the log of nodes and elements added or removed since previous
1532 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1533 # @return list of log_block structures:
1538 def GetLog(self, clearAfterGet):
1539 return self.mesh.GetLog(clearAfterGet)
1541 ## Clear the log of nodes and elements added or removed since previous
1542 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1544 self.mesh.ClearLog()
1546 ## Get the internal Id
1548 return self.mesh.GetId()
1551 def GetStudyId(self):
1552 return self.mesh.GetStudyId()
1554 ## Check group names for duplications.
1555 # Consider maximum group name length stored in MED file.
1556 def HasDuplicatedGroupNamesMED(self):
1557 return self.mesh.GetStudyId()
1559 ## Obtain instance of SMESH_MeshEditor
1560 def GetMeshEditor(self):
1561 return self.mesh.GetMeshEditor()
1564 def GetMEDMesh(self):
1565 return self.mesh.GetMEDMesh()
1568 # Get informations about mesh contents:
1569 # ------------------------------------
1571 ## Returns number of nodes in mesh
1573 return self.mesh.NbNodes()
1575 ## Returns number of elements in mesh
1576 def NbElements(self):
1577 return self.mesh.NbElements()
1579 ## Returns number of edges in mesh
1581 return self.mesh.NbEdges()
1583 ## Returns number of edges with given order in mesh
1584 # @param elementOrder is order of elements:
1585 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1586 def NbEdgesOfOrder(self, elementOrder):
1587 return self.mesh.NbEdgesOfOrder(elementOrder)
1589 ## Returns number of faces in mesh
1591 return self.mesh.NbFaces()
1593 ## Returns number of faces with given order in mesh
1594 # @param elementOrder is order of elements:
1595 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1596 def NbFacesOfOrder(self, elementOrder):
1597 return self.mesh.NbFacesOfOrder(elementOrder)
1599 ## Returns number of triangles in mesh
1600 def NbTriangles(self):
1601 return self.mesh.NbTriangles()
1603 ## Returns number of triangles with given order in mesh
1604 # @param elementOrder is order of elements:
1605 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1606 def NbTrianglesOfOrder(self, elementOrder):
1607 return self.mesh.NbTrianglesOfOrder(elementOrder)
1609 ## Returns number of quadrangles in mesh
1610 def NbQuadrangles(self):
1611 return self.mesh.NbQuadrangles()
1613 ## Returns number of quadrangles with given order in mesh
1614 # @param elementOrder is order of elements:
1615 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1616 def NbQuadranglesOfOrder(self, elementOrder):
1617 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1619 ## Returns number of polygons in mesh
1620 def NbPolygons(self):
1621 return self.mesh.NbPolygons()
1623 ## Returns number of volumes in mesh
1624 def NbVolumes(self):
1625 return self.mesh.NbVolumes()
1627 ## Returns number of volumes with given order in mesh
1628 # @param elementOrder is order of elements:
1629 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1630 def NbVolumesOfOrder(self, elementOrder):
1631 return self.mesh.NbVolumesOfOrder(elementOrder)
1633 ## Returns number of tetrahedrons in mesh
1635 return self.mesh.NbTetras()
1637 ## Returns number of tetrahedrons with given order in mesh
1638 # @param elementOrder is order of elements:
1639 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1640 def NbTetrasOfOrder(self, elementOrder):
1641 return self.mesh.NbTetrasOfOrder(elementOrder)
1643 ## Returns number of hexahedrons in mesh
1645 return self.mesh.NbHexas()
1647 ## Returns number of hexahedrons with given order in mesh
1648 # @param elementOrder is order of elements:
1649 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1650 def NbHexasOfOrder(self, elementOrder):
1651 return self.mesh.NbHexasOfOrder(elementOrder)
1653 ## Returns number of pyramids in mesh
1654 def NbPyramids(self):
1655 return self.mesh.NbPyramids()
1657 ## Returns number of pyramids with given order in mesh
1658 # @param elementOrder is order of elements:
1659 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1660 def NbPyramidsOfOrder(self, elementOrder):
1661 return self.mesh.NbPyramidsOfOrder(elementOrder)
1663 ## Returns number of prisms in mesh
1665 return self.mesh.NbPrisms()
1667 ## Returns number of prisms with given order in mesh
1668 # @param elementOrder is order of elements:
1669 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1670 def NbPrismsOfOrder(self, elementOrder):
1671 return self.mesh.NbPrismsOfOrder(elementOrder)
1673 ## Returns number of polyhedrons in mesh
1674 def NbPolyhedrons(self):
1675 return self.mesh.NbPolyhedrons()
1677 ## Returns number of submeshes in mesh
1678 def NbSubMesh(self):
1679 return self.mesh.NbSubMesh()
1681 ## Returns list of mesh elements ids
1682 def GetElementsId(self):
1683 return self.mesh.GetElementsId()
1685 ## Returns list of ids of mesh elements with given type
1686 # @param elementType is required type of elements
1687 def GetElementsByType(self, elementType):
1688 return self.mesh.GetElementsByType(elementType)
1690 ## Returns list of mesh nodes ids
1691 def GetNodesId(self):
1692 return self.mesh.GetNodesId()
1694 # Get informations about mesh elements:
1695 # ------------------------------------
1697 ## Returns type of mesh element
1698 def GetElementType(self, id, iselem):
1699 return self.mesh.GetElementType(id, iselem)
1701 ## Returns list of submesh elements ids
1702 # @param shapeID is geom object(subshape) IOR
1703 def GetSubMeshElementsId(self, shapeID):
1704 return self.mesh.GetSubMeshElementsId(shapeID)
1706 ## Returns list of submesh nodes ids
1707 # @param shapeID is geom object(subshape) IOR
1708 def GetSubMeshNodesId(self, shapeID, all):
1709 return self.mesh.GetSubMeshNodesId(shapeID, all)
1711 ## Returns list of ids of submesh elements with given type
1712 # @param shapeID is geom object(subshape) IOR
1713 def GetSubMeshElementType(self, shapeID):
1714 return self.mesh.GetSubMeshElementType(shapeID)
1716 ## Get mesh description
1718 return self.mesh.Dump()
1721 # Get information about nodes and elements of mesh by its ids:
1722 # -----------------------------------------------------------
1724 ## Get XYZ coordinates of node as list of double
1725 # \n If there is not node for given ID - returns empty list
1726 def GetNodeXYZ(self, id):
1727 return self.mesh.GetNodeXYZ(id)
1729 ## For given node returns list of IDs of inverse elements
1730 # \n If there is not node for given ID - returns empty list
1731 def GetNodeInverseElements(self, id):
1732 return self.mesh.GetNodeInverseElements(id)
1734 ## If given element is node returns IDs of shape from position
1735 # \n If there is not node for given ID - returns -1
1736 def GetShapeID(self, id):
1737 return self.mesh.GetShapeID(id)
1739 ## For given element returns ID of result shape after
1740 # FindShape() from SMESH_MeshEditor
1741 # \n If there is not element for given ID - returns -1
1742 def GetShapeIDForElem(id):
1743 return self.mesh.GetShapeIDForElem(id)
1745 ## Returns number of nodes for given element
1746 # \n If there is not element for given ID - returns -1
1747 def GetElemNbNodes(self, id):
1748 return self.mesh.GetElemNbNodes(id)
1750 ## Returns ID of node by given index for given element
1751 # \n If there is not element for given ID - returns -1
1752 # \n If there is not node for given index - returns -2
1753 def GetElemNode(self, id, index):
1754 return self.mesh.GetElemNode(id, index)
1756 ## Returns true if given node is medium node
1757 # in given quadratic element
1758 def IsMediumNode(self, elementID, nodeID):
1759 return self.mesh.IsMediumNode(elementID, nodeID)
1761 ## Returns true if given node is medium node
1762 # in one of quadratic elements
1763 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1764 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1766 ## Returns number of edges for given element
1767 def ElemNbEdges(self, id):
1768 return self.mesh.ElemNbEdges(id)
1770 ## Returns number of faces for given element
1771 def ElemNbFaces(self, id):
1772 return self.mesh.ElemNbFaces(id)
1774 ## Returns true if given element is polygon
1775 def IsPoly(self, id):
1776 return self.mesh.IsPoly(id)
1778 ## Returns true if given element is quadratic
1779 def IsQuadratic(self, id):
1780 return self.mesh.IsQuadratic(id)
1782 ## Returns XYZ coordinates of bary center for given element
1784 # \n If there is not element for given ID - returns empty list
1785 def BaryCenter(self, id):
1786 return self.mesh.BaryCenter(id)
1789 # Mesh edition (SMESH_MeshEditor functionality):
1790 # ---------------------------------------------
1792 ## Removes elements from mesh by ids
1793 # @param IDsOfElements is list of ids of elements to remove
1794 def RemoveElements(self, IDsOfElements):
1795 return self.editor.RemoveElements(IDsOfElements)
1797 ## Removes nodes from mesh by ids
1798 # @param IDsOfNodes is list of ids of nodes to remove
1799 def RemoveNodes(self, IDsOfNodes):
1800 return self.editor.RemoveNodes(IDsOfNodes)
1802 ## Add node to mesh by coordinates
1803 def AddNode(self, x, y, z):
1804 return self.editor.AddNode( x, y, z)
1807 ## Create edge both similar and quadratic (this is determed
1808 # by number of given nodes).
1809 # @param IdsOfNodes List of node IDs for creation of element.
1810 # Needed order of nodes in this list corresponds to description
1811 # of MED. \n This description is located by the following link:
1812 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1813 def AddEdge(self, IDsOfNodes):
1814 return self.editor.AddEdge(IDsOfNodes)
1816 ## Create face both similar and quadratic (this is determed
1817 # by number of given nodes).
1818 # @param IdsOfNodes List of node IDs for creation of element.
1819 # Needed order of nodes in this list corresponds to description
1820 # of MED. \n This description is located by the following link:
1821 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1822 def AddFace(self, IDsOfNodes):
1823 return self.editor.AddFace(IDsOfNodes)
1825 ## Add polygonal face to mesh by list of nodes ids
1826 def AddPolygonalFace(self, IdsOfNodes):
1827 return self.editor.AddPolygonalFace(IdsOfNodes)
1829 ## Create volume both similar and quadratic (this is determed
1830 # by number of given nodes).
1831 # @param IdsOfNodes List of node IDs for creation of element.
1832 # Needed order of nodes in this list corresponds to description
1833 # of MED. \n This description is located by the following link:
1834 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1835 def AddVolume(self, IDsOfNodes):
1836 return self.editor.AddVolume(IDsOfNodes)
1838 ## Create volume of many faces, giving nodes for each face.
1839 # @param IdsOfNodes List of node IDs for volume creation face by face.
1840 # @param Quantities List of integer values, Quantities[i]
1841 # gives quantity of nodes in face number i.
1842 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1843 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1845 ## Create volume of many faces, giving IDs of existing faces.
1846 # @param IdsOfFaces List of face IDs for volume creation.
1848 # Note: The created volume will refer only to nodes
1849 # of the given faces, not to the faces itself.
1850 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1851 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1853 ## Move node with given id
1854 # @param NodeID id of the node
1855 # @param x displacing along the X axis
1856 # @param y displacing along the Y axis
1857 # @param z displacing along the Z axis
1858 def MoveNode(self, NodeID, x, y, z):
1859 return self.editor.MoveNode(NodeID, x, y, z)
1861 ## Replace two neighbour triangles sharing Node1-Node2 link
1862 # with ones built on the same 4 nodes but having other common link.
1863 # @param NodeID1 first node id
1864 # @param NodeID2 second node id
1865 # @return false if proper faces not found
1866 def InverseDiag(self, NodeID1, NodeID2):
1867 return self.editor.InverseDiag(NodeID1, NodeID2)
1869 ## Replace two neighbour triangles sharing Node1-Node2 link
1870 # with a quadrangle built on the same 4 nodes.
1871 # @param NodeID1 first node id
1872 # @param NodeID2 second node id
1873 # @return false if proper faces not found
1874 def DeleteDiag(self, NodeID1, NodeID2):
1875 return self.editor.DeleteDiag(NodeID1, NodeID2)
1877 ## Reorient elements by ids
1878 # @param IDsOfElements if undefined reorient all mesh elements
1879 def Reorient(self, IDsOfElements=None):
1880 if IDsOfElements == None:
1881 IDsOfElements = self.GetElementsId()
1882 return self.editor.Reorient(IDsOfElements)
1884 ## Reorient all elements of the object
1885 # @param theObject is mesh, submesh or group
1886 def ReorientObject(self, theObject):
1887 return self.editor.ReorientObject(theObject)
1889 ## Fuse neighbour triangles into quadrangles.
1890 # @param IDsOfElements The triangles to be fused,
1891 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1892 # @param MaxAngle is a max angle between element normals at which fusion
1893 # is still performed; theMaxAngle is mesured in radians.
1894 # @return TRUE in case of success, FALSE otherwise.
1895 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1896 if IDsOfElements == []:
1897 IDsOfElements = self.GetElementsId()
1898 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1900 ## Fuse neighbour triangles of the object into quadrangles
1901 # @param theObject is mesh, submesh or group
1902 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1903 # @param MaxAngle is a max angle between element normals at which fusion
1904 # is still performed; theMaxAngle is mesured in radians.
1905 # @return TRUE in case of success, FALSE otherwise.
1906 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1907 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1909 ## Split quadrangles into triangles.
1910 # @param IDsOfElements the faces to be splitted.
1911 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1912 # @param @return TRUE in case of success, FALSE otherwise.
1913 def QuadToTri (self, IDsOfElements, theCriterion):
1914 if IDsOfElements == []:
1915 IDsOfElements = self.GetElementsId()
1916 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
1918 ## Split quadrangles into triangles.
1919 # @param theObject object to taking list of elements from, is mesh, submesh or group
1920 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1921 def QuadToTriObject (self, theObject, theCriterion):
1922 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
1924 ## Split quadrangles into triangles.
1925 # @param theElems The faces to be splitted
1926 # @param the13Diag is used to choose a diagonal for splitting.
1927 # @return TRUE in case of success, FALSE otherwise.
1928 def SplitQuad (self, IDsOfElements, Diag13):
1929 if IDsOfElements == []:
1930 IDsOfElements = self.GetElementsId()
1931 return self.editor.SplitQuad(IDsOfElements, Diag13)
1933 ## Split quadrangles into triangles.
1934 # @param theObject is object to taking list of elements from, is mesh, submesh or group
1935 def SplitQuadObject (self, theObject, Diag13):
1936 return self.editor.SplitQuadObject(theObject, Diag13)
1938 ## Find better splitting of the given quadrangle.
1939 # @param IDOfQuad ID of the quadrangle to be splitted.
1940 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
1941 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1942 # diagonal is better, 0 if error occurs.
1943 def BestSplit (self, IDOfQuad, theCriterion):
1944 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
1947 # @param IDsOfElements list if ids of elements to smooth
1948 # @param IDsOfFixedNodes list of ids of fixed nodes.
1949 # Note that nodes built on edges and boundary nodes are always fixed.
1950 # @param MaxNbOfIterations maximum number of iterations
1951 # @param MaxAspectRatio varies in range [1.0, inf]
1952 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1953 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1954 MaxNbOfIterations, MaxAspectRatio, Method):
1955 if IDsOfElements == []:
1956 IDsOfElements = self.GetElementsId()
1957 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1958 MaxNbOfIterations, MaxAspectRatio, Method)
1960 ## Smooth elements belong to given object
1961 # @param theObject object to smooth
1962 # @param IDsOfFixedNodes list of ids of fixed nodes.
1963 # Note that nodes built on edges and boundary nodes are always fixed.
1964 # @param MaxNbOfIterations maximum number of iterations
1965 # @param MaxAspectRatio varies in range [1.0, inf]
1966 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1967 def SmoothObject(self, theObject, IDsOfFixedNodes,
1968 MaxNbOfIterations, MaxxAspectRatio, Method):
1969 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1970 MaxNbOfIterations, MaxxAspectRatio, Method)
1972 ## Parametric smooth the given elements
1973 # @param IDsOfElements list if ids of elements to smooth
1974 # @param IDsOfFixedNodes list of ids of fixed nodes.
1975 # Note that nodes built on edges and boundary nodes are always fixed.
1976 # @param MaxNbOfIterations maximum number of iterations
1977 # @param MaxAspectRatio varies in range [1.0, inf]
1978 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1979 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1980 MaxNbOfIterations, MaxAspectRatio, Method):
1981 if IDsOfElements == []:
1982 IDsOfElements = self.GetElementsId()
1983 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1984 MaxNbOfIterations, MaxAspectRatio, Method)
1986 ## Parametric smooth elements belong to given object
1987 # @param theObject object to smooth
1988 # @param IDsOfFixedNodes list of ids of fixed nodes.
1989 # Note that nodes built on edges and boundary nodes are always fixed.
1990 # @param MaxNbOfIterations maximum number of iterations
1991 # @param MaxAspectRatio varies in range [1.0, inf]
1992 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1993 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
1994 MaxNbOfIterations, MaxAspectRatio, Method):
1995 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
1996 MaxNbOfIterations, MaxAspectRatio, Method)
1998 ## Converts all mesh to quadratic one, deletes old elements, replacing
1999 # them with quadratic ones with the same id.
2000 def ConvertToQuadratic(self, theForce3d):
2001 self.editor.ConvertToQuadratic(theForce3d)
2003 ## Converts all mesh from quadratic to ordinary ones,
2004 # deletes old quadratic elements, \n replacing
2005 # them with ordinary mesh elements with the same id.
2006 def ConvertFromQuadratic(self):
2007 return self.editor.ConvertFromQuadratic()
2009 ## Renumber mesh nodes
2010 def RenumberNodes(self):
2011 self.editor.RenumberNodes()
2013 ## Renumber mesh elements
2014 def RenumberElements(self):
2015 self.editor.RenumberElements()
2017 ## Generate new elements by rotation of the elements around the axis
2018 # @param IDsOfElements list of ids of elements to sweep
2019 # @param Axix axis of rotation, AxisStruct or line(geom object)
2020 # @param AngleInRadians angle of Rotation
2021 # @param NbOfSteps number of steps
2022 # @param Tolerance tolerance
2023 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2024 if IDsOfElements == []:
2025 IDsOfElements = self.GetElementsId()
2026 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2027 Axix = GetAxisStruct(Axix)
2028 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2030 ## Generate new elements by rotation of the elements of object around the axis
2031 # @param theObject object wich elements should be sweeped
2032 # @param Axix axis of rotation, AxisStruct or line(geom object)
2033 # @param AngleInRadians angle of Rotation
2034 # @param NbOfSteps number of steps
2035 # @param Tolerance tolerance
2036 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2037 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2038 Axix = GetAxisStruct(Axix)
2039 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2041 ## Generate new elements by extrusion of the elements with given ids
2042 # @param IDsOfElements list of elements ids for extrusion
2043 # @param StepVector vector, defining the direction and value of extrusion
2044 # @param NbOfSteps the number of steps
2045 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2046 if IDsOfElements == []:
2047 IDsOfElements = self.GetElementsId()
2048 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2049 StepVector = GetDirStruct(StepVector)
2050 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2052 ## Generate new elements by extrusion of the elements with given ids
2053 # @param IDsOfElements is ids of elements
2054 # @param StepVector vector, defining the direction and value of extrusion
2055 # @param NbOfSteps the number of steps
2056 # @param ExtrFlags set flags for performing extrusion
2057 # @param SewTolerance uses for comparing locations of nodes if flag
2058 # EXTRUSION_FLAG_SEW is set
2059 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2060 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2061 StepVector = GetDirStruct(StepVector)
2062 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2064 ## Generate new elements by extrusion of the elements belong to object
2065 # @param theObject object wich elements should be processed
2066 # @param StepVector vector, defining the direction and value of extrusion
2067 # @param NbOfSteps the number of steps
2068 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2069 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2070 StepVector = GetDirStruct(StepVector)
2071 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2073 ## Generate new elements by extrusion of the elements belong to object
2074 # @param theObject object wich elements should be processed
2075 # @param StepVector vector, defining the direction and value of extrusion
2076 # @param NbOfSteps the number of steps
2077 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2078 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2079 StepVector = GetDirStruct(StepVector)
2080 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2082 ## Generate new elements by extrusion of the elements belong to object
2083 # @param theObject object wich elements should be processed
2084 # @param StepVector vector, defining the direction and value of extrusion
2085 # @param NbOfSteps the number of steps
2086 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2087 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2088 StepVector = GetDirStruct(StepVector)
2089 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2091 ## Generate new elements by extrusion of the given elements
2092 # A path of extrusion must be a meshed edge.
2093 # @param IDsOfElements is ids of elements
2094 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2095 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2096 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2097 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2098 # @param Angles list of angles
2099 # @param HasRefPoint allows to use base point
2100 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2101 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2102 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2103 HasAngles, Angles, HasRefPoint, RefPoint):
2104 if IDsOfElements == []:
2105 IDsOfElements = self.GetElementsId()
2106 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2107 RefPoint = GetPointStruct(RefPoint)
2108 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2109 HasAngles, Angles, HasRefPoint, RefPoint)
2111 ## Generate new elements by extrusion of the elements belong to object
2112 # A path of extrusion must be a meshed edge.
2113 # @param IDsOfElements is ids of elements
2114 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2115 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2116 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2117 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2118 # @param Angles list of angles
2119 # @param HasRefPoint allows to use base point
2120 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2121 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2122 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2123 HasAngles, Angles, HasRefPoint, RefPoint):
2124 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2125 RefPoint = GetPointStruct(RefPoint)
2126 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2127 HasAngles, Angles, HasRefPoint, RefPoint)
2129 ## Symmetrical copy of mesh elements
2130 # @param IDsOfElements list of elements ids
2131 # @param Mirror is AxisStruct or geom object(point, line, plane)
2132 # @param theMirrorType is POINT, AXIS or PLANE
2133 # If the Mirror is geom object this parameter is unnecessary
2134 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2135 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2136 if IDsOfElements == []:
2137 IDsOfElements = self.GetElementsId()
2138 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2139 Mirror = GetAxisStruct(Mirror)
2140 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2142 ## Symmetrical copy of object
2143 # @param theObject mesh, submesh or group
2144 # @param Mirror is AxisStruct or geom object(point, line, plane)
2145 # @param theMirrorType is POINT, AXIS or PLANE
2146 # If the Mirror is geom object this parameter is unnecessary
2147 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2148 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2149 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2150 Mirror = GetAxisStruct(Mirror)
2151 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2153 ## Translates the elements
2154 # @param IDsOfElements list of elements ids
2155 # @param Vector direction of translation(DirStruct or vector)
2156 # @param Copy allows to copy the translated elements
2157 def Translate(self, IDsOfElements, Vector, Copy):
2158 if IDsOfElements == []:
2159 IDsOfElements = self.GetElementsId()
2160 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2161 Vector = GetDirStruct(Vector)
2162 self.editor.Translate(IDsOfElements, Vector, Copy)
2164 ## Translates the object
2165 # @param theObject object to translate(mesh, submesh, or group)
2166 # @param Vector direction of translation(DirStruct or geom vector)
2167 # @param Copy allows to copy the translated elements
2168 def TranslateObject(self, theObject, Vector, Copy):
2169 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2170 Vector = GetDirStruct(Vector)
2171 self.editor.TranslateObject(theObject, Vector, Copy)
2173 ## Rotates the elements
2174 # @param IDsOfElements list of elements ids
2175 # @param Axis axis of rotation(AxisStruct or geom line)
2176 # @param AngleInRadians angle of rotation(in radians)
2177 # @param Copy allows to copy the rotated elements
2178 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2179 if IDsOfElements == []:
2180 IDsOfElements = self.GetElementsId()
2181 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2182 Axis = GetAxisStruct(Axis)
2183 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2185 ## Rotates the object
2186 # @param theObject object to rotate(mesh, submesh, or group)
2187 # @param Axis axis of rotation(AxisStruct or geom line)
2188 # @param AngleInRadians angle of rotation(in radians)
2189 # @param Copy allows to copy the rotated elements
2190 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2191 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2193 ## Find group of nodes close to each other within Tolerance.
2194 # @param Tolerance tolerance value
2195 # @param list of group of nodes
2196 def FindCoincidentNodes (self, Tolerance):
2197 return self.editor.FindCoincidentNodes(Tolerance)
2200 # @param list of group of nodes
2201 def MergeNodes (self, GroupsOfNodes):
2202 self.editor.MergeNodes(GroupsOfNodes)
2204 ## Remove all but one of elements built on the same nodes.
2205 def MergeEqualElements(self):
2206 self.editor.MergeEqualElements()
2209 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2210 FirstNodeID2, SecondNodeID2, LastNodeID2,
2211 CreatePolygons, CreatePolyedrs):
2212 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2213 FirstNodeID2, SecondNodeID2, LastNodeID2,
2214 CreatePolygons, CreatePolyedrs)
2216 ## Sew conform free borders
2217 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2218 FirstNodeID2, SecondNodeID2):
2219 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2220 FirstNodeID2, SecondNodeID2)
2222 ## Sew border to side
2223 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2224 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2225 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2226 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2228 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2229 # merged with nodes of elements of Side2.
2230 # Number of elements in theSide1 and in theSide2 must be
2231 # equal and they should have similar node connectivity.
2232 # The nodes to merge should belong to sides borders and
2233 # the first node should be linked to the second.
2234 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2235 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2236 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2237 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2238 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2239 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2241 ## Set new nodes for given element.
2242 # @param ide the element id
2243 # @param newIDs nodes ids
2244 # @return If number of nodes is not corresponded to type of element - returns false
2245 def ChangeElemNodes(self, ide, newIDs):
2246 return self.editor.ChangeElemNodes(ide, newIDs)
2248 ## If during last operation of MeshEditor some nodes were
2249 # created this method returns list of it's IDs, \n
2250 # if new nodes not created - returns empty list
2251 def GetLastCreatedNodes(self):
2252 return self.editor.GetLastCreatedNodes()
2254 ## If during last operation of MeshEditor some elements were
2255 # created this method returns list of it's IDs, \n
2256 # if new elements not creared - returns empty list
2257 def GetLastCreatedElems(self):
2258 return self.editor.GetLastCreatedElems()