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
32 import SMESH # necessary for back compatibility
39 # import NETGENPlugin module if possible
58 NETGEN_1D2D3D = FULL_NETGEN
59 NETGEN_FULL = FULL_NETGEN
61 # MirrorType enumeration
62 POINT = SMESH_MeshEditor.POINT
63 AXIS = SMESH_MeshEditor.AXIS
64 PLANE = SMESH_MeshEditor.PLANE
66 # Smooth_Method enumeration
67 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
68 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
70 # Fineness enumeration(for NETGEN)
82 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
83 smesh.SetCurrentStudy(salome.myStudy)
89 ior = salome.orb.object_to_string(obj)
90 sobj = salome.myStudy.FindObjectIOR(ior)
94 attr = sobj.FindAttribute("AttributeName")[1]
97 ## Sets name to object
98 def SetName(obj, name):
99 ior = salome.orb.object_to_string(obj)
100 sobj = salome.myStudy.FindObjectIOR(ior)
102 attr = sobj.FindAttribute("AttributeName")[1]
105 ## Returns long value from enumeration
106 # Uses for SMESH.FunctorType enumeration
107 def EnumToLong(theItem):
110 ## Get PointStruct from vertex
111 # @param theVertex is GEOM object(vertex)
112 # @return SMESH.PointStruct
113 def GetPointStruct(theVertex):
114 [x, y, z] = geompy.PointCoordinates(theVertex)
115 return PointStruct(x,y,z)
117 ## Get DirStruct from vector
118 # @param theVector is GEOM object(vector)
119 # @return SMESH.DirStruct
120 def GetDirStruct(theVector):
121 vertices = geompy.SubShapeAll( theVector, geompy.ShapeType["VERTEX"] )
122 if(len(vertices) != 2):
123 print "Error: vector object is incorrect."
125 p1 = geompy.PointCoordinates(vertices[0])
126 p2 = geompy.PointCoordinates(vertices[1])
127 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
131 ## Get AxisStruct from object
132 # @param theObj is GEOM object(line or plane)
133 # @return SMESH.AxisStruct
134 def GetAxisStruct(theObj):
135 edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
137 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
138 vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
139 vertex1 = geompy.PointCoordinates(vertex1)
140 vertex2 = geompy.PointCoordinates(vertex2)
141 vertex3 = geompy.PointCoordinates(vertex3)
142 vertex4 = geompy.PointCoordinates(vertex4)
143 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
144 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
145 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] ]
146 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
148 elif len(edges) == 1:
149 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
150 p1 = geompy.PointCoordinates( vertex1 )
151 p2 = geompy.PointCoordinates( vertex2 )
152 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
156 # From SMESH_Gen interface:
157 # ------------------------
159 ## Set the current mode
160 def SetEmbeddedMode( theMode ):
161 smesh.SetEmbeddedMode(theMode)
163 ## Get the current mode
164 def IsEmbeddedMode():
165 return smesh.IsEmbeddedMode()
167 ## Set the current study
168 def SetCurrentStudy( theStudy ):
169 smesh.SetCurrentStudy(theStudy)
171 ## Get the current study
172 def GetCurrentStudy():
173 return smesh.GetCurrentStudy()
175 ## Create Mesh object importing data from given UNV file
176 # @return an instance of Mesh class
177 def CreateMeshesFromUNV( theFileName ):
178 aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
179 aMesh = Mesh(aSmeshMesh)
182 ## Create Mesh object(s) importing data from given MED file
183 # @return a list of Mesh class instances
184 def CreateMeshesFromMED( theFileName ):
185 aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
187 for iMesh in range(len(aSmeshMeshes)) :
188 aMesh = Mesh(aSmeshMeshes[iMesh])
189 aMeshes.append(aMesh)
190 return aMeshes, aStatus
192 ## Create Mesh object importing data from given STL file
193 # @return an instance of Mesh class
194 def CreateMeshesFromSTL( theFileName ):
195 aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
196 aMesh = Mesh(aSmeshMesh)
199 ## From SMESH_Gen interface
200 def GetSubShapesId( theMainObject, theListOfSubObjects ):
201 return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
203 ## From SMESH_Gen interface. Creates pattern
205 return smesh.GetPattern()
209 # Filtering. Auxiliary functions:
210 # ------------------------------
212 ## Creates an empty criterion
213 # @return SMESH.Filter.Criterion
214 def GetEmptyCriterion():
215 Type = EnumToLong(FT_Undefined)
216 Compare = EnumToLong(FT_Undefined)
220 UnaryOp = EnumToLong(FT_Undefined)
221 BinaryOp = EnumToLong(FT_Undefined)
224 Precision = -1 ##@1e-07
225 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
226 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
228 ## Creates a criterion by given parameters
229 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
230 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
231 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
232 # @param Treshold is threshold value (range of ids as string, shape, numeric)
233 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
234 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
235 # FT_Undefined(must be for the last criterion in criteria)
236 # @return SMESH.Filter.Criterion
237 def GetCriterion(elementType,
239 Compare = FT_EqualTo,
241 UnaryOp=FT_Undefined,
242 BinaryOp=FT_Undefined):
243 aCriterion = GetEmptyCriterion()
244 aCriterion.TypeOfElement = elementType
245 aCriterion.Type = EnumToLong(CritType)
249 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
250 aCriterion.Compare = EnumToLong(Compare)
251 elif Compare == "=" or Compare == "==":
252 aCriterion.Compare = EnumToLong(FT_EqualTo)
254 aCriterion.Compare = EnumToLong(FT_LessThan)
256 aCriterion.Compare = EnumToLong(FT_MoreThan)
258 aCriterion.Compare = EnumToLong(FT_EqualTo)
261 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
262 FT_BelongToCylinder, FT_LyingOnGeom]:
264 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
265 aCriterion.ThresholdStr = GetName(aTreshold)
266 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
268 print "Error: Treshold should be a shape."
270 elif CritType == FT_RangeOfIds:
272 if isinstance(aTreshold, str):
273 aCriterion.ThresholdStr = aTreshold
275 print "Error: Treshold should be a string."
277 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
278 # Here we do not need treshold
279 if aTreshold == FT_LogicalNOT:
280 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
281 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
282 aCriterion.BinaryOp = aTreshold
286 aTreshold = float(aTreshold)
287 aCriterion.Threshold = aTreshold
289 print "Error: Treshold should be a number."
292 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
293 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
295 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
296 aCriterion.BinaryOp = EnumToLong(Treshold)
298 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
299 aCriterion.BinaryOp = EnumToLong(UnaryOp)
301 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
302 aCriterion.BinaryOp = EnumToLong(BinaryOp)
306 ## Creates filter by given parameters of criterion
307 # @param elementType is the type of elements in the group
308 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
309 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
310 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
311 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
312 # @return SMESH_Filter
313 def GetFilter(elementType,
314 CritType=FT_Undefined,
317 UnaryOp=FT_Undefined):
318 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
319 aFilterMgr = smesh.CreateFilterManager()
320 aFilter = aFilterMgr.CreateFilter()
322 aCriteria.append(aCriterion)
323 aFilter.SetCriteria(aCriteria)
326 ## Creates numerical functor by its type
327 # @param theCrierion is FT_...; functor type
328 # @return SMESH_NumericalFunctor
329 def GetFunctor(theCriterion):
330 aFilterMgr = smesh.CreateFilterManager()
331 if theCriterion == FT_AspectRatio:
332 return aFilterMgr.CreateAspectRatio()
333 elif theCriterion == FT_AspectRatio3D:
334 return aFilterMgr.CreateAspectRatio3D()
335 elif theCriterion == FT_Warping:
336 return aFilterMgr.CreateWarping()
337 elif theCriterion == FT_MinimumAngle:
338 return aFilterMgr.CreateMinimumAngle()
339 elif theCriterion == FT_Taper:
340 return aFilterMgr.CreateTaper()
341 elif theCriterion == FT_Skew:
342 return aFilterMgr.CreateSkew()
343 elif theCriterion == FT_Area:
344 return aFilterMgr.CreateArea()
345 elif theCriterion == FT_Volume3D:
346 return aFilterMgr.CreateVolume3D()
347 elif theCriterion == FT_MultiConnection:
348 return aFilterMgr.CreateMultiConnection()
349 elif theCriterion == FT_MultiConnection2D:
350 return aFilterMgr.CreateMultiConnection2D()
351 elif theCriterion == FT_Length:
352 return aFilterMgr.CreateLength()
353 elif theCriterion == FT_Length2D:
354 return aFilterMgr.CreateLength2D()
356 print "Error: given parameter is not numerucal functor type."
359 ## Print error message if a hypothesis was not assigned.
360 def TreatHypoStatus(status, hypName, geomName, isAlgo):
362 hypType = "algorithm"
364 hypType = "hypothesis"
366 if status == HYP_UNKNOWN_FATAL :
367 reason = "for unknown reason"
368 elif status == HYP_INCOMPATIBLE :
369 reason = "this hypothesis mismatches algorithm"
370 elif status == HYP_NOTCONFORM :
371 reason = "not conform mesh would be built"
372 elif status == HYP_ALREADY_EXIST :
373 reason = hypType + " of the same dimension already assigned to this shape"
374 elif status == HYP_BAD_DIM :
375 reason = hypType + " mismatches shape"
376 elif status == HYP_CONCURENT :
377 reason = "there are concurrent hypotheses on sub-shapes"
378 elif status == HYP_BAD_SUBSHAPE :
379 reason = "shape is neither the main one, nor its subshape, nor a valid group"
380 elif status == HYP_BAD_GEOMETRY:
381 reason = "geometry mismatches algorithm's expectation"
382 elif status == HYP_HIDDEN_ALGO:
383 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
384 elif status == HYP_HIDING_ALGO:
385 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
388 hypName = '"' + hypName + '"'
389 geomName= '"' + geomName+ '"'
390 if status < HYP_UNKNOWN_FATAL:
391 print hypName, "was assigned to", geomName,"but", reason
393 print hypName, "was not assigned to",geomName,":", reason
398 ## Mother class to define algorithm, recommended to do not use directly.
401 class Mesh_Algorithm:
402 # @class Mesh_Algorithm
403 # @brief Class Mesh_Algorithm
411 def FindHypothesis(self,hypname, args):
412 key = "%s %s %s" % (self.__class__.__name__, hypname, args)
413 if Mesh_Algorithm.hypos.has_key( key ):
414 return Mesh_Algorithm.hypos[ key ]
417 ## If the algorithm is global, return 0; \n
418 # else return the submesh associated to this algorithm.
419 def GetSubMesh(self):
422 ## Return the wrapped mesher.
423 def GetAlgorithm(self):
426 ## Get list of hypothesis that can be used with this algorithm
427 def GetCompatibleHypothesis(self):
430 list = self.algo.GetCompatibleHypothesis()
438 def SetName(self, name):
439 SetName(self.algo, name)
443 return self.algo.GetId()
446 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
448 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
449 algo = smesh.CreateHypothesis(hypo, so)
450 self.Assign(algo, mesh, geom)
454 def Assign(self, algo, mesh, geom):
456 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
465 name = geompy.SubShapeName(geom, piece)
466 geompy.addToStudyInFather(piece, geom, name)
467 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
470 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
471 TreatHypoStatus( status, algo.GetName(), GetName(algo), True )
474 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so", UseExisting=0):
477 hypo = self.FindHypothesis(hyp, args)
478 if hypo!=None: CreateNew = 0
481 hypo = smesh.CreateHypothesis(hyp, so)
482 key = "%s %s %s" % (self.__class__.__name__, hyp, args)
483 Mesh_Algorithm.hypos[key] = hypo
489 a = a + s + str(args[i])
492 name = GetName(self.geom)
493 #SetName(hypo, name + "/" + hyp + a) - NPAL16198
494 SetName(hypo, hyp + a)
496 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
497 TreatHypoStatus( status, hyp, GetName(hypo), 0 )
501 # Public class: Mesh_Segment
502 # --------------------------
504 ## Class to define a segment 1D algorithm for discretization
507 class Mesh_Segment(Mesh_Algorithm):
509 algo = 0 # algorithm object common for all Mesh_Segments
511 ## Private constructor.
512 def __init__(self, mesh, geom=0):
513 if not Mesh_Segment.algo:
514 Mesh_Segment.algo = self.Create(mesh, geom, "Regular_1D")
516 self.Assign( Mesh_Segment.algo, mesh, geom)
519 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
520 # @param l for the length of segments that cut an edge
521 # @param UseExisting if ==true - search existing hypothesis created with
522 # same parameters, else (default) - create new
523 def LocalLength(self, l, UseExisting=0):
524 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting)
528 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
529 # @param n for the number of segments that cut an edge
530 # @param s for the scale factor (optional)
531 # @param UseExisting if ==true - search existing hypothesis created with
532 # same parameters, else (default) - create new
533 def NumberOfSegments(self, n, s=[], UseExisting=0):
535 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting)
537 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting)
538 hyp.SetDistrType( 1 )
539 hyp.SetScaleFactor(s)
540 hyp.SetNumberOfSegments(n)
543 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
544 # @param start for the length of the first segment
545 # @param end for the length of the last segment
546 # @param UseExisting if ==true - search existing hypothesis created with
547 # same parameters, else (default) - create new
548 def Arithmetic1D(self, start, end, UseExisting=0):
549 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting)
550 hyp.SetLength(start, 1)
551 hyp.SetLength(end , 0)
554 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
555 # @param start for the length of the first segment
556 # @param end for the length of the last segment
557 # @param UseExisting if ==true - search existing hypothesis created with
558 # same parameters, else (default) - create new
559 def StartEndLength(self, start, end, UseExisting=0):
560 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting)
561 hyp.SetLength(start, 1)
562 hyp.SetLength(end , 0)
565 ## Define "Deflection1D" hypothesis
566 # @param d for the deflection
567 # @param UseExisting if ==true - search existing hypothesis created with
568 # same parameters, else (default) - create new
569 def Deflection1D(self, d, UseExisting=0):
570 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting)
574 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
575 # the opposite side in the case of quadrangular faces
576 def Propagation(self):
577 return self.Hypothesis("Propagation", UseExisting=1)
579 ## Define "AutomaticLength" hypothesis
580 # @param fineness for the fineness [0-1]
581 # @param UseExisting if ==true - search existing hypothesis created with
582 # same parameters, else (default) - create new
583 def AutomaticLength(self, fineness=0, UseExisting=0):
584 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting)
585 hyp.SetFineness( fineness )
588 ## Define "SegmentLengthAroundVertex" hypothesis
589 # @param length for the segment length
590 # @param vertex for the length localization: vertex index [0,1] | verext object
591 # @param UseExisting if ==true - search existing hypothesis created with
592 # same parameters, else (default) - create new
593 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
595 store_geom = self.geom
597 if type(vertex) is types.IntType:
598 vertex = geompy.SubShapeAllSorted(self.geom,geompy.ShapeType["VERTEX"])[vertex]
602 hyp = self.Hypothesis("SegmentAroundVertex_0D",[length],UseExisting=UseExisting)
603 hyp = self.Hypothesis("SegmentLengthAroundVertex",[length],UseExisting=UseExisting)
604 self.geom = store_geom
605 hyp.SetLength( length )
608 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
609 # If the 2D mesher sees that all boundary edges are quadratic ones,
610 # it generates quadratic faces, else it generates linear faces using
611 # medium nodes as if they were vertex ones.
612 # The 3D mesher generates quadratic volumes only if all boundary faces
613 # are quadratic ones, else it fails.
614 def QuadraticMesh(self):
615 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1)
618 # Public class: Mesh_CompositeSegment
619 # --------------------------
621 ## Class to define a segment 1D algorithm for discretization
624 class Mesh_CompositeSegment(Mesh_Segment):
626 algo = 0 # algorithm object common for all Mesh_CompositeSegments
628 ## Private constructor.
629 def __init__(self, mesh, geom=0):
630 if not Mesh_CompositeSegment.algo:
631 Mesh_CompositeSegment.algo = self.Create(mesh, geom, "CompositeSegment_1D")
633 self.Assign( Mesh_CompositeSegment.algo, mesh, geom)
637 # Public class: Mesh_Segment_Python
638 # ---------------------------------
640 ## Class to define a segment 1D algorithm for discretization with python function
643 class Mesh_Segment_Python(Mesh_Segment):
645 algo = 0 # algorithm object common for all Mesh_Segment_Pythons
647 ## Private constructor.
648 def __init__(self, mesh, geom=0):
649 import Python1dPlugin
650 if not Mesh_Segment_Python.algo:
651 Mesh_Segment_Python.algo = self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
653 self.Assign( Mesh_Segment_Python.algo, mesh, geom)
656 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
657 # @param n for the number of segments that cut an edge
658 # @param func for the python function that calculate the length of all segments
659 # @param UseExisting if ==true - search existing hypothesis created with
660 # same parameters, else (default) - create new
661 def PythonSplit1D(self, n, func, UseExisting=0):
662 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so", UseExisting=UseExisting)
663 hyp.SetNumberOfSegments(n)
664 hyp.SetPythonLog10RatioFunction(func)
667 # Public class: Mesh_Triangle
668 # ---------------------------
670 ## Class to define a triangle 2D algorithm
673 class Mesh_Triangle(Mesh_Algorithm):
679 # algorithm objects common for all instances of Mesh_Triangle
684 ## Private constructor.
685 def __init__(self, mesh, algoType, geom=0):
686 if algoType == MEFISTO:
687 if not Mesh_Triangle.algoMEF:
688 Mesh_Triangle.algoMEF = self.Create(mesh, geom, "MEFISTO_2D")
690 self.Assign( Mesh_Triangle.algoMEF, mesh, geom)
694 elif algoType == NETGEN:
696 print "Warning: NETGENPlugin module unavailable"
698 if not Mesh_Triangle.algoNET:
699 Mesh_Triangle.algoNET = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
701 self.Assign( Mesh_Triangle.algoNET, mesh, geom)
704 elif algoType == NETGEN_2D:
706 print "Warning: NETGENPlugin module unavailable"
708 if not Mesh_Triangle.algoNET_2D:
709 Mesh_Triangle.algoNET_2D = self.Create(mesh, geom,
710 "NETGEN_2D_ONLY", "libNETGENEngine.so")
712 self.Assign( Mesh_Triangle.algoNET_2D, mesh, geom)
716 self.algoType = algoType
718 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
719 # @param area for the maximum area of each triangles
720 # @param UseExisting if ==true - search existing hypothesis created with
721 # same parameters, else (default) - create new
723 # Only for algoType == MEFISTO || NETGEN_2D
724 def MaxElementArea(self, area, UseExisting=0):
725 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
726 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting)
727 hyp.SetMaxElementArea(area)
729 elif self.algoType == NETGEN:
730 print "Netgen 1D-2D algo doesn't support this hypothesis"
733 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
735 # Only for algoType == MEFISTO || NETGEN_2D
736 def LengthFromEdges(self):
737 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
738 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1)
740 elif self.algoType == NETGEN:
741 print "Netgen 1D-2D algo doesn't support this hypothesis"
744 ## Set QuadAllowed flag
746 # Only for algoType == NETGEN || NETGEN_2D
747 def SetQuadAllowed(self, toAllow=True):
748 if self.algoType == NETGEN_2D:
749 if toAllow: # add QuadranglePreference
750 self.Hypothesis("QuadranglePreference", UseExisting=1)
751 else: # remove QuadranglePreference
752 for hyp in self.mesh.GetHypothesisList( self.geom ):
753 if hyp.GetName() == "QuadranglePreference":
754 self.mesh.RemoveHypothesis( self.geom, hyp )
759 if self.params == 0 and self.Parameters():
760 self.params.SetQuadAllowed(toAllow)
763 ## Define "Netgen 2D Parameters" hypothesis
765 # Only for algoType == NETGEN
766 def Parameters(self):
767 if self.algoType == NETGEN:
768 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
769 "libNETGENEngine.so", UseExisting=0)
771 elif self.algoType == MEFISTO:
772 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
774 elif self.algoType == NETGEN_2D:
775 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
776 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
782 # Only for algoType == NETGEN
783 def SetMaxSize(self, theSize):
784 if self.params == 0 and self.Parameters():
785 self.params.SetMaxSize(theSize)
787 ## Set SecondOrder flag
789 # Only for algoType == NETGEN
790 def SetSecondOrder(self, theVal):
791 if self.params == 0 and self.Parameters():
792 self.params.SetSecondOrder(theVal)
797 # Only for algoType == NETGEN
798 def SetOptimize(self, theVal):
799 if self.params == 0 and self.Parameters():
800 self.params.SetOptimize(theVal)
803 # @param theFineness is:
804 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
806 # Only for algoType == NETGEN
807 def SetFineness(self, theFineness):
808 if self.params == 0 and self.Parameters():
809 self.params.SetFineness(theFineness)
813 # Only for algoType == NETGEN
814 def SetGrowthRate(self, theRate):
815 if self.params == 0 and self.Parameters():
816 self.params.SetGrowthRate(theRate)
820 # Only for algoType == NETGEN
821 def SetNbSegPerEdge(self, theVal):
822 if self.params == 0 and self.Parameters():
823 self.params.SetNbSegPerEdge(theVal)
825 ## Set NbSegPerRadius
827 # Only for algoType == NETGEN
828 def SetNbSegPerRadius(self, theVal):
829 if self.params == 0 and self.Parameters():
830 self.params.SetNbSegPerRadius(theVal)
835 # Public class: Mesh_Quadrangle
836 # -----------------------------
838 ## Class to define a quadrangle 2D algorithm
841 class Mesh_Quadrangle(Mesh_Algorithm):
843 algo = 0 # algorithm object common for all Mesh_Quadrangles
845 ## Private constructor.
846 def __init__(self, mesh, geom=0):
847 if not Mesh_Quadrangle.algo:
848 Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
850 self.Assign( Mesh_Quadrangle.algo, mesh, geom)
853 ## Define "QuadranglePreference" hypothesis, forcing construction
854 # of quadrangles if the number of nodes on opposite edges is not the same
855 # in the case where the global number of nodes on edges is even
856 def QuadranglePreference(self):
857 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
860 # Public class: Mesh_Tetrahedron
861 # ------------------------------
863 ## Class to define a tetrahedron 3D algorithm
866 class Mesh_Tetrahedron(Mesh_Algorithm):
871 algoNET = 0 # algorithm object common for all Mesh_Tetrahedrons
872 algoGHS = 0 # algorithm object common for all Mesh_Tetrahedrons
873 algoFNET = 0 # algorithm object common for all Mesh_Tetrahedrons
875 ## Private constructor.
876 def __init__(self, mesh, algoType, geom=0):
877 if algoType == NETGEN:
878 if not Mesh_Tetrahedron.algoNET:
879 Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
881 self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
885 elif algoType == GHS3D:
886 if not Mesh_Tetrahedron.algoGHS:
888 Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
890 self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
894 elif algoType == FULL_NETGEN:
896 print "Warning: NETGENPlugin module has not been imported."
897 if not Mesh_Tetrahedron.algoFNET:
898 Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
900 self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
904 self.algoType = algoType
906 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
907 # @param vol for the maximum volume of each tetrahedral
908 # @param UseExisting if ==true - search existing hypothesis created with
909 # same parameters, else (default) - create new
910 def MaxElementVolume(self, vol, UseExisting=0):
911 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
912 hyp.SetMaxElementVolume(vol)
915 ## Define "Netgen 3D Parameters" hypothesis
916 def Parameters(self):
917 if (self.algoType == FULL_NETGEN):
918 self.params = self.Hypothesis("NETGEN_Parameters", [],
919 "libNETGENEngine.so", UseExisting=0)
922 print "Algo doesn't support this hypothesis"
926 def SetMaxSize(self, theSize):
929 self.params.SetMaxSize(theSize)
931 ## Set SecondOrder flag
932 def SetSecondOrder(self, theVal):
935 self.params.SetSecondOrder(theVal)
938 def SetOptimize(self, theVal):
941 self.params.SetOptimize(theVal)
944 # @param theFineness is:
945 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
946 def SetFineness(self, theFineness):
949 self.params.SetFineness(theFineness)
952 def SetGrowthRate(self, theRate):
955 self.params.SetGrowthRate(theRate)
958 def SetNbSegPerEdge(self, theVal):
961 self.params.SetNbSegPerEdge(theVal)
963 ## Set NbSegPerRadius
964 def SetNbSegPerRadius(self, theVal):
967 self.params.SetNbSegPerRadius(theVal)
969 # Public class: Mesh_Hexahedron
970 # ------------------------------
972 ## Class to define a hexahedron 3D algorithm
975 class Mesh_Hexahedron(Mesh_Algorithm):
977 algo = 0 # algorithm object common for all Mesh_Hexahedrons
979 ## Private constructor.
980 def __init__(self, mesh, geom=0):
981 if not Mesh_Hexahedron.algo:
982 Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
984 self.Assign( Mesh_Hexahedron.algo, mesh, geom)
987 # Deprecated, only for compatibility!
988 # Public class: Mesh_Netgen
989 # ------------------------------
991 ## Class to define a NETGEN-based 2D or 3D algorithm
992 # that need no discrete boundary (i.e. independent)
994 # This class is deprecated, only for compatibility!
997 class Mesh_Netgen(Mesh_Algorithm):
1001 algoNET23 = 0 # algorithm object common for all Mesh_Netgens
1002 algoNET2 = 0 # algorithm object common for all Mesh_Netgens
1004 ## Private constructor.
1005 def __init__(self, mesh, is3D, geom=0):
1007 print "Warning: NETGENPlugin module has not been imported."
1011 if not Mesh_Netgen.algoNET23:
1012 Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1014 self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1019 if not Mesh_Netgen.algoNET2:
1020 Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1022 self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1026 ## Define hypothesis containing parameters of the algorithm
1027 def Parameters(self):
1029 hyp = self.Hypothesis("NETGEN_Parameters", [],
1030 "libNETGENEngine.so", UseExisting=0)
1032 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1033 "libNETGENEngine.so", UseExisting=0)
1036 # Public class: Mesh_Projection1D
1037 # ------------------------------
1039 ## Class to define a projection 1D algorithm
1042 class Mesh_Projection1D(Mesh_Algorithm):
1044 algo = 0 # algorithm object common for all Mesh_Projection1Ds
1046 ## Private constructor.
1047 def __init__(self, mesh, geom=0):
1048 if not Mesh_Projection1D.algo:
1049 Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1051 self.Assign( Mesh_Projection1D.algo, mesh, geom)
1054 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1055 # take a mesh pattern from, and optionally association of vertices
1056 # between the source edge and a target one (where a hipothesis is assigned to)
1057 # @param edge to take nodes distribution from
1058 # @param mesh to take nodes distribution from (optional)
1059 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1060 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1061 # to associate with \a srcV (optional)
1062 # @param UseExisting if ==true - search existing hypothesis created with
1063 # same parameters, else (default) - create new
1064 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1065 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1066 hyp.SetSourceEdge( edge )
1067 if not mesh is None and isinstance(mesh, Mesh):
1068 mesh = mesh.GetMesh()
1069 hyp.SetSourceMesh( mesh )
1070 hyp.SetVertexAssociation( srcV, tgtV )
1074 # Public class: Mesh_Projection2D
1075 # ------------------------------
1077 ## Class to define a projection 2D algorithm
1080 class Mesh_Projection2D(Mesh_Algorithm):
1082 algo = 0 # algorithm object common for all Mesh_Projection2Ds
1084 ## Private constructor.
1085 def __init__(self, mesh, geom=0):
1086 if not Mesh_Projection2D.algo:
1087 Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1089 self.Assign( Mesh_Projection2D.algo, mesh, geom)
1092 ## Define "Source Face" hypothesis, specifying a meshed face to
1093 # take a mesh pattern from, and optionally association of vertices
1094 # between the source face and a target one (where a hipothesis is assigned to)
1095 # @param face to take mesh pattern from
1096 # @param mesh to take mesh pattern from (optional)
1097 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1098 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1099 # to associate with \a srcV1 (optional)
1100 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1101 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1102 # to associate with \a srcV2 (optional)
1103 # @param UseExisting if ==true - search existing hypothesis created with
1104 # same parameters, else (default) - create new
1106 # Note: association vertices must belong to one edge of a face
1107 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1108 srcV2=None, tgtV2=None, UseExisting=0):
1109 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1110 UseExisting=UseExisting)
1111 hyp.SetSourceFace( face )
1112 if not mesh is None and isinstance(mesh, Mesh):
1113 mesh = mesh.GetMesh()
1114 hyp.SetSourceMesh( mesh )
1115 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1118 # Public class: Mesh_Projection3D
1119 # ------------------------------
1121 ## Class to define a projection 3D algorithm
1124 class Mesh_Projection3D(Mesh_Algorithm):
1126 algo = 0 # algorithm object common for all Mesh_Projection3Ds
1128 ## Private constructor.
1129 def __init__(self, mesh, geom=0):
1130 if not Mesh_Projection3D.algo:
1131 Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1133 self.Assign( Mesh_Projection3D.algo, mesh, geom)
1136 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1137 # take a mesh pattern from, and optionally association of vertices
1138 # between the source solid and a target one (where a hipothesis is assigned to)
1139 # @param solid to take mesh pattern from
1140 # @param mesh to take mesh pattern from (optional)
1141 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1142 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1143 # to associate with \a srcV1 (optional)
1144 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1145 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1146 # to associate with \a srcV2 (optional)
1147 # @param UseExisting - if ==true - search existing hypothesis created with
1148 # same parameters, else (default) - create new
1150 # Note: association vertices must belong to one edge of a solid
1151 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1152 srcV2=0, tgtV2=0, UseExisting=0):
1153 hyp = self.Hypothesis("ProjectionSource3D",
1154 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1155 UseExisting=UseExisting)
1156 hyp.SetSource3DShape( solid )
1157 if not mesh is None and isinstance(mesh, Mesh):
1158 mesh = mesh.GetMesh()
1159 hyp.SetSourceMesh( mesh )
1160 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1164 # Public class: Mesh_Prism
1165 # ------------------------
1167 ## Class to define a 3D extrusion algorithm
1170 class Mesh_Prism3D(Mesh_Algorithm):
1172 algo = 0 # algorithm object common for all Mesh_Prism3Ds
1174 ## Private constructor.
1175 def __init__(self, mesh, geom=0):
1176 if not Mesh_Prism3D.algo:
1177 Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1179 self.Assign( Mesh_Prism3D.algo, mesh, geom)
1182 # Public class: Mesh_RadialPrism
1183 # -------------------------------
1185 ## Class to define a Radial Prism 3D algorithm
1188 class Mesh_RadialPrism3D(Mesh_Algorithm):
1190 algo = 0 # algorithm object common for all Mesh_RadialPrism3Ds
1192 ## Private constructor.
1193 def __init__(self, mesh, geom=0):
1194 if not Mesh_RadialPrism3D.algo:
1195 Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1197 self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1199 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1200 self.nbLayers = None
1202 ## Return 3D hypothesis holding the 1D one
1203 def Get3DHypothesis(self):
1204 return self.distribHyp
1206 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1207 # hypothes. Returns the created hypothes
1208 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1209 if not self.nbLayers is None:
1210 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1211 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1212 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
1213 hyp = smesh.CreateHypothesis(hypType, so)
1214 SetCurrentStudy( study ) # anable publishing
1215 self.distribHyp.SetLayerDistribution( hyp )
1218 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1219 # prisms to build between the inner and outer shells
1220 # @param UseExisting if ==true - search existing hypothesis created with
1221 # same parameters, else (default) - create new
1222 def NumberOfLayers(self, n, UseExisting=0):
1223 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1224 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1225 self.nbLayers.SetNumberOfLayers( n )
1226 return self.nbLayers
1228 ## Define "LocalLength" hypothesis, specifying segment length
1229 # to build between the inner and outer shells
1230 # @param l for the length of segments
1231 def LocalLength(self, l):
1232 hyp = self.OwnHypothesis("LocalLength", [l] )
1236 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1237 # prisms to build between the inner and outer shells
1238 # @param n for the number of segments
1239 # @param s for the scale factor (optional)
1240 def NumberOfSegments(self, n, s=[]):
1242 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1244 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1245 hyp.SetDistrType( 1 )
1246 hyp.SetScaleFactor(s)
1247 hyp.SetNumberOfSegments(n)
1250 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1251 # to build between the inner and outer shells as arithmetic length increasing
1252 # @param start for the length of the first segment
1253 # @param end for the length of the last segment
1254 def Arithmetic1D(self, start, end ):
1255 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1256 hyp.SetLength(start, 1)
1257 hyp.SetLength(end , 0)
1260 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1261 # to build between the inner and outer shells as geometric length increasing
1262 # @param start for the length of the first segment
1263 # @param end for the length of the last segment
1264 def StartEndLength(self, start, end):
1265 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1266 hyp.SetLength(start, 1)
1267 hyp.SetLength(end , 0)
1270 ## Define "AutomaticLength" hypothesis, specifying number of segments
1271 # to build between the inner and outer shells
1272 # @param fineness for the fineness [0-1]
1273 def AutomaticLength(self, fineness=0):
1274 hyp = self.OwnHypothesis("AutomaticLength")
1275 hyp.SetFineness( fineness )
1279 # Public class: Mesh
1280 # ==================
1282 ## Class to define a mesh
1284 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1294 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1295 # sets GUI name of this mesh to \a name.
1296 # @param obj Shape to be meshed or SMESH_Mesh object
1297 # @param name Study name of the mesh
1298 def __init__(self, obj=0, name=0):
1302 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1304 self.mesh = smesh.CreateMesh(self.geom)
1305 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1308 self.mesh = smesh.CreateEmptyMesh()
1310 SetName(self.mesh, name)
1312 SetName(self.mesh, GetName(obj))
1314 self.editor = self.mesh.GetMeshEditor()
1316 ## Method that inits the Mesh object from SMESH_Mesh interface
1317 # @param theMesh is SMESH_Mesh object
1318 def SetMesh(self, theMesh):
1320 self.geom = self.mesh.GetShapeToMesh()
1322 ## Method that returns the mesh
1323 # @return SMESH_Mesh object
1329 name = GetName(self.GetMesh())
1333 def SetName(self, name):
1334 SetName(self.GetMesh(), name)
1336 ## Get the subMesh object associated to a subShape. The subMesh object
1337 # gives access to nodes and elements IDs.
1338 # \n SubMesh will be used instead of SubShape in a next idl version to
1339 # adress a specific subMesh...
1340 def GetSubMesh(self, theSubObject, name):
1341 submesh = self.mesh.GetSubMesh(theSubObject, name)
1344 ## Method that returns the shape associated to the mesh
1345 # @return GEOM_Object
1349 ## Method that associates given shape to the mesh(entails the mesh recreation)
1350 # @param geom shape to be meshed(GEOM_Object)
1351 def SetShape(self, geom):
1352 self.mesh = smesh.CreateMesh(geom)
1354 ## Return true if hypotheses are defined well
1355 # @param theMesh is an instance of Mesh class
1356 # @param theSubObject subshape of a mesh shape
1357 def IsReadyToCompute(self, theSubObject):
1358 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1360 ## Return errors of hypotheses definintion
1361 # error list is empty if everything is OK
1362 # @param theMesh is an instance of Mesh class
1363 # @param theSubObject subshape of a mesh shape
1364 # @return a list of errors
1365 def GetAlgoState(self, theSubObject):
1366 return smesh.GetAlgoState(self.mesh, theSubObject)
1368 ## Return geometrical object the given element is built on.
1369 # The returned geometrical object, if not nil, is either found in the
1370 # study or is published by this method with the given name
1371 # @param theMesh is an instance of Mesh class
1372 # @param theElementID an id of the mesh element
1373 # @param theGeomName user defined name of geometrical object
1374 # @return GEOM::GEOM_Object instance
1375 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1376 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1378 ## Returns mesh dimension depending on shape one
1379 def MeshDimension(self):
1380 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1381 if len( shells ) > 0 :
1383 elif geompy.NumberOfFaces( self.geom ) > 0 :
1385 elif geompy.NumberOfEdges( self.geom ) > 0 :
1391 ## Creates a segment discretization 1D algorithm.
1392 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1393 # If the optional \a geom parameter is not sets, this algorithm is global.
1394 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1395 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1396 # @param geom If defined, subshape to be meshed
1397 def Segment(self, algo=REGULAR, geom=0):
1398 ## if Segment(geom) is called by mistake
1399 if isinstance( algo, geompy.GEOM._objref_GEOM_Object):
1400 algo, geom = geom, algo
1401 if not algo: algo = REGULAR
1404 return Mesh_Segment(self, geom)
1405 elif algo == PYTHON:
1406 return Mesh_Segment_Python(self, geom)
1407 elif algo == COMPOSITE:
1408 return Mesh_CompositeSegment(self, geom)
1410 return Mesh_Segment(self, geom)
1412 ## Creates a triangle 2D algorithm for faces.
1413 # If the optional \a geom parameter is not sets, this algorithm is global.
1414 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1415 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1416 # @param geom If defined, subshape to be meshed
1417 def Triangle(self, algo=MEFISTO, geom=0):
1418 ## if Triangle(geom) is called by mistake
1419 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1423 return Mesh_Triangle(self, algo, geom)
1425 ## Creates a quadrangle 2D algorithm for faces.
1426 # If the optional \a geom parameter is not sets, this algorithm is global.
1427 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1428 # @param geom If defined, subshape to be meshed
1429 def Quadrangle(self, geom=0):
1430 return Mesh_Quadrangle(self, geom)
1432 ## Creates a tetrahedron 3D algorithm for solids.
1433 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1434 # If the optional \a geom parameter is not sets, this algorithm is global.
1435 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1436 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1437 # @param geom If defined, subshape to be meshed
1438 def Tetrahedron(self, algo=NETGEN, geom=0):
1439 ## if Tetrahedron(geom) is called by mistake
1440 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1441 algo, geom = geom, algo
1442 if not algo: algo = NETGEN
1444 return Mesh_Tetrahedron(self, algo, geom)
1446 ## Creates a hexahedron 3D algorithm for solids.
1447 # If the optional \a geom parameter is not sets, this algorithm is global.
1448 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1449 # @param geom If defined, subshape to be meshed
1450 def Hexahedron(self, geom=0):
1451 return Mesh_Hexahedron(self, geom)
1453 ## Deprecated, only for compatibility!
1454 def Netgen(self, is3D, geom=0):
1455 return Mesh_Netgen(self, is3D, geom)
1457 ## Creates a projection 1D algorithm for edges.
1458 # If the optional \a geom parameter is not sets, this algorithm is global.
1459 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1460 # @param geom If defined, subshape to be meshed
1461 def Projection1D(self, geom=0):
1462 return Mesh_Projection1D(self, geom)
1464 ## Creates a projection 2D algorithm for faces.
1465 # If the optional \a geom parameter is not sets, this algorithm is global.
1466 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1467 # @param geom If defined, subshape to be meshed
1468 def Projection2D(self, geom=0):
1469 return Mesh_Projection2D(self, geom)
1471 ## Creates a projection 3D algorithm for solids.
1472 # If the optional \a geom parameter is not sets, this algorithm is global.
1473 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1474 # @param geom If defined, subshape to be meshed
1475 def Projection3D(self, geom=0):
1476 return Mesh_Projection3D(self, geom)
1478 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1479 # If the optional \a geom parameter is not sets, this algorithm is global.
1480 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1481 # @param geom If defined, subshape to be meshed
1482 def Prism(self, geom=0):
1486 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1487 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1488 if nbSolids == 0 or nbSolids == nbShells:
1489 return Mesh_Prism3D(self, geom)
1490 return Mesh_RadialPrism3D(self, geom)
1492 ## Compute the mesh and return the status of the computation
1493 def Compute(self, geom=0):
1494 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1496 print "Compute impossible: mesh is not constructed on geom shape."
1502 ok = smesh.Compute(self.mesh, geom)
1503 except SALOME.SALOME_Exception, ex:
1504 print "Mesh computation failed, exception cought:"
1505 print " ", ex.details.text
1508 print "Mesh computation failed, exception cought:"
1509 traceback.print_exc()
1511 errors = smesh.GetAlgoState( self.mesh, geom )
1514 if err.isGlobalAlgo:
1519 dim = str(err.algoDim)
1520 if err.name == MISSING_ALGO:
1521 reason = glob + dim + "D algorithm is missing"
1522 elif err.name == MISSING_HYPO:
1523 name = '"' + err.algoName + '"'
1524 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1525 elif err.name == NOT_CONFORM_MESH:
1526 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1527 elif err.name == BAD_PARAM_VALUE:
1528 name = '"' + err.algoName + '"'
1529 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1530 " has a bad parameter value"
1532 reason = "For unknown reason."+\
1533 " Revise Mesh.Compute() implementation in smesh.py!"
1535 if allReasons != "":
1538 allReasons += reason
1540 if allReasons != "":
1541 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1544 print '"' + GetName(self.mesh) + '"',"has not been computed."
1547 if salome.sg.hasDesktop():
1548 smeshgui = salome.ImportComponentGUI("SMESH")
1549 smeshgui.Init(salome.myStudyId)
1550 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1551 salome.sg.updateObjBrowser(1)
1555 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1556 # The parameter \a fineness [0,-1] defines mesh fineness
1557 def AutomaticTetrahedralization(self, fineness=0):
1558 dim = self.MeshDimension()
1560 self.RemoveGlobalHypotheses()
1561 self.Segment().AutomaticLength(fineness)
1563 self.Triangle().LengthFromEdges()
1566 self.Tetrahedron(NETGEN)
1568 return self.Compute()
1570 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1571 # The parameter \a fineness [0,-1] defines mesh fineness
1572 def AutomaticHexahedralization(self, fineness=0):
1573 dim = self.MeshDimension()
1575 self.RemoveGlobalHypotheses()
1576 self.Segment().AutomaticLength(fineness)
1583 return self.Compute()
1585 ## Assign hypothesis
1586 # @param hyp is a hypothesis to assign
1587 # @param geom is subhape of mesh geometry
1588 def AddHypothesis(self, hyp, geom=0 ):
1589 if isinstance( hyp, Mesh_Algorithm ):
1590 hyp = hyp.GetAlgorithm()
1595 status = self.mesh.AddHypothesis(geom, hyp)
1596 isAlgo = hyp._narrow( SMESH_Algo )
1597 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1600 ## Unassign hypothesis
1601 # @param hyp is a hypothesis to unassign
1602 # @param geom is subhape of mesh geometry
1603 def RemoveHypothesis(self, hyp, geom=0 ):
1604 if isinstance( hyp, Mesh_Algorithm ):
1605 hyp = hyp.GetAlgorithm()
1610 status = self.mesh.RemoveHypothesis(geom, hyp)
1613 ## Get the list of hypothesis added on a geom
1614 # @param geom is subhape of mesh geometry
1615 def GetHypothesisList(self, geom):
1616 return self.mesh.GetHypothesisList( geom )
1618 ## Removes all global hypotheses
1619 def RemoveGlobalHypotheses(self):
1620 current_hyps = self.mesh.GetHypothesisList( self.geom )
1621 for hyp in current_hyps:
1622 self.mesh.RemoveHypothesis( self.geom, hyp )
1626 ## Create a mesh group based on geometric object \a grp
1627 # and give a \a name, \n if this parameter is not defined
1628 # the name is the same as the geometric group name \n
1629 # Note: Works like GroupOnGeom().
1630 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1631 # @param name is the name of the mesh group
1632 # @return SMESH_GroupOnGeom
1633 def Group(self, grp, name=""):
1634 return self.GroupOnGeom(grp, name)
1636 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1637 # Export the mesh in a file with the MED format and choice the \a version of MED format
1638 # @param f is the file name
1639 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1640 def ExportToMED(self, f, version, opt=0):
1641 self.mesh.ExportToMED(f, opt, version)
1643 ## Export the mesh in a file with the MED format
1644 # @param f is the file name
1645 # @param auto_groups boolean parameter for creating/not creating
1646 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1647 # the typical use is auto_groups=false.
1648 # @param version MED format version(MED_V2_1 or MED_V2_2)
1649 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1650 self.mesh.ExportToMED(f, auto_groups, version)
1652 ## Export the mesh in a file with the DAT format
1653 # @param f is the file name
1654 def ExportDAT(self, f):
1655 self.mesh.ExportDAT(f)
1657 ## Export the mesh in a file with the UNV format
1658 # @param f is the file name
1659 def ExportUNV(self, f):
1660 self.mesh.ExportUNV(f)
1662 ## Export the mesh in a file with the STL format
1663 # @param f is the file name
1664 # @param ascii defined the kind of file contents
1665 def ExportSTL(self, f, ascii=1):
1666 self.mesh.ExportSTL(f, ascii)
1669 # Operations with groups:
1670 # ----------------------
1672 ## Creates an empty mesh group
1673 # @param elementType is the type of elements in the group
1674 # @param name is the name of the mesh group
1675 # @return SMESH_Group
1676 def CreateEmptyGroup(self, elementType, name):
1677 return self.mesh.CreateGroup(elementType, name)
1679 ## Creates a mesh group based on geometric object \a grp
1680 # and give a \a name, \n if this parameter is not defined
1681 # the name is the same as the geometric group name
1682 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1683 # @param name is the name of the mesh group
1684 # @return SMESH_GroupOnGeom
1685 def GroupOnGeom(self, grp, name="", type=None):
1687 name = grp.GetName()
1690 tgeo = str(grp.GetShapeType())
1691 if tgeo == "VERTEX":
1693 elif tgeo == "EDGE":
1695 elif tgeo == "FACE":
1697 elif tgeo == "SOLID":
1699 elif tgeo == "SHELL":
1701 elif tgeo == "COMPOUND":
1702 if len( geompy.GetObjectIDs( grp )) == 0:
1703 print "Mesh.Group: empty geometric group", GetName( grp )
1705 tgeo = geompy.GetType(grp)
1706 if tgeo == geompy.ShapeType["VERTEX"]:
1708 elif tgeo == geompy.ShapeType["EDGE"]:
1710 elif tgeo == geompy.ShapeType["FACE"]:
1712 elif tgeo == geompy.ShapeType["SOLID"]:
1716 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1719 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1721 ## Create a mesh group by the given ids of elements
1722 # @param groupName is the name of the mesh group
1723 # @param elementType is the type of elements in the group
1724 # @param elemIDs is the list of ids
1725 # @return SMESH_Group
1726 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1727 group = self.mesh.CreateGroup(elementType, groupName)
1731 ## Create a mesh group by the given conditions
1732 # @param groupName is the name of the mesh group
1733 # @param elementType is the type of elements in the group
1734 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1735 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1736 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1737 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1738 # @return SMESH_Group
1742 CritType=FT_Undefined,
1745 UnaryOp=FT_Undefined):
1746 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1747 group = self.MakeGroupByCriterion(groupName, aCriterion)
1750 ## Create a mesh group by the given criterion
1751 # @param groupName is the name of the mesh group
1752 # @param Criterion is the instance of Criterion class
1753 # @return SMESH_Group
1754 def MakeGroupByCriterion(self, groupName, Criterion):
1755 aFilterMgr = smesh.CreateFilterManager()
1756 aFilter = aFilterMgr.CreateFilter()
1758 aCriteria.append(Criterion)
1759 aFilter.SetCriteria(aCriteria)
1760 group = self.MakeGroupByFilter(groupName, aFilter)
1763 ## Create a mesh group by the given criteria(list of criterions)
1764 # @param groupName is the name of the mesh group
1765 # @param Criteria is the list of criterions
1766 # @return SMESH_Group
1767 def MakeGroupByCriteria(self, groupName, theCriteria):
1768 aFilterMgr = smesh.CreateFilterManager()
1769 aFilter = aFilterMgr.CreateFilter()
1770 aFilter.SetCriteria(theCriteria)
1771 group = self.MakeGroupByFilter(groupName, aFilter)
1774 ## Create a mesh group by the given filter
1775 # @param groupName is the name of the mesh group
1776 # @param Criterion is the instance of Filter class
1777 # @return SMESH_Group
1778 def MakeGroupByFilter(self, groupName, theFilter):
1779 anIds = theFilter.GetElementsId(self.mesh)
1780 anElemType = theFilter.GetElementType()
1781 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1784 ## Pass mesh elements through the given filter and return ids
1785 # @param theFilter is SMESH_Filter
1786 # @return list of ids
1787 def GetIdsFromFilter(self, theFilter):
1788 return theFilter.GetElementsId(self.mesh)
1790 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1791 # Returns list of special structures(borders).
1792 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1793 def GetFreeBorders(self):
1794 aFilterMgr = smesh.CreateFilterManager()
1795 aPredicate = aFilterMgr.CreateFreeEdges()
1796 aPredicate.SetMesh(self.mesh)
1797 aBorders = aPredicate.GetBorders()
1801 def RemoveGroup(self, group):
1802 self.mesh.RemoveGroup(group)
1804 ## Remove group with its contents
1805 def RemoveGroupWithContents(self, group):
1806 self.mesh.RemoveGroupWithContents(group)
1808 ## Get the list of groups existing in the mesh
1809 def GetGroups(self):
1810 return self.mesh.GetGroups()
1812 ## Get the list of names of groups existing in the mesh
1813 def GetGroupNames(self):
1814 groups = self.GetGroups()
1816 for group in groups:
1817 names.append(group.GetName())
1820 ## Union of two groups
1821 # New group is created. All mesh elements that are
1822 # present in initial groups are added to the new one
1823 def UnionGroups(self, group1, group2, name):
1824 return self.mesh.UnionGroups(group1, group2, name)
1826 ## Intersection of two groups
1827 # New group is created. All mesh elements that are
1828 # present in both initial groups are added to the new one.
1829 def IntersectGroups(self, group1, group2, name):
1830 return self.mesh.IntersectGroups(group1, group2, name)
1832 ## Cut of two groups
1833 # New group is created. All mesh elements that are present in
1834 # main group but do not present in tool group are added to the new one
1835 def CutGroups(self, mainGroup, toolGroup, name):
1836 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1839 # Get some info about mesh:
1840 # ------------------------
1842 ## Get the log of nodes and elements added or removed since previous
1844 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1845 # @return list of log_block structures:
1850 def GetLog(self, clearAfterGet):
1851 return self.mesh.GetLog(clearAfterGet)
1853 ## Clear the log of nodes and elements added or removed since previous
1854 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1856 self.mesh.ClearLog()
1858 ## Get the internal Id
1860 return self.mesh.GetId()
1863 def GetStudyId(self):
1864 return self.mesh.GetStudyId()
1866 ## Check group names for duplications.
1867 # Consider maximum group name length stored in MED file.
1868 def HasDuplicatedGroupNamesMED(self):
1869 return self.mesh.HasDuplicatedGroupNamesMED()
1871 ## Obtain instance of SMESH_MeshEditor
1872 def GetMeshEditor(self):
1873 return self.mesh.GetMeshEditor()
1876 def GetMEDMesh(self):
1877 return self.mesh.GetMEDMesh()
1880 # Get informations about mesh contents:
1881 # ------------------------------------
1883 ## Returns number of nodes in mesh
1885 return self.mesh.NbNodes()
1887 ## Returns number of elements in mesh
1888 def NbElements(self):
1889 return self.mesh.NbElements()
1891 ## Returns number of edges in mesh
1893 return self.mesh.NbEdges()
1895 ## Returns number of edges with given order in mesh
1896 # @param elementOrder is order of elements:
1897 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1898 def NbEdgesOfOrder(self, elementOrder):
1899 return self.mesh.NbEdgesOfOrder(elementOrder)
1901 ## Returns number of faces in mesh
1903 return self.mesh.NbFaces()
1905 ## Returns number of faces with given order in mesh
1906 # @param elementOrder is order of elements:
1907 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1908 def NbFacesOfOrder(self, elementOrder):
1909 return self.mesh.NbFacesOfOrder(elementOrder)
1911 ## Returns number of triangles in mesh
1912 def NbTriangles(self):
1913 return self.mesh.NbTriangles()
1915 ## Returns number of triangles with given order in mesh
1916 # @param elementOrder is order of elements:
1917 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1918 def NbTrianglesOfOrder(self, elementOrder):
1919 return self.mesh.NbTrianglesOfOrder(elementOrder)
1921 ## Returns number of quadrangles in mesh
1922 def NbQuadrangles(self):
1923 return self.mesh.NbQuadrangles()
1925 ## Returns number of quadrangles with given order in mesh
1926 # @param elementOrder is order of elements:
1927 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1928 def NbQuadranglesOfOrder(self, elementOrder):
1929 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1931 ## Returns number of polygons in mesh
1932 def NbPolygons(self):
1933 return self.mesh.NbPolygons()
1935 ## Returns number of volumes in mesh
1936 def NbVolumes(self):
1937 return self.mesh.NbVolumes()
1939 ## Returns number of volumes with given order in mesh
1940 # @param elementOrder is order of elements:
1941 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1942 def NbVolumesOfOrder(self, elementOrder):
1943 return self.mesh.NbVolumesOfOrder(elementOrder)
1945 ## Returns number of tetrahedrons in mesh
1947 return self.mesh.NbTetras()
1949 ## Returns number of tetrahedrons with given order in mesh
1950 # @param elementOrder is order of elements:
1951 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1952 def NbTetrasOfOrder(self, elementOrder):
1953 return self.mesh.NbTetrasOfOrder(elementOrder)
1955 ## Returns number of hexahedrons in mesh
1957 return self.mesh.NbHexas()
1959 ## Returns number of hexahedrons with given order in mesh
1960 # @param elementOrder is order of elements:
1961 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1962 def NbHexasOfOrder(self, elementOrder):
1963 return self.mesh.NbHexasOfOrder(elementOrder)
1965 ## Returns number of pyramids in mesh
1966 def NbPyramids(self):
1967 return self.mesh.NbPyramids()
1969 ## Returns number of pyramids with given order in mesh
1970 # @param elementOrder is order of elements:
1971 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1972 def NbPyramidsOfOrder(self, elementOrder):
1973 return self.mesh.NbPyramidsOfOrder(elementOrder)
1975 ## Returns number of prisms in mesh
1977 return self.mesh.NbPrisms()
1979 ## Returns number of prisms with given order in mesh
1980 # @param elementOrder is order of elements:
1981 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1982 def NbPrismsOfOrder(self, elementOrder):
1983 return self.mesh.NbPrismsOfOrder(elementOrder)
1985 ## Returns number of polyhedrons in mesh
1986 def NbPolyhedrons(self):
1987 return self.mesh.NbPolyhedrons()
1989 ## Returns number of submeshes in mesh
1990 def NbSubMesh(self):
1991 return self.mesh.NbSubMesh()
1993 ## Returns list of mesh elements ids
1994 def GetElementsId(self):
1995 return self.mesh.GetElementsId()
1997 ## Returns list of ids of mesh elements with given type
1998 # @param elementType is required type of elements
1999 def GetElementsByType(self, elementType):
2000 return self.mesh.GetElementsByType(elementType)
2002 ## Returns list of mesh nodes ids
2003 def GetNodesId(self):
2004 return self.mesh.GetNodesId()
2006 # Get informations about mesh elements:
2007 # ------------------------------------
2009 ## Returns type of mesh element
2010 def GetElementType(self, id, iselem):
2011 return self.mesh.GetElementType(id, iselem)
2013 ## Returns list of submesh elements ids
2014 # @param shapeID is geom object(subshape) IOR
2015 def GetSubMeshElementsId(self, shapeID):
2016 return self.mesh.GetSubMeshElementsId(shapeID)
2018 ## Returns list of submesh nodes ids
2019 # @param shapeID is geom object(subshape) IOR
2020 def GetSubMeshNodesId(self, shapeID, all):
2021 return self.mesh.GetSubMeshNodesId(shapeID, all)
2023 ## Returns list of ids of submesh elements with given type
2024 # @param shapeID is geom object(subshape) IOR
2025 def GetSubMeshElementType(self, shapeID):
2026 return self.mesh.GetSubMeshElementType(shapeID)
2028 ## Get mesh description
2030 return self.mesh.Dump()
2033 # Get information about nodes and elements of mesh by its ids:
2034 # -----------------------------------------------------------
2036 ## Get XYZ coordinates of node as list of double
2037 # \n If there is not node for given ID - returns empty list
2038 def GetNodeXYZ(self, id):
2039 return self.mesh.GetNodeXYZ(id)
2041 ## For given node returns list of IDs of inverse elements
2042 # \n If there is not node for given ID - returns empty list
2043 def GetNodeInverseElements(self, id):
2044 return self.mesh.GetNodeInverseElements(id)
2046 ## If given element is node returns IDs of shape from position
2047 # \n If there is not node for given ID - returns -1
2048 def GetShapeID(self, id):
2049 return self.mesh.GetShapeID(id)
2051 ## For given element returns ID of result shape after
2052 # FindShape() from SMESH_MeshEditor
2053 # \n If there is not element for given ID - returns -1
2054 def GetShapeIDForElem(self,id):
2055 return self.mesh.GetShapeIDForElem(id)
2057 ## Returns number of nodes for given element
2058 # \n If there is not element for given ID - returns -1
2059 def GetElemNbNodes(self, id):
2060 return self.mesh.GetElemNbNodes(id)
2062 ## Returns ID of node by given index for given element
2063 # \n If there is not element for given ID - returns -1
2064 # \n If there is not node for given index - returns -2
2065 def GetElemNode(self, id, index):
2066 return self.mesh.GetElemNode(id, index)
2068 ## Returns IDs of nodes of given element
2069 def GetElemNodes(self, id):
2070 return self.mesh.GetElemNodes(id)
2072 ## Returns true if given node is medium node
2073 # in given quadratic element
2074 def IsMediumNode(self, elementID, nodeID):
2075 return self.mesh.IsMediumNode(elementID, nodeID)
2077 ## Returns true if given node is medium node
2078 # in one of quadratic elements
2079 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2080 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2082 ## Returns number of edges for given element
2083 def ElemNbEdges(self, id):
2084 return self.mesh.ElemNbEdges(id)
2086 ## Returns number of faces for given element
2087 def ElemNbFaces(self, id):
2088 return self.mesh.ElemNbFaces(id)
2090 ## Returns true if given element is polygon
2091 def IsPoly(self, id):
2092 return self.mesh.IsPoly(id)
2094 ## Returns true if given element is quadratic
2095 def IsQuadratic(self, id):
2096 return self.mesh.IsQuadratic(id)
2098 ## Returns XYZ coordinates of bary center for given element
2100 # \n If there is not element for given ID - returns empty list
2101 def BaryCenter(self, id):
2102 return self.mesh.BaryCenter(id)
2105 # Mesh edition (SMESH_MeshEditor functionality):
2106 # ---------------------------------------------
2108 ## Removes elements from mesh by ids
2109 # @param IDsOfElements is list of ids of elements to remove
2110 def RemoveElements(self, IDsOfElements):
2111 return self.editor.RemoveElements(IDsOfElements)
2113 ## Removes nodes from mesh by ids
2114 # @param IDsOfNodes is list of ids of nodes to remove
2115 def RemoveNodes(self, IDsOfNodes):
2116 return self.editor.RemoveNodes(IDsOfNodes)
2118 ## Add node to mesh by coordinates
2119 def AddNode(self, x, y, z):
2120 return self.editor.AddNode( x, y, z)
2123 ## Create edge both similar and quadratic (this is determed
2124 # by number of given nodes).
2125 # @param IdsOfNodes List of node IDs for creation of element.
2126 # Needed order of nodes in this list corresponds to description
2127 # of MED. \n This description is located by the following link:
2128 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2129 def AddEdge(self, IDsOfNodes):
2130 return self.editor.AddEdge(IDsOfNodes)
2132 ## Create face both similar and quadratic (this is determed
2133 # by number of given nodes).
2134 # @param IdsOfNodes List of node IDs for creation of element.
2135 # Needed order of nodes in this list corresponds to description
2136 # of MED. \n This description is located by the following link:
2137 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2138 def AddFace(self, IDsOfNodes):
2139 return self.editor.AddFace(IDsOfNodes)
2141 ## Add polygonal face to mesh by list of nodes ids
2142 def AddPolygonalFace(self, IdsOfNodes):
2143 return self.editor.AddPolygonalFace(IdsOfNodes)
2145 ## Create volume both similar and quadratic (this is determed
2146 # by number of given nodes).
2147 # @param IdsOfNodes List of node IDs for creation of element.
2148 # Needed order of nodes in this list corresponds to description
2149 # of MED. \n This description is located by the following link:
2150 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2151 def AddVolume(self, IDsOfNodes):
2152 return self.editor.AddVolume(IDsOfNodes)
2154 ## Create volume of many faces, giving nodes for each face.
2155 # @param IdsOfNodes List of node IDs for volume creation face by face.
2156 # @param Quantities List of integer values, Quantities[i]
2157 # gives quantity of nodes in face number i.
2158 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2159 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2161 ## Create volume of many faces, giving IDs of existing faces.
2162 # @param IdsOfFaces List of face IDs for volume creation.
2164 # Note: The created volume will refer only to nodes
2165 # of the given faces, not to the faces itself.
2166 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2167 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2169 ## Move node with given id
2170 # @param NodeID id of the node
2171 # @param x new X coordinate
2172 # @param y new Y coordinate
2173 # @param z new Z coordinate
2174 def MoveNode(self, NodeID, x, y, z):
2175 return self.editor.MoveNode(NodeID, x, y, z)
2177 ## Find a node closest to a point
2178 # @param x X coordinate of a point
2179 # @param y Y coordinate of a point
2180 # @param z Z coordinate of a point
2181 # @return id of a node
2182 def FindNodeClosestTo(self, x, y, z):
2183 preview = self.mesh.GetMeshEditPreviewer()
2184 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2186 ## Find a node closest to a point and move it to a point location
2187 # @param x X coordinate of a point
2188 # @param y Y coordinate of a point
2189 # @param z Z coordinate of a point
2190 # @return id of a moved node
2191 def MeshToPassThroughAPoint(self, x, y, z):
2192 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2194 ## Replace two neighbour triangles sharing Node1-Node2 link
2195 # with ones built on the same 4 nodes but having other common link.
2196 # @param NodeID1 first node id
2197 # @param NodeID2 second node id
2198 # @return false if proper faces not found
2199 def InverseDiag(self, NodeID1, NodeID2):
2200 return self.editor.InverseDiag(NodeID1, NodeID2)
2202 ## Replace two neighbour triangles sharing Node1-Node2 link
2203 # with a quadrangle built on the same 4 nodes.
2204 # @param NodeID1 first node id
2205 # @param NodeID2 second node id
2206 # @return false if proper faces not found
2207 def DeleteDiag(self, NodeID1, NodeID2):
2208 return self.editor.DeleteDiag(NodeID1, NodeID2)
2210 ## Reorient elements by ids
2211 # @param IDsOfElements if undefined reorient all mesh elements
2212 def Reorient(self, IDsOfElements=None):
2213 if IDsOfElements == None:
2214 IDsOfElements = self.GetElementsId()
2215 return self.editor.Reorient(IDsOfElements)
2217 ## Reorient all elements of the object
2218 # @param theObject is mesh, submesh or group
2219 def ReorientObject(self, theObject):
2220 return self.editor.ReorientObject(theObject)
2222 ## Fuse neighbour triangles into quadrangles.
2223 # @param IDsOfElements The triangles to be fused,
2224 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2225 # @param MaxAngle is a max angle between element normals at which fusion
2226 # is still performed; theMaxAngle is mesured in radians.
2227 # @return TRUE in case of success, FALSE otherwise.
2228 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2229 if IDsOfElements == []:
2230 IDsOfElements = self.GetElementsId()
2231 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
2233 ## Fuse neighbour triangles of the object into quadrangles
2234 # @param theObject is mesh, submesh or group
2235 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2236 # @param MaxAngle is a max angle between element normals at which fusion
2237 # is still performed; theMaxAngle is mesured in radians.
2238 # @return TRUE in case of success, FALSE otherwise.
2239 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2240 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
2242 ## Split quadrangles into triangles.
2243 # @param IDsOfElements the faces to be splitted.
2244 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2245 # @param @return TRUE in case of success, FALSE otherwise.
2246 def QuadToTri (self, IDsOfElements, theCriterion):
2247 if IDsOfElements == []:
2248 IDsOfElements = self.GetElementsId()
2249 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
2251 ## Split quadrangles into triangles.
2252 # @param theObject object to taking list of elements from, is mesh, submesh or group
2253 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2254 def QuadToTriObject (self, theObject, theCriterion):
2255 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
2257 ## Split quadrangles into triangles.
2258 # @param theElems The faces to be splitted
2259 # @param the13Diag is used to choose a diagonal for splitting.
2260 # @return TRUE in case of success, FALSE otherwise.
2261 def SplitQuad (self, IDsOfElements, Diag13):
2262 if IDsOfElements == []:
2263 IDsOfElements = self.GetElementsId()
2264 return self.editor.SplitQuad(IDsOfElements, Diag13)
2266 ## Split quadrangles into triangles.
2267 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2268 def SplitQuadObject (self, theObject, Diag13):
2269 return self.editor.SplitQuadObject(theObject, Diag13)
2271 ## Find better splitting of the given quadrangle.
2272 # @param IDOfQuad ID of the quadrangle to be splitted.
2273 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2274 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2275 # diagonal is better, 0 if error occurs.
2276 def BestSplit (self, IDOfQuad, theCriterion):
2277 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2279 ## Split quafrangle faces near triangular facets of volumes
2281 def SplitQuadsNearTriangularFacets(self):
2282 faces_array = self.GetElementsByType(SMESH.FACE)
2283 for face_id in faces_array:
2284 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2285 quad_nodes = self.mesh.GetElemNodes(face_id)
2286 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2287 isVolumeFound = False
2288 for node1_elem in node1_elems:
2289 if not isVolumeFound:
2290 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2291 nb_nodes = self.GetElemNbNodes(node1_elem)
2292 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2293 volume_elem = node1_elem
2294 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2295 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2296 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2297 isVolumeFound = True
2298 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2299 self.SplitQuad([face_id], False) # diagonal 2-4
2300 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2301 isVolumeFound = True
2302 self.SplitQuad([face_id], True) # diagonal 1-3
2303 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2304 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2305 isVolumeFound = True
2306 self.SplitQuad([face_id], True) # diagonal 1-3
2308 ## @brief Split hexahedrons into tetrahedrons.
2310 # Use pattern mapping functionality for splitting.
2311 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2312 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2313 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2314 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2315 # key-point will be mapped into <theNode001>-th node of each volume.
2316 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2317 # @return TRUE in case of success, FALSE otherwise.
2318 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2319 # Pattern: 5.---------.6
2324 # (0,0,1) 4.---------.7 * |
2331 # (0,0,0) 0.---------.3
2332 pattern_tetra = "!!! Nb of points: \n 8 \n\
2342 !!! Indices of points of 6 tetras: \n\
2350 pattern = GetPattern()
2351 isDone = pattern.LoadFromFile(pattern_tetra)
2353 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2356 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2357 isDone = pattern.MakeMesh(self.mesh, False, False)
2358 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2360 # split quafrangle faces near triangular facets of volumes
2361 self.SplitQuadsNearTriangularFacets()
2365 ## @brief Split hexahedrons into prisms.
2367 # Use pattern mapping functionality for splitting.
2368 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2369 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2370 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2371 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2372 # key-point will be mapped into <theNode001>-th node of each volume.
2373 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2374 # @param @return TRUE in case of success, FALSE otherwise.
2375 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2376 # Pattern: 5.---------.6
2381 # (0,0,1) 4.---------.7 |
2388 # (0,0,0) 0.---------.3
2389 pattern_prism = "!!! Nb of points: \n 8 \n\
2399 !!! Indices of points of 2 prisms: \n\
2403 pattern = GetPattern()
2404 isDone = pattern.LoadFromFile(pattern_prism)
2406 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2409 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2410 isDone = pattern.MakeMesh(self.mesh, False, False)
2411 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2413 # split quafrangle faces near triangular facets of volumes
2414 self.SplitQuadsNearTriangularFacets()
2419 # @param IDsOfElements list if ids of elements to smooth
2420 # @param IDsOfFixedNodes list of ids of fixed nodes.
2421 # Note that nodes built on edges and boundary nodes are always fixed.
2422 # @param MaxNbOfIterations maximum number of iterations
2423 # @param MaxAspectRatio varies in range [1.0, inf]
2424 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2425 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2426 MaxNbOfIterations, MaxAspectRatio, Method):
2427 if IDsOfElements == []:
2428 IDsOfElements = self.GetElementsId()
2429 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2430 MaxNbOfIterations, MaxAspectRatio, Method)
2432 ## Smooth elements belong to given object
2433 # @param theObject object to smooth
2434 # @param IDsOfFixedNodes list of ids of fixed nodes.
2435 # Note that nodes built on edges and boundary nodes are always fixed.
2436 # @param MaxNbOfIterations maximum number of iterations
2437 # @param MaxAspectRatio varies in range [1.0, inf]
2438 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2439 def SmoothObject(self, theObject, IDsOfFixedNodes,
2440 MaxNbOfIterations, MaxxAspectRatio, Method):
2441 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2442 MaxNbOfIterations, MaxxAspectRatio, Method)
2444 ## Parametric smooth the given elements
2445 # @param IDsOfElements list if ids of elements to smooth
2446 # @param IDsOfFixedNodes list of ids of fixed nodes.
2447 # Note that nodes built on edges and boundary nodes are always fixed.
2448 # @param MaxNbOfIterations maximum number of iterations
2449 # @param MaxAspectRatio varies in range [1.0, inf]
2450 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2451 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2452 MaxNbOfIterations, MaxAspectRatio, Method):
2453 if IDsOfElements == []:
2454 IDsOfElements = self.GetElementsId()
2455 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2456 MaxNbOfIterations, MaxAspectRatio, Method)
2458 ## Parametric smooth elements belong to given object
2459 # @param theObject object to smooth
2460 # @param IDsOfFixedNodes list of ids of fixed nodes.
2461 # Note that nodes built on edges and boundary nodes are always fixed.
2462 # @param MaxNbOfIterations maximum number of iterations
2463 # @param MaxAspectRatio varies in range [1.0, inf]
2464 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2465 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2466 MaxNbOfIterations, MaxAspectRatio, Method):
2467 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2468 MaxNbOfIterations, MaxAspectRatio, Method)
2470 ## Converts all mesh to quadratic one, deletes old elements, replacing
2471 # them with quadratic ones with the same id.
2472 def ConvertToQuadratic(self, theForce3d):
2473 self.editor.ConvertToQuadratic(theForce3d)
2475 ## Converts all mesh from quadratic to ordinary ones,
2476 # deletes old quadratic elements, \n replacing
2477 # them with ordinary mesh elements with the same id.
2478 def ConvertFromQuadratic(self):
2479 return self.editor.ConvertFromQuadratic()
2481 ## Renumber mesh nodes
2482 def RenumberNodes(self):
2483 self.editor.RenumberNodes()
2485 ## Renumber mesh elements
2486 def RenumberElements(self):
2487 self.editor.RenumberElements()
2489 ## Generate new elements by rotation of the elements around the axis
2490 # @param IDsOfElements list of ids of elements to sweep
2491 # @param Axix axis of rotation, AxisStruct or line(geom object)
2492 # @param AngleInRadians angle of Rotation
2493 # @param NbOfSteps number of steps
2494 # @param Tolerance tolerance
2495 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2496 if IDsOfElements == []:
2497 IDsOfElements = self.GetElementsId()
2498 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2499 Axix = GetAxisStruct(Axix)
2500 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2502 ## Generate new elements by rotation of the elements of object around the axis
2503 # @param theObject object wich elements should be sweeped
2504 # @param Axix axis of rotation, AxisStruct or line(geom object)
2505 # @param AngleInRadians angle of Rotation
2506 # @param NbOfSteps number of steps
2507 # @param Tolerance tolerance
2508 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2509 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2510 Axix = GetAxisStruct(Axix)
2511 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2513 ## Generate new elements by extrusion of the elements with given ids
2514 # @param IDsOfElements list of elements ids for extrusion
2515 # @param StepVector vector, defining the direction and value of extrusion
2516 # @param NbOfSteps the number of steps
2517 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2518 if IDsOfElements == []:
2519 IDsOfElements = self.GetElementsId()
2520 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2521 StepVector = GetDirStruct(StepVector)
2522 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2524 ## Generate new elements by extrusion of the elements with given ids
2525 # @param IDsOfElements is ids of elements
2526 # @param StepVector vector, defining the direction and value of extrusion
2527 # @param NbOfSteps the number of steps
2528 # @param ExtrFlags set flags for performing extrusion
2529 # @param SewTolerance uses for comparing locations of nodes if flag
2530 # EXTRUSION_FLAG_SEW is set
2531 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2532 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2533 StepVector = GetDirStruct(StepVector)
2534 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2536 ## Generate new elements by extrusion of the elements belong to object
2537 # @param theObject object wich elements should be processed
2538 # @param StepVector vector, defining the direction and value of extrusion
2539 # @param NbOfSteps the number of steps
2540 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2541 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2542 StepVector = GetDirStruct(StepVector)
2543 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2545 ## Generate new elements by extrusion of the elements belong to object
2546 # @param theObject object wich elements should be processed
2547 # @param StepVector vector, defining the direction and value of extrusion
2548 # @param NbOfSteps the number of steps
2549 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2550 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2551 StepVector = GetDirStruct(StepVector)
2552 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2554 ## Generate new elements by extrusion of the elements belong to object
2555 # @param theObject object wich elements should be processed
2556 # @param StepVector vector, defining the direction and value of extrusion
2557 # @param NbOfSteps the number of steps
2558 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2559 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2560 StepVector = GetDirStruct(StepVector)
2561 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2563 ## Generate new elements by extrusion of the given elements
2564 # A path of extrusion must be a meshed edge.
2565 # @param IDsOfElements is ids of elements
2566 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2567 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2568 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2569 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2570 # @param Angles list of angles
2571 # @param HasRefPoint allows to use base point
2572 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2573 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2574 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2575 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2576 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2577 if IDsOfElements == []:
2578 IDsOfElements = self.GetElementsId()
2579 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2580 RefPoint = GetPointStruct(RefPoint)
2582 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2583 HasAngles, Angles, HasRefPoint, RefPoint)
2585 ## Generate new elements by extrusion of the elements belong to object
2586 # A path of extrusion must be a meshed edge.
2587 # @param IDsOfElements is ids of elements
2588 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2589 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2590 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2591 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2592 # @param Angles list of angles
2593 # @param HasRefPoint allows to use base point
2594 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2595 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2596 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2597 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2598 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2599 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2600 RefPoint = GetPointStruct(RefPoint)
2601 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2602 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation)
2604 ## Symmetrical copy of mesh elements
2605 # @param IDsOfElements list of elements ids
2606 # @param Mirror is AxisStruct or geom object(point, line, plane)
2607 # @param theMirrorType is POINT, AXIS or PLANE
2608 # If the Mirror is geom object this parameter is unnecessary
2609 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2610 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2611 if IDsOfElements == []:
2612 IDsOfElements = self.GetElementsId()
2613 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2614 Mirror = GetAxisStruct(Mirror)
2615 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2617 ## Symmetrical copy of object
2618 # @param theObject mesh, submesh or group
2619 # @param Mirror is AxisStruct or geom object(point, line, plane)
2620 # @param theMirrorType is POINT, AXIS or PLANE
2621 # If the Mirror is geom object this parameter is unnecessary
2622 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2623 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2624 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2625 Mirror = GetAxisStruct(Mirror)
2626 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2628 ## Translates the elements
2629 # @param IDsOfElements list of elements ids
2630 # @param Vector direction of translation(DirStruct or vector)
2631 # @param Copy allows to copy the translated elements
2632 def Translate(self, IDsOfElements, Vector, Copy):
2633 if IDsOfElements == []:
2634 IDsOfElements = self.GetElementsId()
2635 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2636 Vector = GetDirStruct(Vector)
2637 self.editor.Translate(IDsOfElements, Vector, Copy)
2639 ## Translates the object
2640 # @param theObject object to translate(mesh, submesh, or group)
2641 # @param Vector direction of translation(DirStruct or geom vector)
2642 # @param Copy allows to copy the translated elements
2643 def TranslateObject(self, theObject, Vector, Copy):
2644 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2645 Vector = GetDirStruct(Vector)
2646 self.editor.TranslateObject(theObject, Vector, Copy)
2648 ## Rotates the elements
2649 # @param IDsOfElements list of elements ids
2650 # @param Axis axis of rotation(AxisStruct or geom line)
2651 # @param AngleInRadians angle of rotation(in radians)
2652 # @param Copy allows to copy the rotated elements
2653 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2654 if IDsOfElements == []:
2655 IDsOfElements = self.GetElementsId()
2656 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2657 Axis = GetAxisStruct(Axis)
2658 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2660 ## Rotates the object
2661 # @param theObject object to rotate(mesh, submesh, or group)
2662 # @param Axis axis of rotation(AxisStruct or geom line)
2663 # @param AngleInRadians angle of rotation(in radians)
2664 # @param Copy allows to copy the rotated elements
2665 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2666 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2668 ## Find group of nodes close to each other within Tolerance.
2669 # @param Tolerance tolerance value
2670 # @param list of group of nodes
2671 def FindCoincidentNodes (self, Tolerance):
2672 return self.editor.FindCoincidentNodes(Tolerance)
2674 ## Find group of nodes close to each other within Tolerance.
2675 # @param Tolerance tolerance value
2676 # @param SubMeshOrGroup SubMesh or Group
2677 # @param list of group of nodes
2678 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2679 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2682 # @param list of group of nodes
2683 def MergeNodes (self, GroupsOfNodes):
2684 self.editor.MergeNodes(GroupsOfNodes)
2686 ## Find elements built on the same nodes.
2687 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2688 # @return a list of groups of equal elements
2689 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2690 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2692 ## Merge elements in each given group.
2693 # @param GroupsOfElementsID groups of elements for merging
2694 def MergeElements(self, GroupsOfElementsID):
2695 self.editor.MergeElements(GroupsOfElementsID)
2697 ## Remove all but one of elements built on the same nodes.
2698 def MergeEqualElements(self):
2699 self.editor.MergeEqualElements()
2702 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2703 FirstNodeID2, SecondNodeID2, LastNodeID2,
2704 CreatePolygons, CreatePolyedrs):
2705 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2706 FirstNodeID2, SecondNodeID2, LastNodeID2,
2707 CreatePolygons, CreatePolyedrs)
2709 ## Sew conform free borders
2710 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2711 FirstNodeID2, SecondNodeID2):
2712 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2713 FirstNodeID2, SecondNodeID2)
2715 ## Sew border to side
2716 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2717 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2718 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2719 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2721 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2722 # merged with nodes of elements of Side2.
2723 # Number of elements in theSide1 and in theSide2 must be
2724 # equal and they should have similar node connectivity.
2725 # The nodes to merge should belong to sides borders and
2726 # the first node should be linked to the second.
2727 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2728 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2729 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2730 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2731 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2732 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2734 ## Set new nodes for given element.
2735 # @param ide the element id
2736 # @param newIDs nodes ids
2737 # @return If number of nodes is not corresponded to type of element - returns false
2738 def ChangeElemNodes(self, ide, newIDs):
2739 return self.editor.ChangeElemNodes(ide, newIDs)
2741 ## If during last operation of MeshEditor some nodes were
2742 # created this method returns list of its IDs, \n
2743 # if new nodes not created - returns empty list
2744 def GetLastCreatedNodes(self):
2745 return self.editor.GetLastCreatedNodes()
2747 ## If during last operation of MeshEditor some elements were
2748 # created this method returns list of its IDs, \n
2749 # if new elements not creared - returns empty list
2750 def GetLastCreatedElems(self):
2751 return self.editor.GetLastCreatedElems()