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 3D extrusion 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 3D extrusion (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))
1957 ## Split quafrangle faces near triangular facets of volumes
1959 def SplitQuadsNearTriangularFacets(self):
1960 faces_array = self.GetElementsByType(SMESH.FACE)
1961 for face_id in faces_array:
1962 if self.GetElemNbNodes(face_id) == 4: # quadrangle
1963 quad_nodes = self.mesh.GetElemNodes(face_id)
1964 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
1965 isVolumeFound = False
1966 for node1_elem in node1_elems:
1967 if not isVolumeFound:
1968 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
1969 nb_nodes = self.GetElemNbNodes(node1_elem)
1970 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
1971 volume_elem = node1_elem
1972 volume_nodes = self.mesh.GetElemNodes(volume_elem)
1973 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
1974 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
1975 isVolumeFound = True
1976 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
1977 self.SplitQuad([face_id], False) # diagonal 2-4
1978 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
1979 isVolumeFound = True
1980 self.SplitQuad([face_id], True) # diagonal 1-3
1981 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
1982 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
1983 isVolumeFound = True
1984 self.SplitQuad([face_id], True) # diagonal 1-3
1986 ## @brief Split hexahedrons into tetrahedrons.
1988 # Use pattern mapping functionality for splitting.
1989 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
1990 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
1991 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
1992 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
1993 # key-point will be mapped into <theNode001>-th node of each volume.
1994 # The (0,0,0) key-point of used pattern corresponds to not split corner.
1995 # @param @return TRUE in case of success, FALSE otherwise.
1996 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
1997 # Pattern: 5.---------.6
2002 # (0,0,1) 4.---------.7 * |
2009 # (0,0,0) 0.---------.3
2010 pattern_tetra = "!!! Nb of points: \n 8 \n\
2020 !!! Indices of points of 6 tetras: \n\
2028 pattern = GetPattern()
2029 isDone = pattern.LoadFromFile(pattern_tetra)
2031 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2034 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2035 isDone = pattern.MakeMesh(self.mesh, False, False)
2036 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2038 # split quafrangle faces near triangular facets of volumes
2039 self.SplitQuadsNearTriangularFacets()
2043 ## @brief Split hexahedrons into prisms.
2045 # Use pattern mapping functionality for splitting.
2046 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2047 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2048 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2049 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2050 # key-point will be mapped into <theNode001>-th node of each volume.
2051 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2052 # @param @return TRUE in case of success, FALSE otherwise.
2053 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2054 # Pattern: 5.---------.6
2059 # (0,0,1) 4.---------.7 |
2066 # (0,0,0) 0.---------.3
2067 pattern_prism = "!!! Nb of points: \n 8 \n\
2077 !!! Indices of points of 2 prisms: \n\
2081 pattern = GetPattern()
2082 isDone = pattern.LoadFromFile(pattern_prism)
2084 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2087 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2088 isDone = pattern.MakeMesh(self.mesh, False, False)
2089 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2091 # split quafrangle faces near triangular facets of volumes
2092 self.SplitQuadsNearTriangularFacets()
2097 # @param IDsOfElements list if ids of elements to smooth
2098 # @param IDsOfFixedNodes list of ids of fixed nodes.
2099 # Note that nodes built on edges and boundary nodes are always fixed.
2100 # @param MaxNbOfIterations maximum number of iterations
2101 # @param MaxAspectRatio varies in range [1.0, inf]
2102 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2103 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2104 MaxNbOfIterations, MaxAspectRatio, Method):
2105 if IDsOfElements == []:
2106 IDsOfElements = self.GetElementsId()
2107 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2108 MaxNbOfIterations, MaxAspectRatio, Method)
2110 ## Smooth elements belong to given object
2111 # @param theObject object to smooth
2112 # @param IDsOfFixedNodes list of ids of fixed nodes.
2113 # Note that nodes built on edges and boundary nodes are always fixed.
2114 # @param MaxNbOfIterations maximum number of iterations
2115 # @param MaxAspectRatio varies in range [1.0, inf]
2116 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2117 def SmoothObject(self, theObject, IDsOfFixedNodes,
2118 MaxNbOfIterations, MaxxAspectRatio, Method):
2119 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2120 MaxNbOfIterations, MaxxAspectRatio, Method)
2122 ## Parametric smooth the given elements
2123 # @param IDsOfElements list if ids of elements to smooth
2124 # @param IDsOfFixedNodes list of ids of fixed nodes.
2125 # Note that nodes built on edges and boundary nodes are always fixed.
2126 # @param MaxNbOfIterations maximum number of iterations
2127 # @param MaxAspectRatio varies in range [1.0, inf]
2128 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2129 def SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2130 MaxNbOfIterations, MaxAspectRatio, Method):
2131 if IDsOfElements == []:
2132 IDsOfElements = self.GetElementsId()
2133 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2134 MaxNbOfIterations, MaxAspectRatio, Method)
2136 ## Parametric smooth elements belong to given object
2137 # @param theObject object to smooth
2138 # @param IDsOfFixedNodes list of ids of fixed nodes.
2139 # Note that nodes built on edges and boundary nodes are always fixed.
2140 # @param MaxNbOfIterations maximum number of iterations
2141 # @param MaxAspectRatio varies in range [1.0, inf]
2142 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2143 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2144 MaxNbOfIterations, MaxAspectRatio, Method):
2145 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2146 MaxNbOfIterations, MaxAspectRatio, Method)
2148 ## Converts all mesh to quadratic one, deletes old elements, replacing
2149 # them with quadratic ones with the same id.
2150 def ConvertToQuadratic(self, theForce3d):
2151 self.editor.ConvertToQuadratic(theForce3d)
2153 ## Converts all mesh from quadratic to ordinary ones,
2154 # deletes old quadratic elements, \n replacing
2155 # them with ordinary mesh elements with the same id.
2156 def ConvertFromQuadratic(self):
2157 return self.editor.ConvertFromQuadratic()
2159 ## Renumber mesh nodes
2160 def RenumberNodes(self):
2161 self.editor.RenumberNodes()
2163 ## Renumber mesh elements
2164 def RenumberElements(self):
2165 self.editor.RenumberElements()
2167 ## Generate new elements by rotation of the elements around the axis
2168 # @param IDsOfElements list of ids of elements to sweep
2169 # @param Axix axis of rotation, AxisStruct or line(geom object)
2170 # @param AngleInRadians angle of Rotation
2171 # @param NbOfSteps number of steps
2172 # @param Tolerance tolerance
2173 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2174 if IDsOfElements == []:
2175 IDsOfElements = self.GetElementsId()
2176 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2177 Axix = GetAxisStruct(Axix)
2178 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2180 ## Generate new elements by rotation of the elements of object around the axis
2181 # @param theObject object wich elements should be sweeped
2182 # @param Axix axis of rotation, AxisStruct or line(geom object)
2183 # @param AngleInRadians angle of Rotation
2184 # @param NbOfSteps number of steps
2185 # @param Tolerance tolerance
2186 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2187 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2188 Axix = GetAxisStruct(Axix)
2189 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2191 ## Generate new elements by extrusion of the elements with given ids
2192 # @param IDsOfElements list of elements ids for extrusion
2193 # @param StepVector vector, defining the direction and value of extrusion
2194 # @param NbOfSteps the number of steps
2195 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2196 if IDsOfElements == []:
2197 IDsOfElements = self.GetElementsId()
2198 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2199 StepVector = GetDirStruct(StepVector)
2200 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2202 ## Generate new elements by extrusion of the elements with given ids
2203 # @param IDsOfElements is ids of elements
2204 # @param StepVector vector, defining the direction and value of extrusion
2205 # @param NbOfSteps the number of steps
2206 # @param ExtrFlags set flags for performing extrusion
2207 # @param SewTolerance uses for comparing locations of nodes if flag
2208 # EXTRUSION_FLAG_SEW is set
2209 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2210 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2211 StepVector = GetDirStruct(StepVector)
2212 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2214 ## Generate new elements by extrusion of the elements belong to object
2215 # @param theObject object wich elements should be processed
2216 # @param StepVector vector, defining the direction and value of extrusion
2217 # @param NbOfSteps the number of steps
2218 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2219 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2220 StepVector = GetDirStruct(StepVector)
2221 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2223 ## Generate new elements by extrusion of the elements belong to object
2224 # @param theObject object wich elements should be processed
2225 # @param StepVector vector, defining the direction and value of extrusion
2226 # @param NbOfSteps the number of steps
2227 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2228 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2229 StepVector = GetDirStruct(StepVector)
2230 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2232 ## Generate new elements by extrusion of the elements belong to object
2233 # @param theObject object wich elements should be processed
2234 # @param StepVector vector, defining the direction and value of extrusion
2235 # @param NbOfSteps the number of steps
2236 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2237 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2238 StepVector = GetDirStruct(StepVector)
2239 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2241 ## Generate new elements by extrusion of the given elements
2242 # A path of extrusion must be a meshed edge.
2243 # @param IDsOfElements is ids of elements
2244 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2245 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2246 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2247 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2248 # @param Angles list of angles
2249 # @param HasRefPoint allows to use base point
2250 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2251 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2252 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2253 HasAngles, Angles, HasRefPoint, RefPoint):
2254 if IDsOfElements == []:
2255 IDsOfElements = self.GetElementsId()
2256 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2257 RefPoint = GetPointStruct(RefPoint)
2258 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2259 HasAngles, Angles, HasRefPoint, RefPoint)
2261 ## Generate new elements by extrusion of the elements belong to object
2262 # A path of extrusion must be a meshed edge.
2263 # @param IDsOfElements is ids of elements
2264 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2265 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2266 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2267 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2268 # @param Angles list of angles
2269 # @param HasRefPoint allows to use base point
2270 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2271 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2272 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2273 HasAngles, Angles, HasRefPoint, RefPoint):
2274 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2275 RefPoint = GetPointStruct(RefPoint)
2276 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2277 HasAngles, Angles, HasRefPoint, RefPoint)
2279 ## Symmetrical copy of mesh elements
2280 # @param IDsOfElements list of elements ids
2281 # @param Mirror is AxisStruct or geom object(point, line, plane)
2282 # @param theMirrorType is POINT, AXIS or PLANE
2283 # If the Mirror is geom object this parameter is unnecessary
2284 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2285 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2286 if IDsOfElements == []:
2287 IDsOfElements = self.GetElementsId()
2288 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2289 Mirror = GetAxisStruct(Mirror)
2290 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2292 ## Symmetrical copy of object
2293 # @param theObject mesh, submesh or group
2294 # @param Mirror is AxisStruct or geom object(point, line, plane)
2295 # @param theMirrorType is POINT, AXIS or PLANE
2296 # If the Mirror is geom object this parameter is unnecessary
2297 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2298 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2299 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2300 Mirror = GetAxisStruct(Mirror)
2301 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2303 ## Translates the elements
2304 # @param IDsOfElements list of elements ids
2305 # @param Vector direction of translation(DirStruct or vector)
2306 # @param Copy allows to copy the translated elements
2307 def Translate(self, IDsOfElements, Vector, Copy):
2308 if IDsOfElements == []:
2309 IDsOfElements = self.GetElementsId()
2310 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2311 Vector = GetDirStruct(Vector)
2312 self.editor.Translate(IDsOfElements, Vector, Copy)
2314 ## Translates the object
2315 # @param theObject object to translate(mesh, submesh, or group)
2316 # @param Vector direction of translation(DirStruct or geom vector)
2317 # @param Copy allows to copy the translated elements
2318 def TranslateObject(self, theObject, Vector, Copy):
2319 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2320 Vector = GetDirStruct(Vector)
2321 self.editor.TranslateObject(theObject, Vector, Copy)
2323 ## Rotates the elements
2324 # @param IDsOfElements list of elements ids
2325 # @param Axis axis of rotation(AxisStruct or geom line)
2326 # @param AngleInRadians angle of rotation(in radians)
2327 # @param Copy allows to copy the rotated elements
2328 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2329 if IDsOfElements == []:
2330 IDsOfElements = self.GetElementsId()
2331 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2332 Axis = GetAxisStruct(Axis)
2333 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2335 ## Rotates the object
2336 # @param theObject object to rotate(mesh, submesh, or group)
2337 # @param Axis axis of rotation(AxisStruct or geom line)
2338 # @param AngleInRadians angle of rotation(in radians)
2339 # @param Copy allows to copy the rotated elements
2340 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2341 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2343 ## Find group of nodes close to each other within Tolerance.
2344 # @param Tolerance tolerance value
2345 # @param list of group of nodes
2346 def FindCoincidentNodes (self, Tolerance):
2347 return self.editor.FindCoincidentNodes(Tolerance)
2350 # @param list of group of nodes
2351 def MergeNodes (self, GroupsOfNodes):
2352 self.editor.MergeNodes(GroupsOfNodes)
2354 ## Remove all but one of elements built on the same nodes.
2355 def MergeEqualElements(self):
2356 self.editor.MergeEqualElements()
2359 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2360 FirstNodeID2, SecondNodeID2, LastNodeID2,
2361 CreatePolygons, CreatePolyedrs):
2362 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2363 FirstNodeID2, SecondNodeID2, LastNodeID2,
2364 CreatePolygons, CreatePolyedrs)
2366 ## Sew conform free borders
2367 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2368 FirstNodeID2, SecondNodeID2):
2369 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2370 FirstNodeID2, SecondNodeID2)
2372 ## Sew border to side
2373 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2374 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2375 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2376 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2378 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2379 # merged with nodes of elements of Side2.
2380 # Number of elements in theSide1 and in theSide2 must be
2381 # equal and they should have similar node connectivity.
2382 # The nodes to merge should belong to sides borders and
2383 # the first node should be linked to the second.
2384 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2385 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2386 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2387 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2388 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2389 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2391 ## Set new nodes for given element.
2392 # @param ide the element id
2393 # @param newIDs nodes ids
2394 # @return If number of nodes is not corresponded to type of element - returns false
2395 def ChangeElemNodes(self, ide, newIDs):
2396 return self.editor.ChangeElemNodes(ide, newIDs)
2398 ## If during last operation of MeshEditor some nodes were
2399 # created this method returns list of it's IDs, \n
2400 # if new nodes not created - returns empty list
2401 def GetLastCreatedNodes(self):
2402 return self.editor.GetLastCreatedNodes()
2404 ## If during last operation of MeshEditor some elements were
2405 # created this method returns list of it's IDs, \n
2406 # if new elements not creared - returns empty list
2407 def GetLastCreatedElems(self):
2408 return self.editor.GetLastCreatedElems()