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."
352 ## Private method. Print error message if a hypothesis was not assigned.
353 def TreatHypoStatus(status, hypName, geomName, isAlgo):
355 hypType = "algorithm"
357 hypType = "hypothesis"
359 if status == HYP_UNKNOWN_FATAL :
360 reason = "for unknown reason"
361 elif status == HYP_INCOMPATIBLE :
362 reason = "this hypothesis mismatches algorithm"
363 elif status == HYP_NOTCONFORM :
364 reason = "not conform mesh would be built"
365 elif status == HYP_ALREADY_EXIST :
366 reason = hypType + " of the same dimension already assigned to this shape"
367 elif status == HYP_BAD_DIM :
368 reason = hypType + " mismatches shape"
369 elif status == HYP_CONCURENT :
370 reason = "there are concurrent hypotheses on sub-shapes"
371 elif status == HYP_BAD_SUBSHAPE :
372 reason = "shape is neither the main one, nor its subshape, nor a valid group"
373 elif status == HYP_BAD_GEOMETRY:
374 reason = "geometry mismatches algorithm's expectation"
375 elif status == HYP_HIDDEN_ALGO:
376 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
377 elif status == HYP_HIDING_ALGO:
378 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
381 hypName = '"' + hypName + '"'
382 geomName= '"' + geomName+ '"'
383 if status < HYP_UNKNOWN_FATAL:
384 print hypName, "was assigned to", geomName,"but", reason
386 print hypName, "was not assigned to",geomName,":", reason
391 ## Mother class to define algorithm, recommended to don't use directly.
394 class Mesh_Algorithm:
395 # @class Mesh_Algorithm
396 # @brief Class Mesh_Algorithm
403 ## If the algorithm is global, return 0; \n
404 # else return the submesh associated to this algorithm.
405 def GetSubMesh(self):
408 ## Return the wrapped mesher.
409 def GetAlgorithm(self):
412 ## Get list of hypothesis that can be used with this algorithm
413 def GetCompatibleHypothesis(self):
416 list = self.algo.GetCompatibleHypothesis()
424 def SetName(self, name):
425 SetName(self.algo, name)
429 return self.algo.GetId()
432 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
434 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
439 name = GetName(piece)
444 name = geompy.SubShapeName(geom, piece)
445 geompy.addToStudyInFather(piece, geom, name)
446 self.subm = mesh.mesh.GetSubMesh(geom, hypo)
448 self.algo = smesh.CreateHypothesis(hypo, so)
449 SetName(self.algo, name + "/" + hypo)
450 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
451 TreatHypoStatus( status, hypo, name, 1 )
454 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
455 hypo = smesh.CreateHypothesis(hyp, so)
461 a = a + s + str(args[i])
464 name = GetName(self.geom)
465 SetName(hypo, name + "/" + hyp + a)
466 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
467 TreatHypoStatus( status, hyp, name, 0 )
471 # Public class: Mesh_Segment
472 # --------------------------
474 ## Class to define a segment 1D algorithm for discretization
477 class Mesh_Segment(Mesh_Algorithm):
479 ## Private constructor.
480 def __init__(self, mesh, geom=0):
481 self.Create(mesh, geom, "Regular_1D")
483 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
484 # @param l for the length of segments that cut an edge
485 def LocalLength(self, l):
486 hyp = self.Hypothesis("LocalLength", [l])
490 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
491 # @param n for the number of segments that cut an edge
492 # @param s for the scale factor (optional)
493 def NumberOfSegments(self, n, s=[]):
495 hyp = self.Hypothesis("NumberOfSegments", [n])
497 hyp = self.Hypothesis("NumberOfSegments", [n,s])
498 hyp.SetDistrType( 1 )
499 hyp.SetScaleFactor(s)
500 hyp.SetNumberOfSegments(n)
503 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
504 # @param start for the length of the first segment
505 # @param end for the length of the last segment
506 def Arithmetic1D(self, start, end):
507 hyp = self.Hypothesis("Arithmetic1D", [start, end])
508 hyp.SetLength(start, 1)
509 hyp.SetLength(end , 0)
512 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
513 # @param start for the length of the first segment
514 # @param end for the length of the last segment
515 def StartEndLength(self, start, end):
516 hyp = self.Hypothesis("StartEndLength", [start, end])
517 hyp.SetLength(start, 1)
518 hyp.SetLength(end , 0)
521 ## Define "Deflection1D" hypothesis
522 # @param d for the deflection
523 def Deflection1D(self, d):
524 hyp = self.Hypothesis("Deflection1D", [d])
528 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
529 # the opposite side in the case of quadrangular faces
530 def Propagation(self):
531 return self.Hypothesis("Propagation")
533 ## Define "AutomaticLength" hypothesis
534 # @param fineness for the fineness [0-1]
535 def AutomaticLength(self, fineness=0):
536 hyp = self.Hypothesis("AutomaticLength")
537 hyp.SetFineness( fineness )
540 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
541 # If the 2D mesher sees that all boundary edges are quadratic ones,
542 # it generates quadratic faces, else it generates linear faces using
543 # medium nodes as if they were vertex ones.
544 # The 3D mesher generates quadratic volumes only if all boundary faces
545 # are quadratic ones, else it fails.
546 def QuadraticMesh(self):
547 hyp = self.Hypothesis("QuadraticMesh")
550 # Public class: Mesh_Segment_Python
551 # ---------------------------------
553 ## Class to define a segment 1D algorithm for discretization with python function
556 class Mesh_Segment_Python(Mesh_Segment):
558 ## Private constructor.
559 def __init__(self, mesh, geom=0):
560 import Python1dPlugin
561 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
563 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
564 # @param n for the number of segments that cut an edge
565 # @param func for the python function that calculate the length of all segments
566 def PythonSplit1D(self, n, func):
567 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
568 hyp.SetNumberOfSegments(n)
569 hyp.SetPythonLog10RatioFunction(func)
572 # Public class: Mesh_Triangle
573 # ---------------------------
575 ## Class to define a triangle 2D algorithm
578 class Mesh_Triangle(Mesh_Algorithm):
583 ## Private constructor.
584 def __init__(self, mesh, algoType, geom=0):
585 if algoType == MEFISTO:
586 self.Create(mesh, geom, "MEFISTO_2D")
587 elif algoType == NETGEN:
589 print "Warning: NETGENPlugin module has not been imported."
590 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
591 self.algoType = algoType
593 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
594 # @param area for the maximum area of each triangles
595 def MaxElementArea(self, area):
596 if self.algoType == MEFISTO:
597 hyp = self.Hypothesis("MaxElementArea", [area])
598 hyp.SetMaxElementArea(area)
600 elif self.algoType == NETGEN:
601 print "Netgen 1D-2D algo doesn't support this hypothesis"
604 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
605 def LengthFromEdges(self):
606 if self.algoType == MEFISTO:
607 hyp = self.Hypothesis("LengthFromEdges")
609 elif self.algoType == NETGEN:
610 print "Netgen 1D-2D algo doesn't support this hypothesis"
613 ## Define "Netgen 2D Parameters" hypothesis
614 def Parameters(self):
615 if self.algoType == NETGEN:
616 self.params = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
618 elif self.algoType == MEFISTO:
619 print "Mefisto algo doesn't support this hypothesis"
623 def SetMaxSize(self, theSize):
626 self.params.SetMaxSize(theSize)
628 ## Set SecondOrder flag
629 def SetSecondOrder(seld, theVal):
632 self.params.SetSecondOrder(theVal)
635 def SetOptimize(self, theVal):
638 self.params.SetOptimize(theVal)
641 # @param theFineness is:
642 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
643 def SetFineness(self, theFineness):
646 self.params.SetFineness(theFineness)
649 def SetGrowthRate(self, theRate):
652 self.params.SetGrowthRate(theRate)
655 def SetNbSegPerEdge(self, theVal):
658 self.params.SetNbSegPerEdge(theVal)
660 ## Set NbSegPerRadius
661 def SetNbSegPerRadius(self, theVal):
664 self.params.SetNbSegPerRadius(theVal)
666 ## Set QuadAllowed flag
667 def SetQuadAllowed(self, toAllow):
670 self.params.SetQuadAllowed(toAllow)
673 # Public class: Mesh_Quadrangle
674 # -----------------------------
676 ## Class to define a quadrangle 2D algorithm
679 class Mesh_Quadrangle(Mesh_Algorithm):
681 ## Private constructor.
682 def __init__(self, mesh, geom=0):
683 self.Create(mesh, geom, "Quadrangle_2D")
685 ## Define "QuadranglePreference" hypothesis, forcing construction
686 # of quadrangles if the number of nodes on opposite edges is not the same
687 # in the case where the global number of nodes on edges is even
688 def QuadranglePreference(self):
689 hyp = self.Hypothesis("QuadranglePreference")
692 # Public class: Mesh_Tetrahedron
693 # ------------------------------
695 ## Class to define a tetrahedron 3D algorithm
698 class Mesh_Tetrahedron(Mesh_Algorithm):
703 ## Private constructor.
704 def __init__(self, mesh, algoType, geom=0):
705 if algoType == NETGEN:
706 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
707 elif algoType == GHS3D:
709 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
710 elif algoType == FULL_NETGEN:
712 print "Warning: NETGENPlugin module has not been imported."
713 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
714 self.algoType = algoType
716 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
717 # @param vol for the maximum volume of each tetrahedral
718 def MaxElementVolume(self, vol):
719 hyp = self.Hypothesis("MaxElementVolume", [vol])
720 hyp.SetMaxElementVolume(vol)
723 ## Define "Netgen 3D Parameters" hypothesis
724 def Parameters(self):
725 if (self.algoType == FULL_NETGEN):
726 self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
729 print "Algo doesn't support this hypothesis"
733 def SetMaxSize(self, theSize):
736 self.params.SetMaxSize(theSize)
738 ## Set SecondOrder flag
739 def SetSecondOrder(self, theVal):
742 self.params.SetSecondOrder(theVal)
745 def SetOptimize(self, theVal):
748 self.params.SetOptimize(theVal)
751 # @param theFineness is:
752 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
753 def SetFineness(self, theFineness):
756 self.params.SetFineness(theFineness)
759 def SetGrowthRate(self, theRate):
762 self.params.SetGrowthRate(theRate)
765 def SetNbSegPerEdge(self, theVal):
768 self.params.SetNbSegPerEdge(theVal)
770 ## Set NbSegPerRadius
771 def SetNbSegPerRadius(self, theVal):
774 self.params.SetNbSegPerRadius(theVal)
776 # Public class: Mesh_Hexahedron
777 # ------------------------------
779 ## Class to define a hexahedron 3D algorithm
782 class Mesh_Hexahedron(Mesh_Algorithm):
784 ## Private constructor.
785 def __init__(self, mesh, geom=0):
786 self.Create(mesh, geom, "Hexa_3D")
788 # Deprecated, only for compatibility!
789 # Public class: Mesh_Netgen
790 # ------------------------------
792 ## Class to define a NETGEN-based 2D or 3D algorithm
793 # that need no discrete boundary (i.e. independent)
795 # This class is deprecated, only for compatibility!
798 class Mesh_Netgen(Mesh_Algorithm):
802 ## Private constructor.
803 def __init__(self, mesh, is3D, geom=0):
805 print "Warning: NETGENPlugin module has not been imported."
809 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
811 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
813 ## Define hypothesis containing parameters of the algorithm
814 def Parameters(self):
816 hyp = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so")
818 hyp = self.Hypothesis("NETGEN_Parameters_2D", [], "libNETGENEngine.so")
821 # Public class: Mesh_Projection1D
822 # ------------------------------
824 ## Class to define a projection 1D algorithm
827 class Mesh_Projection1D(Mesh_Algorithm):
829 ## Private constructor.
830 def __init__(self, mesh, geom=0):
831 self.Create(mesh, geom, "Projection_1D")
833 ## Define "Source Edge" hypothesis, specifying a meshed edge to
834 # take a mesh pattern from, and optionally association of vertices
835 # between the source edge and a target one (where a hipothesis is assigned to)
836 # @param edge to take nodes distribution from
837 # @param mesh to take nodes distribution from (optional)
838 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
839 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
840 # to associate with \a srcV (optional)
841 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None):
842 hyp = self.Hypothesis("ProjectionSource1D")
843 hyp.SetSourceEdge( edge )
844 if not mesh is None and isinstance(mesh, Mesh):
845 mesh = mesh.GetMesh()
846 hyp.SetSourceMesh( mesh )
847 hyp.SetVertexAssociation( srcV, tgtV )
851 # Public class: Mesh_Projection2D
852 # ------------------------------
854 ## Class to define a projection 2D algorithm
857 class Mesh_Projection2D(Mesh_Algorithm):
859 ## Private constructor.
860 def __init__(self, mesh, geom=0):
861 self.Create(mesh, geom, "Projection_2D")
863 ## Define "Source Face" hypothesis, specifying a meshed face to
864 # take a mesh pattern from, and optionally association of vertices
865 # between the source face and a target one (where a hipothesis is assigned to)
866 # @param face to take mesh pattern from
867 # @param mesh to take mesh pattern from (optional)
868 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
869 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
870 # to associate with \a srcV1 (optional)
871 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
872 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
873 # to associate with \a srcV2 (optional)
875 # Note: association vertices must belong to one edge of a face
876 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None, srcV2=None, tgtV2=None):
877 hyp = self.Hypothesis("ProjectionSource2D")
878 hyp.SetSourceFace( face )
879 if not mesh is None and isinstance(mesh, Mesh):
880 mesh = mesh.GetMesh()
881 hyp.SetSourceMesh( mesh )
882 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
885 # Public class: Mesh_Projection3D
886 # ------------------------------
888 ## Class to define a projection 3D algorithm
891 class Mesh_Projection3D(Mesh_Algorithm):
893 ## Private constructor.
894 def __init__(self, mesh, geom=0):
895 self.Create(mesh, geom, "Projection_3D")
897 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
898 # take a mesh pattern from, and optionally association of vertices
899 # between the source solid and a target one (where a hipothesis is assigned to)
900 # @param solid to take mesh pattern from
901 # @param mesh to take mesh pattern from (optional)
902 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
903 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
904 # to associate with \a srcV1 (optional)
905 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
906 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
907 # to associate with \a srcV2 (optional)
909 # Note: association vertices must belong to one edge of a solid
910 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0, srcV2=0, tgtV2=0):
911 hyp = self.Hypothesis("ProjectionSource3D")
912 hyp.SetSource3DShape( solid )
913 if not mesh is None and isinstance(mesh, Mesh):
914 mesh = mesh.GetMesh()
915 hyp.SetSourceMesh( mesh )
916 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
920 # Public class: Mesh_Prism
921 # ------------------------
923 ## Class to define a Prism 3D algorithm
926 class Mesh_Prism3D(Mesh_Algorithm):
928 ## Private constructor.
929 def __init__(self, mesh, geom=0):
930 self.Create(mesh, geom, "Prism_3D")
932 # Public class: Mesh_RadialPrism
933 # -------------------------------
935 ## Class to define a Radial Prism 3D algorithm
938 class Mesh_RadialPrism3D(Mesh_Algorithm):
940 ## Private constructor.
941 def __init__(self, mesh, geom=0):
942 self.Create(mesh, geom, "RadialPrism_3D")
943 self.distribHyp = self.Hypothesis( "LayerDistribution" )
946 ## Return 3D hypothesis holding the 1D one
947 def Get3DHypothesis(self):
948 return self.distribHyp
950 ## Private method creating 1D hypothes and storing it in the LayerDistribution
951 # hypothes. Returns the created hypothes
952 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
953 if not self.nbLayers is None:
954 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
955 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
956 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
957 hyp = smesh.CreateHypothesis(hypType, so)
958 SetCurrentStudy( study ) # anable publishing
959 self.distribHyp.SetLayerDistribution( hyp )
962 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
963 # prisms to build between the inner and outer shells
964 def NumberOfLayers(self, n ):
965 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
966 self.nbLayers = self.Hypothesis("NumberOfLayers")
967 self.nbLayers.SetNumberOfLayers( n )
970 ## Define "LocalLength" hypothesis, specifying segment length
971 # to build between the inner and outer shells
972 # @param l for the length of segments
973 def LocalLength(self, l):
974 hyp = self.OwnHypothesis("LocalLength", [l])
978 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
979 # prisms to build between the inner and outer shells
980 # @param n for the number of segments
981 # @param s for the scale factor (optional)
982 def NumberOfSegments(self, n, s=[]):
984 hyp = self.OwnHypothesis("NumberOfSegments", [n])
986 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
987 hyp.SetDistrType( 1 )
988 hyp.SetScaleFactor(s)
989 hyp.SetNumberOfSegments(n)
992 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
993 # to build between the inner and outer shells as arithmetic length increasing
994 # @param start for the length of the first segment
995 # @param end for the length of the last segment
996 def Arithmetic1D(self, start, end):
997 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
998 hyp.SetLength(start, 1)
999 hyp.SetLength(end , 0)
1002 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1003 # to build between the inner and outer shells as geometric length increasing
1004 # @param start for the length of the first segment
1005 # @param end for the length of the last segment
1006 def StartEndLength(self, start, end):
1007 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1008 hyp.SetLength(start, 1)
1009 hyp.SetLength(end , 0)
1012 ## Define "AutomaticLength" hypothesis, specifying number of segments
1013 # to build between the inner and outer shells
1014 # @param fineness for the fineness [0-1]
1015 def AutomaticLength(self, fineness=0):
1016 hyp = self.OwnHypothesis("AutomaticLength")
1017 hyp.SetFineness( fineness )
1021 # Public class: Mesh
1022 # ==================
1024 ## Class to define a mesh
1026 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1036 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1037 # sets GUI name of this mesh to \a name.
1038 # @param obj Shape to be meshed or SMESH_Mesh object
1039 # @param name Study name of the mesh
1040 def __init__(self, obj=0, name=0):
1044 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1046 self.mesh = smesh.CreateMesh(self.geom)
1047 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1050 self.mesh = smesh.CreateEmptyMesh()
1052 SetName(self.mesh, name)
1054 SetName(self.mesh, GetName(obj))
1056 self.editor = self.mesh.GetMeshEditor()
1058 ## Method that inits the Mesh object from SMESH_Mesh interface
1059 # @param theMesh is SMESH_Mesh object
1060 def SetMesh(self, theMesh):
1062 self.geom = self.mesh.GetShapeToMesh()
1064 ## Method that returns the mesh
1065 # @return SMESH_Mesh object
1071 name = GetName(self.GetMesh())
1075 def SetName(self, name):
1076 SetName(self.GetMesh(), name)
1078 ## Get the subMesh object associated to a subShape. The subMesh object
1079 # gives access to nodes and elements IDs.
1080 # \n SubMesh will be used instead of SubShape in a next idl version to
1081 # adress a specific subMesh...
1082 def GetSubMesh(self, theSubObject, name):
1083 submesh = self.mesh.GetSubMesh(theSubObject, name)
1086 ## Method that returns the shape associated to the mesh
1087 # @return GEOM_Object
1091 ## Method that associates given shape to the mesh(entails the mesh recreation)
1092 # @param geom shape to be meshed(GEOM_Object)
1093 def SetShape(self, geom):
1094 self.mesh = smesh.CreateMesh(geom)
1096 ## Return true if hypotheses are defined well
1097 # @param theMesh is an instance of Mesh class
1098 # @param theSubObject subshape of a mesh shape
1099 def IsReadyToCompute(self, theSubObject):
1100 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1102 ## Return errors of hypotheses definintion
1103 # error list is empty if everything is OK
1104 # @param theMesh is an instance of Mesh class
1105 # @param theSubObject subshape of a mesh shape
1106 # @return a list of errors
1107 def GetAlgoState(self, theSubObject):
1108 return smesh.GetAlgoState(self.mesh, theSubObject)
1110 ## Return geometrical object the given element is built on.
1111 # The returned geometrical object, if not nil, is either found in the
1112 # study or is published by this method with the given name
1113 # @param theMesh is an instance of Mesh class
1114 # @param theElementID an id of the mesh element
1115 # @param theGeomName user defined name of geometrical object
1116 # @return GEOM::GEOM_Object instance
1117 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1118 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1120 ## Returns mesh dimension depending on shape one
1121 def MeshDimension(self):
1122 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1123 if len( shells ) > 0 :
1125 elif geompy.NumberOfFaces( self.geom ) > 0 :
1127 elif geompy.NumberOfEdges( self.geom ) > 0 :
1133 ## Creates a segment discretization 1D algorithm.
1134 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1135 # If the optional \a geom parameter is not sets, this algorithm is global.
1136 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1137 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1138 # @param geom If defined, subshape to be meshed
1139 def Segment(self, algo=REGULAR, geom=0):
1140 ## if Segment(geom) is called by mistake
1141 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1142 algo, geom = geom, algo
1145 return Mesh_Segment(self, geom)
1146 elif algo == PYTHON:
1147 return Mesh_Segment_Python(self, geom)
1149 return Mesh_Segment(self, geom)
1151 ## Creates a triangle 2D algorithm for faces.
1152 # If the optional \a geom parameter is not sets, this algorithm is global.
1153 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1154 # @param algo values are: smesh.MEFISTO or smesh.NETGEN
1155 # @param geom If defined, subshape to be meshed
1156 def Triangle(self, algo=MEFISTO, geom=0):
1157 ## if Triangle(geom) is called by mistake
1158 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1162 return Mesh_Triangle(self, algo, geom)
1164 ## Creates a quadrangle 2D algorithm for faces.
1165 # If the optional \a geom parameter is not sets, this algorithm is global.
1166 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1167 # @param geom If defined, subshape to be meshed
1168 def Quadrangle(self, geom=0):
1169 return Mesh_Quadrangle(self, geom)
1171 ## Creates a tetrahedron 3D algorithm for solids.
1172 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1173 # If the optional \a geom parameter is not sets, this algorithm is global.
1174 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1175 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1176 # @param geom If defined, subshape to be meshed
1177 def Tetrahedron(self, algo=NETGEN, geom=0):
1178 ## if Tetrahedron(geom) is called by mistake
1179 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1180 algo, geom = geom, algo
1182 return Mesh_Tetrahedron(self, algo, geom)
1184 ## Creates a hexahedron 3D algorithm for solids.
1185 # If the optional \a geom parameter is not sets, this algorithm is global.
1186 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1187 # @param geom If defined, subshape to be meshed
1188 def Hexahedron(self, geom=0):
1189 return Mesh_Hexahedron(self, geom)
1191 ## Deprecated, only for compatibility!
1192 def Netgen(self, is3D, geom=0):
1193 return Mesh_Netgen(self, is3D, geom)
1195 ## Creates a projection 1D algorithm for edges.
1196 # If the optional \a geom parameter is not sets, this algorithm is global.
1197 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1198 # @param geom If defined, subshape to be meshed
1199 def Projection1D(self, geom=0):
1200 return Mesh_Projection1D(self, geom)
1202 ## Creates a projection 2D algorithm for faces.
1203 # If the optional \a geom parameter is not sets, this algorithm is global.
1204 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1205 # @param geom If defined, subshape to be meshed
1206 def Projection2D(self, geom=0):
1207 return Mesh_Projection2D(self, geom)
1209 ## Creates a projection 3D algorithm for solids.
1210 # If the optional \a geom parameter is not sets, this algorithm is global.
1211 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1212 # @param geom If defined, subshape to be meshed
1213 def Projection3D(self, geom=0):
1214 return Mesh_Projection3D(self, geom)
1216 ## Creates a Prism 3D or RadialPrism 3D algorithm for solids.
1217 # If the optional \a geom parameter is not sets, this algorithm is global.
1218 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1219 # @param geom If defined, subshape to be meshed
1220 def Prism(self, geom=0):
1224 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1225 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1226 if nbSolids == 0 or nbSolids == nbShells:
1227 return Mesh_Prism3D(self, geom)
1228 return Mesh_RadialPrism3D(self, geom)
1230 ## Compute the mesh and return the status of the computation
1231 def Compute(self, geom=0):
1232 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1234 print "Compute impossible: mesh is not constructed on geom shape."
1238 ok = smesh.Compute(self.mesh, geom)
1240 errors = smesh.GetAlgoState( self.mesh, geom )
1243 if err.isGlobalAlgo:
1248 dim = str(err.algoDim)
1249 if err.name == MISSING_ALGO:
1250 reason = glob + dim + "D algorithm is missing"
1251 elif err.name == MISSING_HYPO:
1252 name = '"' + err.algoName + '"'
1253 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1254 elif err.name == NOT_CONFORM_MESH:
1255 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1256 elif err.name == BAD_PARAM_VALUE:
1257 name = '"' + err.algoName + '"'
1258 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1259 " has a bad parameter value"
1261 reason = "For unknown reason."+\
1262 " Revise Mesh.Compute() implementation in smesh.py!"
1264 if allReasons != "":
1267 allReasons += reason
1269 if allReasons != "":
1270 print '"' + GetName(self.mesh) + '"',"not computed:"
1274 if salome.sg.hasDesktop():
1275 smeshgui = salome.ImportComponentGUI("SMESH")
1276 smeshgui.Init(salome.myStudyId)
1277 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok )
1278 salome.sg.updateObjBrowser(1)
1282 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1283 # The parameter \a fineness [0,-1] defines mesh fineness
1284 def AutomaticTetrahedralization(self, fineness=0):
1285 dim = self.MeshDimension()
1287 self.RemoveGlobalHypotheses()
1288 self.Segment().AutomaticLength(fineness)
1290 self.Triangle().LengthFromEdges()
1293 self.Tetrahedron(NETGEN)
1295 return self.Compute()
1297 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1298 # The parameter \a fineness [0,-1] defines mesh fineness
1299 def AutomaticHexahedralization(self, fineness=0):
1300 dim = self.MeshDimension()
1302 self.RemoveGlobalHypotheses()
1303 self.Segment().AutomaticLength(fineness)
1310 return self.Compute()
1312 ## Get the list of hypothesis added on a geom
1313 # @param geom is subhape of mesh geometry
1314 def GetHypothesisList(self, geom):
1315 return self.mesh.GetHypothesisList( geom )
1317 ## Removes all global hypotheses
1318 def RemoveGlobalHypotheses(self):
1319 current_hyps = self.mesh.GetHypothesisList( self.geom )
1320 for hyp in current_hyps:
1321 self.mesh.RemoveHypothesis( self.geom, hyp )
1325 ## Create a mesh group based on geometric object \a grp
1326 # and give a \a name, \n if this parameter is not defined
1327 # the name is the same as the geometric group name \n
1328 # Note: Works like GroupOnGeom().
1329 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1330 # @param name is the name of the mesh group
1331 # @return SMESH_GroupOnGeom
1332 def Group(self, grp, name=""):
1333 return self.GroupOnGeom(grp, name)
1335 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1336 # Export the mesh in a file with the MED format and choice the \a version of MED format
1337 # @param f is the file name
1338 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1339 def ExportToMED(self, f, version, opt=0):
1340 self.mesh.ExportToMED(f, opt, version)
1342 ## Export the mesh in a file with the MED format
1343 # @param f is the file name
1344 # @param auto_groups boolean parameter for creating/not creating
1345 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1346 # the typical use is auto_groups=false.
1347 # @param version MED format version(MED_V2_1 or MED_V2_2)
1348 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1349 self.mesh.ExportToMED(f, auto_groups, version)
1351 ## Export the mesh in a file with the DAT format
1352 # @param f is the file name
1353 def ExportDAT(self, f):
1354 self.mesh.ExportDAT(f)
1356 ## Export the mesh in a file with the UNV format
1357 # @param f is the file name
1358 def ExportUNV(self, f):
1359 self.mesh.ExportUNV(f)
1361 ## Export the mesh in a file with the STL format
1362 # @param f is the file name
1363 # @param ascii defined the kind of file contents
1364 def ExportSTL(self, f, ascii=1):
1365 self.mesh.ExportSTL(f, ascii)
1368 # Operations with groups:
1369 # ----------------------
1371 ## Creates an empty mesh group
1372 # @param elementType is the type of elements in the group
1373 # @param name is the name of the mesh group
1374 # @return SMESH_Group
1375 def CreateEmptyGroup(self, elementType, name):
1376 return self.mesh.CreateGroup(elementType, name)
1378 ## Creates a mesh group based on geometric object \a grp
1379 # and give a \a name, \n if this parameter is not defined
1380 # the name is the same as the geometric group name
1381 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1382 # @param name is the name of the mesh group
1383 # @return SMESH_GroupOnGeom
1384 def GroupOnGeom(self, grp, name="", type=None):
1386 name = grp.GetName()
1389 tgeo = str(grp.GetShapeType())
1390 if tgeo == "VERTEX":
1392 elif tgeo == "EDGE":
1394 elif tgeo == "FACE":
1396 elif tgeo == "SOLID":
1398 elif tgeo == "SHELL":
1400 elif tgeo == "COMPOUND":
1401 if len( geompy.GetObjectIDs( grp )) == 0:
1402 print "Mesh.Group: empty geometric group", GetName( grp )
1404 tgeo = geompy.GetType(grp)
1405 if tgeo == geompy.ShapeType["VERTEX"]:
1407 elif tgeo == geompy.ShapeType["EDGE"]:
1409 elif tgeo == geompy.ShapeType["FACE"]:
1411 elif tgeo == geompy.ShapeType["SOLID"]:
1415 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1418 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1420 ## Create a mesh group by the given ids of elements
1421 # @param groupName is the name of the mesh group
1422 # @param elementType is the type of elements in the group
1423 # @param elemIDs is the list of ids
1424 # @return SMESH_Group
1425 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1426 group = self.mesh.CreateGroup(elementType, groupName)
1430 ## Create a mesh group by the given conditions
1431 # @param groupName is the name of the mesh group
1432 # @param elementType is the type of elements in the group
1433 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1434 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1435 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1436 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1437 # @return SMESH_Group
1441 CritType=FT_Undefined,
1444 UnaryOp=FT_Undefined):
1445 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1446 group = self.MakeGroupByCriterion(groupName, aCriterion)
1449 ## Create a mesh group by the given criterion
1450 # @param groupName is the name of the mesh group
1451 # @param Criterion is the instance of Criterion class
1452 # @return SMESH_Group
1453 def MakeGroupByCriterion(self, groupName, Criterion):
1454 aFilterMgr = smesh.CreateFilterManager()
1455 aFilter = aFilterMgr.CreateFilter()
1457 aCriteria.append(Criterion)
1458 aFilter.SetCriteria(aCriteria)
1459 group = self.MakeGroupByFilter(groupName, aFilter)
1462 ## Create a mesh group by the given criteria(list of criterions)
1463 # @param groupName is the name of the mesh group
1464 # @param Criteria is the list of criterions
1465 # @return SMESH_Group
1466 def MakeGroupByCriteria(self, groupName, theCriteria):
1467 aFilterMgr = smesh.CreateFilterManager()
1468 aFilter = aFilterMgr.CreateFilter()
1469 aFilter.SetCriteria(theCriteria)
1470 group = self.MakeGroupByFilter(groupName, aFilter)
1473 ## Create a mesh group by the given filter
1474 # @param groupName is the name of the mesh group
1475 # @param Criterion is the instance of Filter class
1476 # @return SMESH_Group
1477 def MakeGroupByFilter(self, groupName, theFilter):
1478 anIds = theFilter.GetElementsId(self.mesh)
1479 anElemType = theFilter.GetElementType()
1480 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1483 ## Pass mesh elements through the given filter and return ids
1484 # @param theFilter is SMESH_Filter
1485 # @return list of ids
1486 def GetIdsFromFilter(self, theFilter):
1487 return theFilter.GetElementsId(self.mesh)
1489 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1490 # Returns list of special structures(borders).
1491 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1492 def GetFreeBorders(self):
1493 aFilterMgr = smesh.CreateFilterManager()
1494 aPredicate = aFilterMgr.CreateFreeEdges()
1495 aPredicate.SetMesh(self.mesh)
1496 aBorders = aPredicate.GetBorders()
1500 def RemoveGroup(self, group):
1501 self.mesh.RemoveGroup(group)
1503 ## Remove group with its contents
1504 def RemoveGroupWithContents(self, group):
1505 self.mesh.RemoveGroupWithContents(group)
1507 ## Get the list of groups existing in the mesh
1508 def GetGroups(self):
1509 return self.mesh.GetGroups()
1511 ## Get the list of names of groups existing in the mesh
1512 def GetGroupNames(self):
1513 groups = self.GetGroups()
1515 for group in groups:
1516 names.append(group.GetName())
1519 ## Union of two groups
1520 # New group is created. All mesh elements that are
1521 # present in initial groups are added to the new one
1522 def UnionGroups(self, group1, group2, name):
1523 return self.mesh.UnionGroups(group1, group2, name)
1525 ## Intersection of two groups
1526 # New group is created. All mesh elements that are
1527 # present in both initial groups are added to the new one.
1528 def IntersectGroups(self, group1, group2, name):
1529 return self.mesh.IntersectGroups(group1, group2, name)
1531 ## Cut of two groups
1532 # New group is created. All mesh elements that are present in
1533 # main group but do not present in tool group are added to the new one
1534 def CutGroups(self, mainGroup, toolGroup, name):
1535 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1538 # Get some info about mesh:
1539 # ------------------------
1541 ## Get the log of nodes and elements added or removed since previous
1543 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1544 # @return list of log_block structures:
1549 def GetLog(self, clearAfterGet):
1550 return self.mesh.GetLog(clearAfterGet)
1552 ## Clear the log of nodes and elements added or removed since previous
1553 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1555 self.mesh.ClearLog()
1557 ## Get the internal Id
1559 return self.mesh.GetId()
1562 def GetStudyId(self):
1563 return self.mesh.GetStudyId()
1565 ## Check group names for duplications.
1566 # Consider maximum group name length stored in MED file.
1567 def HasDuplicatedGroupNamesMED(self):
1568 return self.mesh.GetStudyId()
1570 ## Obtain instance of SMESH_MeshEditor
1571 def GetMeshEditor(self):
1572 return self.mesh.GetMeshEditor()
1575 def GetMEDMesh(self):
1576 return self.mesh.GetMEDMesh()
1579 # Get informations about mesh contents:
1580 # ------------------------------------
1582 ## Returns number of nodes in mesh
1584 return self.mesh.NbNodes()
1586 ## Returns number of elements in mesh
1587 def NbElements(self):
1588 return self.mesh.NbElements()
1590 ## Returns number of edges in mesh
1592 return self.mesh.NbEdges()
1594 ## Returns number of edges with given order in mesh
1595 # @param elementOrder is order of elements:
1596 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1597 def NbEdgesOfOrder(self, elementOrder):
1598 return self.mesh.NbEdgesOfOrder(elementOrder)
1600 ## Returns number of faces in mesh
1602 return self.mesh.NbFaces()
1604 ## Returns number of faces with given order in mesh
1605 # @param elementOrder is order of elements:
1606 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1607 def NbFacesOfOrder(self, elementOrder):
1608 return self.mesh.NbFacesOfOrder(elementOrder)
1610 ## Returns number of triangles in mesh
1611 def NbTriangles(self):
1612 return self.mesh.NbTriangles()
1614 ## Returns number of triangles with given order in mesh
1615 # @param elementOrder is order of elements:
1616 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1617 def NbTrianglesOfOrder(self, elementOrder):
1618 return self.mesh.NbTrianglesOfOrder(elementOrder)
1620 ## Returns number of quadrangles in mesh
1621 def NbQuadrangles(self):
1622 return self.mesh.NbQuadrangles()
1624 ## Returns number of quadrangles with given order in mesh
1625 # @param elementOrder is order of elements:
1626 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1627 def NbQuadranglesOfOrder(self, elementOrder):
1628 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1630 ## Returns number of polygons in mesh
1631 def NbPolygons(self):
1632 return self.mesh.NbPolygons()
1634 ## Returns number of volumes in mesh
1635 def NbVolumes(self):
1636 return self.mesh.NbVolumes()
1638 ## Returns number of volumes with given order in mesh
1639 # @param elementOrder is order of elements:
1640 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1641 def NbVolumesOfOrder(self, elementOrder):
1642 return self.mesh.NbVolumesOfOrder(elementOrder)
1644 ## Returns number of tetrahedrons in mesh
1646 return self.mesh.NbTetras()
1648 ## Returns number of tetrahedrons with given order in mesh
1649 # @param elementOrder is order of elements:
1650 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1651 def NbTetrasOfOrder(self, elementOrder):
1652 return self.mesh.NbTetrasOfOrder(elementOrder)
1654 ## Returns number of hexahedrons in mesh
1656 return self.mesh.NbHexas()
1658 ## Returns number of hexahedrons with given order in mesh
1659 # @param elementOrder is order of elements:
1660 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1661 def NbHexasOfOrder(self, elementOrder):
1662 return self.mesh.NbHexasOfOrder(elementOrder)
1664 ## Returns number of pyramids in mesh
1665 def NbPyramids(self):
1666 return self.mesh.NbPyramids()
1668 ## Returns number of pyramids with given order in mesh
1669 # @param elementOrder is order of elements:
1670 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1671 def NbPyramidsOfOrder(self, elementOrder):
1672 return self.mesh.NbPyramidsOfOrder(elementOrder)
1674 ## Returns number of prisms in mesh
1676 return self.mesh.NbPrisms()
1678 ## Returns number of prisms with given order in mesh
1679 # @param elementOrder is order of elements:
1680 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1681 def NbPrismsOfOrder(self, elementOrder):
1682 return self.mesh.NbPrismsOfOrder(elementOrder)
1684 ## Returns number of polyhedrons in mesh
1685 def NbPolyhedrons(self):
1686 return self.mesh.NbPolyhedrons()
1688 ## Returns number of submeshes in mesh
1689 def NbSubMesh(self):
1690 return self.mesh.NbSubMesh()
1692 ## Returns list of mesh elements ids
1693 def GetElementsId(self):
1694 return self.mesh.GetElementsId()
1696 ## Returns list of ids of mesh elements with given type
1697 # @param elementType is required type of elements
1698 def GetElementsByType(self, elementType):
1699 return self.mesh.GetElementsByType(elementType)
1701 ## Returns list of mesh nodes ids
1702 def GetNodesId(self):
1703 return self.mesh.GetNodesId()
1705 # Get informations about mesh elements:
1706 # ------------------------------------
1708 ## Returns type of mesh element
1709 def GetElementType(self, id, iselem):
1710 return self.mesh.GetElementType(id, iselem)
1712 ## Returns list of submesh elements ids
1713 # @param shapeID is geom object(subshape) IOR
1714 def GetSubMeshElementsId(self, shapeID):
1715 return self.mesh.GetSubMeshElementsId(shapeID)
1717 ## Returns list of submesh nodes ids
1718 # @param shapeID is geom object(subshape) IOR
1719 def GetSubMeshNodesId(self, shapeID, all):
1720 return self.mesh.GetSubMeshNodesId(shapeID, all)
1722 ## Returns list of ids of submesh elements with given type
1723 # @param shapeID is geom object(subshape) IOR
1724 def GetSubMeshElementType(self, shapeID):
1725 return self.mesh.GetSubMeshElementType(shapeID)
1727 ## Get mesh description
1729 return self.mesh.Dump()
1732 # Get information about nodes and elements of mesh by its ids:
1733 # -----------------------------------------------------------
1735 ## Get XYZ coordinates of node as list of double
1736 # \n If there is not node for given ID - returns empty list
1737 def GetNodeXYZ(self, id):
1738 return self.mesh.GetNodeXYZ(id)
1740 ## For given node returns list of IDs of inverse elements
1741 # \n If there is not node for given ID - returns empty list
1742 def GetNodeInverseElements(self, id):
1743 return self.mesh.GetNodeInverseElements(id)
1745 ## If given element is node returns IDs of shape from position
1746 # \n If there is not node for given ID - returns -1
1747 def GetShapeID(self, id):
1748 return self.mesh.GetShapeID(id)
1750 ## For given element returns ID of result shape after
1751 # FindShape() from SMESH_MeshEditor
1752 # \n If there is not element for given ID - returns -1
1753 def GetShapeIDForElem(id):
1754 return self.mesh.GetShapeIDForElem(id)
1756 ## Returns number of nodes for given element
1757 # \n If there is not element for given ID - returns -1
1758 def GetElemNbNodes(self, id):
1759 return self.mesh.GetElemNbNodes(id)
1761 ## Returns ID of node by given index for given element
1762 # \n If there is not element for given ID - returns -1
1763 # \n If there is not node for given index - returns -2
1764 def GetElemNode(self, id, index):
1765 return self.mesh.GetElemNode(id, index)
1767 ## Returns true if given node is medium node
1768 # in given quadratic element
1769 def IsMediumNode(self, elementID, nodeID):
1770 return self.mesh.IsMediumNode(elementID, nodeID)
1772 ## Returns true if given node is medium node
1773 # in one of quadratic elements
1774 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
1775 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
1777 ## Returns number of edges for given element
1778 def ElemNbEdges(self, id):
1779 return self.mesh.ElemNbEdges(id)
1781 ## Returns number of faces for given element
1782 def ElemNbFaces(self, id):
1783 return self.mesh.ElemNbFaces(id)
1785 ## Returns true if given element is polygon
1786 def IsPoly(self, id):
1787 return self.mesh.IsPoly(id)
1789 ## Returns true if given element is quadratic
1790 def IsQuadratic(self, id):
1791 return self.mesh.IsQuadratic(id)
1793 ## Returns XYZ coordinates of bary center for given element
1795 # \n If there is not element for given ID - returns empty list
1796 def BaryCenter(self, id):
1797 return self.mesh.BaryCenter(id)
1800 # Mesh edition (SMESH_MeshEditor functionality):
1801 # ---------------------------------------------
1803 ## Removes elements from mesh by ids
1804 # @param IDsOfElements is list of ids of elements to remove
1805 def RemoveElements(self, IDsOfElements):
1806 return self.editor.RemoveElements(IDsOfElements)
1808 ## Removes nodes from mesh by ids
1809 # @param IDsOfNodes is list of ids of nodes to remove
1810 def RemoveNodes(self, IDsOfNodes):
1811 return self.editor.RemoveNodes(IDsOfNodes)
1813 ## Add node to mesh by coordinates
1814 def AddNode(self, x, y, z):
1815 return self.editor.AddNode( x, y, z)
1818 ## Create edge both similar and quadratic (this is determed
1819 # by number of given nodes).
1820 # @param IdsOfNodes List of node IDs for creation of element.
1821 # Needed order of nodes in this list corresponds to description
1822 # of MED. \n This description is located by the following link:
1823 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1824 def AddEdge(self, IDsOfNodes):
1825 return self.editor.AddEdge(IDsOfNodes)
1827 ## Create face both similar and quadratic (this is determed
1828 # by number of given nodes).
1829 # @param IdsOfNodes List of node IDs for creation of element.
1830 # Needed order of nodes in this list corresponds to description
1831 # of MED. \n This description is located by the following link:
1832 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1833 def AddFace(self, IDsOfNodes):
1834 return self.editor.AddFace(IDsOfNodes)
1836 ## Add polygonal face to mesh by list of nodes ids
1837 def AddPolygonalFace(self, IdsOfNodes):
1838 return self.editor.AddPolygonalFace(IdsOfNodes)
1840 ## Create volume both similar and quadratic (this is determed
1841 # by number of given nodes).
1842 # @param IdsOfNodes List of node IDs for creation of element.
1843 # Needed order of nodes in this list corresponds to description
1844 # of MED. \n This description is located by the following link:
1845 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
1846 def AddVolume(self, IDsOfNodes):
1847 return self.editor.AddVolume(IDsOfNodes)
1849 ## Create volume of many faces, giving nodes for each face.
1850 # @param IdsOfNodes List of node IDs for volume creation face by face.
1851 # @param Quantities List of integer values, Quantities[i]
1852 # gives quantity of nodes in face number i.
1853 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
1854 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
1856 ## Create volume of many faces, giving IDs of existing faces.
1857 # @param IdsOfFaces List of face IDs for volume creation.
1859 # Note: The created volume will refer only to nodes
1860 # of the given faces, not to the faces itself.
1861 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
1862 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
1864 ## Move node with given id
1865 # @param NodeID id of the node
1866 # @param x displacing along the X axis
1867 # @param y displacing along the Y axis
1868 # @param z displacing along the Z axis
1869 def MoveNode(self, NodeID, x, y, z):
1870 return self.editor.MoveNode(NodeID, x, y, z)
1872 ## Replace two neighbour triangles sharing Node1-Node2 link
1873 # with ones built on the same 4 nodes but having other common link.
1874 # @param NodeID1 first node id
1875 # @param NodeID2 second node id
1876 # @return false if proper faces not found
1877 def InverseDiag(self, NodeID1, NodeID2):
1878 return self.editor.InverseDiag(NodeID1, NodeID2)
1880 ## Replace two neighbour triangles sharing Node1-Node2 link
1881 # with a quadrangle built on the same 4 nodes.
1882 # @param NodeID1 first node id
1883 # @param NodeID2 second node id
1884 # @return false if proper faces not found
1885 def DeleteDiag(self, NodeID1, NodeID2):
1886 return self.editor.DeleteDiag(NodeID1, NodeID2)
1888 ## Reorient elements by ids
1889 # @param IDsOfElements if undefined reorient all mesh elements
1890 def Reorient(self, IDsOfElements=None):
1891 if IDsOfElements == None:
1892 IDsOfElements = self.GetElementsId()
1893 return self.editor.Reorient(IDsOfElements)
1895 ## Reorient all elements of the object
1896 # @param theObject is mesh, submesh or group
1897 def ReorientObject(self, theObject):
1898 return self.editor.ReorientObject(theObject)
1900 ## Fuse neighbour triangles into quadrangles.
1901 # @param IDsOfElements The triangles to be fused,
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 TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
1907 if IDsOfElements == []:
1908 IDsOfElements = self.GetElementsId()
1909 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
1911 ## Fuse neighbour triangles of the object into quadrangles
1912 # @param theObject is mesh, submesh or group
1913 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
1914 # @param MaxAngle is a max angle between element normals at which fusion
1915 # is still performed; theMaxAngle is mesured in radians.
1916 # @return TRUE in case of success, FALSE otherwise.
1917 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
1918 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
1920 ## Split quadrangles into triangles.
1921 # @param IDsOfElements the faces to be splitted.
1922 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1923 # @param @return TRUE in case of success, FALSE otherwise.
1924 def QuadToTri (self, IDsOfElements, theCriterion):
1925 if IDsOfElements == []:
1926 IDsOfElements = self.GetElementsId()
1927 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
1929 ## Split quadrangles into triangles.
1930 # @param theObject object to taking list of elements from, is mesh, submesh or group
1931 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
1932 def QuadToTriObject (self, theObject, theCriterion):
1933 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
1935 ## Split quadrangles into triangles.
1936 # @param theElems The faces to be splitted
1937 # @param the13Diag is used to choose a diagonal for splitting.
1938 # @return TRUE in case of success, FALSE otherwise.
1939 def SplitQuad (self, IDsOfElements, Diag13):
1940 if IDsOfElements == []:
1941 IDsOfElements = self.GetElementsId()
1942 return self.editor.SplitQuad(IDsOfElements, Diag13)
1944 ## Split quadrangles into triangles.
1945 # @param theObject is object to taking list of elements from, is mesh, submesh or group
1946 def SplitQuadObject (self, theObject, Diag13):
1947 return self.editor.SplitQuadObject(theObject, Diag13)
1949 ## Find better splitting of the given quadrangle.
1950 # @param IDOfQuad ID of the quadrangle to be splitted.
1951 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
1952 # @return 1 if 1-3 diagonal is better, 2 if 2-4
1953 # diagonal is better, 0 if error occurs.
1954 def BestSplit (self, IDOfQuad, theCriterion):
1955 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
1958 # @param IDsOfElements list if ids of elements to smooth
1959 # @param IDsOfFixedNodes list of ids of fixed nodes.
1960 # Note that nodes built on edges and boundary nodes are always fixed.
1961 # @param MaxNbOfIterations maximum number of iterations
1962 # @param MaxAspectRatio varies in range [1.0, inf]
1963 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1964 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
1965 MaxNbOfIterations, MaxAspectRatio, Method):
1966 if IDsOfElements == []:
1967 IDsOfElements = self.GetElementsId()
1968 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
1969 MaxNbOfIterations, MaxAspectRatio, Method)
1971 ## Smooth elements belong to given object
1972 # @param theObject object to smooth
1973 # @param IDsOfFixedNodes list of ids of fixed nodes.
1974 # Note that nodes built on edges and boundary nodes are always fixed.
1975 # @param MaxNbOfIterations maximum number of iterations
1976 # @param MaxAspectRatio varies in range [1.0, inf]
1977 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1978 def SmoothObject(self, theObject, IDsOfFixedNodes,
1979 MaxNbOfIterations, MaxxAspectRatio, Method):
1980 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
1981 MaxNbOfIterations, MaxxAspectRatio, Method)
1983 ## Parametric smooth the given elements
1984 # @param IDsOfElements list if ids of elements to smooth
1985 # @param IDsOfFixedNodes list of ids of fixed nodes.
1986 # Note that nodes built on edges and boundary nodes are always fixed.
1987 # @param MaxNbOfIterations maximum number of iterations
1988 # @param MaxAspectRatio varies in range [1.0, inf]
1989 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
1990 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1991 MaxNbOfIterations, MaxAspectRatio, Method):
1992 if IDsOfElements == []:
1993 IDsOfElements = self.GetElementsId()
1994 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
1995 MaxNbOfIterations, MaxAspectRatio, Method)
1997 ## Parametric smooth elements belong to given object
1998 # @param theObject object to smooth
1999 # @param IDsOfFixedNodes list of ids of fixed nodes.
2000 # Note that nodes built on edges and boundary nodes are always fixed.
2001 # @param MaxNbOfIterations maximum number of iterations
2002 # @param MaxAspectRatio varies in range [1.0, inf]
2003 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2004 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2005 MaxNbOfIterations, MaxAspectRatio, Method):
2006 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2007 MaxNbOfIterations, MaxAspectRatio, Method)
2009 ## Converts all mesh to quadratic one, deletes old elements, replacing
2010 # them with quadratic ones with the same id.
2011 def ConvertToQuadratic(self, theForce3d):
2012 self.editor.ConvertToQuadratic(theForce3d)
2014 ## Converts all mesh from quadratic to ordinary ones,
2015 # deletes old quadratic elements, \n replacing
2016 # them with ordinary mesh elements with the same id.
2017 def ConvertFromQuadratic(self):
2018 return self.editor.ConvertFromQuadratic()
2020 ## Renumber mesh nodes
2021 def RenumberNodes(self):
2022 self.editor.RenumberNodes()
2024 ## Renumber mesh elements
2025 def RenumberElements(self):
2026 self.editor.RenumberElements()
2028 ## Generate new elements by rotation of the elements around the axis
2029 # @param IDsOfElements list of ids of elements to sweep
2030 # @param Axix axis of rotation, AxisStruct or line(geom object)
2031 # @param AngleInRadians angle of Rotation
2032 # @param NbOfSteps number of steps
2033 # @param Tolerance tolerance
2034 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2035 if IDsOfElements == []:
2036 IDsOfElements = self.GetElementsId()
2037 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2038 Axix = GetAxisStruct(Axix)
2039 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2041 ## Generate new elements by rotation of the elements of object around the axis
2042 # @param theObject object wich elements should be sweeped
2043 # @param Axix axis of rotation, AxisStruct or line(geom object)
2044 # @param AngleInRadians angle of Rotation
2045 # @param NbOfSteps number of steps
2046 # @param Tolerance tolerance
2047 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2048 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2049 Axix = GetAxisStruct(Axix)
2050 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2052 ## Generate new elements by extrusion of the elements with given ids
2053 # @param IDsOfElements list of elements ids for extrusion
2054 # @param StepVector vector, defining the direction and value of extrusion
2055 # @param NbOfSteps the number of steps
2056 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2057 if IDsOfElements == []:
2058 IDsOfElements = self.GetElementsId()
2059 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2060 StepVector = GetDirStruct(StepVector)
2061 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2063 ## Generate new elements by extrusion of the elements with given ids
2064 # @param IDsOfElements is ids of elements
2065 # @param StepVector vector, defining the direction and value of extrusion
2066 # @param NbOfSteps the number of steps
2067 # @param ExtrFlags set flags for performing extrusion
2068 # @param SewTolerance uses for comparing locations of nodes if flag
2069 # EXTRUSION_FLAG_SEW is set
2070 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2071 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2072 StepVector = GetDirStruct(StepVector)
2073 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2075 ## Generate new elements by extrusion of the elements belong to object
2076 # @param theObject object wich elements should be processed
2077 # @param StepVector vector, defining the direction and value of extrusion
2078 # @param NbOfSteps the number of steps
2079 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2080 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2081 StepVector = GetDirStruct(StepVector)
2082 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2084 ## Generate new elements by extrusion of the elements belong to object
2085 # @param theObject object wich elements should be processed
2086 # @param StepVector vector, defining the direction and value of extrusion
2087 # @param NbOfSteps the number of steps
2088 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2089 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2090 StepVector = GetDirStruct(StepVector)
2091 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2093 ## Generate new elements by extrusion of the elements belong to object
2094 # @param theObject object wich elements should be processed
2095 # @param StepVector vector, defining the direction and value of extrusion
2096 # @param NbOfSteps the number of steps
2097 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2098 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2099 StepVector = GetDirStruct(StepVector)
2100 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2102 ## Generate new elements by extrusion of the given elements
2103 # A path of extrusion must be a meshed edge.
2104 # @param IDsOfElements is ids of elements
2105 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2106 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2107 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2108 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2109 # @param Angles list of angles
2110 # @param HasRefPoint allows to use base point
2111 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2112 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2113 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2114 HasAngles, Angles, HasRefPoint, RefPoint):
2115 if IDsOfElements == []:
2116 IDsOfElements = self.GetElementsId()
2117 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2118 RefPoint = GetPointStruct(RefPoint)
2119 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2120 HasAngles, Angles, HasRefPoint, RefPoint)
2122 ## Generate new elements by extrusion of the elements belong to object
2123 # A path of extrusion must be a meshed edge.
2124 # @param IDsOfElements is ids of elements
2125 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2126 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2127 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2128 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2129 # @param Angles list of angles
2130 # @param HasRefPoint allows to use base point
2131 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2132 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2133 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2134 HasAngles, Angles, HasRefPoint, RefPoint):
2135 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2136 RefPoint = GetPointStruct(RefPoint)
2137 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2138 HasAngles, Angles, HasRefPoint, RefPoint)
2140 ## Symmetrical copy of mesh elements
2141 # @param IDsOfElements list of elements ids
2142 # @param Mirror is AxisStruct or geom object(point, line, plane)
2143 # @param theMirrorType is POINT, AXIS or PLANE
2144 # If the Mirror is geom object this parameter is unnecessary
2145 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2146 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2147 if IDsOfElements == []:
2148 IDsOfElements = self.GetElementsId()
2149 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2150 Mirror = GetAxisStruct(Mirror)
2151 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2153 ## Symmetrical copy of object
2154 # @param theObject mesh, submesh or group
2155 # @param Mirror is AxisStruct or geom object(point, line, plane)
2156 # @param theMirrorType is POINT, AXIS or PLANE
2157 # If the Mirror is geom object this parameter is unnecessary
2158 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2159 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2160 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2161 Mirror = GetAxisStruct(Mirror)
2162 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2164 ## Translates the elements
2165 # @param IDsOfElements list of elements ids
2166 # @param Vector direction of translation(DirStruct or vector)
2167 # @param Copy allows to copy the translated elements
2168 def Translate(self, IDsOfElements, Vector, Copy):
2169 if IDsOfElements == []:
2170 IDsOfElements = self.GetElementsId()
2171 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2172 Vector = GetDirStruct(Vector)
2173 self.editor.Translate(IDsOfElements, Vector, Copy)
2175 ## Translates the object
2176 # @param theObject object to translate(mesh, submesh, or group)
2177 # @param Vector direction of translation(DirStruct or geom vector)
2178 # @param Copy allows to copy the translated elements
2179 def TranslateObject(self, theObject, Vector, Copy):
2180 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2181 Vector = GetDirStruct(Vector)
2182 self.editor.TranslateObject(theObject, Vector, Copy)
2184 ## Rotates the elements
2185 # @param IDsOfElements list of elements ids
2186 # @param Axis axis of rotation(AxisStruct or geom line)
2187 # @param AngleInRadians angle of rotation(in radians)
2188 # @param Copy allows to copy the rotated elements
2189 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2190 if IDsOfElements == []:
2191 IDsOfElements = self.GetElementsId()
2192 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2193 Axis = GetAxisStruct(Axis)
2194 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2196 ## Rotates the object
2197 # @param theObject object to rotate(mesh, submesh, or group)
2198 # @param Axis axis of rotation(AxisStruct or geom line)
2199 # @param AngleInRadians angle of rotation(in radians)
2200 # @param Copy allows to copy the rotated elements
2201 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2202 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2204 ## Find group of nodes close to each other within Tolerance.
2205 # @param Tolerance tolerance value
2206 # @param list of group of nodes
2207 def FindCoincidentNodes (self, Tolerance):
2208 return self.editor.FindCoincidentNodes(Tolerance)
2211 # @param list of group of nodes
2212 def MergeNodes (self, GroupsOfNodes):
2213 self.editor.MergeNodes(GroupsOfNodes)
2215 ## Remove all but one of elements built on the same nodes.
2216 def MergeEqualElements(self):
2217 self.editor.MergeEqualElements()
2220 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2221 FirstNodeID2, SecondNodeID2, LastNodeID2,
2222 CreatePolygons, CreatePolyedrs):
2223 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2224 FirstNodeID2, SecondNodeID2, LastNodeID2,
2225 CreatePolygons, CreatePolyedrs)
2227 ## Sew conform free borders
2228 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2229 FirstNodeID2, SecondNodeID2):
2230 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2231 FirstNodeID2, SecondNodeID2)
2233 ## Sew border to side
2234 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2235 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2236 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2237 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2239 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2240 # merged with nodes of elements of Side2.
2241 # Number of elements in theSide1 and in theSide2 must be
2242 # equal and they should have similar node connectivity.
2243 # The nodes to merge should belong to sides borders and
2244 # the first node should be linked to the second.
2245 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2246 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2247 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2248 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2249 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2250 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2252 ## Set new nodes for given element.
2253 # @param ide the element id
2254 # @param newIDs nodes ids
2255 # @return If number of nodes is not corresponded to type of element - returns false
2256 def ChangeElemNodes(self, ide, newIDs):
2257 return self.editor.ChangeElemNodes(ide, newIDs)
2259 ## If during last operation of MeshEditor some nodes were
2260 # created this method returns list of it's IDs, \n
2261 # if new nodes not created - returns empty list
2262 def GetLastCreatedNodes(self):
2263 return self.editor.GetLastCreatedNodes()
2265 ## If during last operation of MeshEditor some elements were
2266 # created this method returns list of it's IDs, \n
2267 # if new elements not creared - returns empty list
2268 def GetLastCreatedElems(self):
2269 return self.editor.GetLastCreatedElems()