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(self.geom), 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, GetName(hypo), GetName(self.geom), 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 caught:"
1505 print " ", ex.details.text
1508 print "Mesh computation failed, exception caught:"
1509 traceback.print_exc()
1511 errors = smesh.GetAlgoState( self.mesh, geom )
1514 if err.isGlobalAlgo:
1522 reason = '%s %sD algorithm is missing' % (glob, dim)
1523 elif err.state == HYP_MISSING:
1524 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1525 % (glob, dim, name, dim))
1526 elif err.state == HYP_NOTCONFORM:
1527 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1528 elif err.state == HYP_BAD_PARAMETER:
1529 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1530 % ( glob, dim, name ))
1531 elif err.state == HYP_BAD_GEOMETRY:
1532 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1533 'its expectation' % ( glob, dim, name ))
1535 reason = "For unknown reason."+\
1536 " Revise Mesh.Compute() implementation in smesh.py!"
1538 if allReasons != "":
1541 allReasons += reason
1543 if allReasons != "":
1544 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1547 print '"' + GetName(self.mesh) + '"',"has not been computed."
1550 if salome.sg.hasDesktop():
1551 smeshgui = salome.ImportComponentGUI("SMESH")
1552 smeshgui.Init(salome.myStudyId)
1553 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1554 salome.sg.updateObjBrowser(1)
1558 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1559 # The parameter \a fineness [0,-1] defines mesh fineness
1560 def AutomaticTetrahedralization(self, fineness=0):
1561 dim = self.MeshDimension()
1563 self.RemoveGlobalHypotheses()
1564 self.Segment().AutomaticLength(fineness)
1566 self.Triangle().LengthFromEdges()
1569 self.Tetrahedron(NETGEN)
1571 return self.Compute()
1573 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1574 # The parameter \a fineness [0,-1] defines mesh fineness
1575 def AutomaticHexahedralization(self, fineness=0):
1576 dim = self.MeshDimension()
1578 self.RemoveGlobalHypotheses()
1579 self.Segment().AutomaticLength(fineness)
1586 return self.Compute()
1588 ## Assign hypothesis
1589 # @param hyp is a hypothesis to assign
1590 # @param geom is subhape of mesh geometry
1591 def AddHypothesis(self, hyp, geom=0 ):
1592 if isinstance( hyp, Mesh_Algorithm ):
1593 hyp = hyp.GetAlgorithm()
1598 status = self.mesh.AddHypothesis(geom, hyp)
1599 isAlgo = hyp._narrow( SMESH_Algo )
1600 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1603 ## Unassign hypothesis
1604 # @param hyp is a hypothesis to unassign
1605 # @param geom is subhape of mesh geometry
1606 def RemoveHypothesis(self, hyp, geom=0 ):
1607 if isinstance( hyp, Mesh_Algorithm ):
1608 hyp = hyp.GetAlgorithm()
1613 status = self.mesh.RemoveHypothesis(geom, hyp)
1616 ## Get the list of hypothesis added on a geom
1617 # @param geom is subhape of mesh geometry
1618 def GetHypothesisList(self, geom):
1619 return self.mesh.GetHypothesisList( geom )
1621 ## Removes all global hypotheses
1622 def RemoveGlobalHypotheses(self):
1623 current_hyps = self.mesh.GetHypothesisList( self.geom )
1624 for hyp in current_hyps:
1625 self.mesh.RemoveHypothesis( self.geom, hyp )
1629 ## Create a mesh group based on geometric object \a grp
1630 # and give a \a name, \n if this parameter is not defined
1631 # the name is the same as the geometric group name \n
1632 # Note: Works like GroupOnGeom().
1633 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1634 # @param name is the name of the mesh group
1635 # @return SMESH_GroupOnGeom
1636 def Group(self, grp, name=""):
1637 return self.GroupOnGeom(grp, name)
1639 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1640 # Export the mesh in a file with the MED format and choice the \a version of MED format
1641 # @param f is the file name
1642 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1643 def ExportToMED(self, f, version, opt=0):
1644 self.mesh.ExportToMED(f, opt, version)
1646 ## Export the mesh in a file with the MED format
1647 # @param f is the file name
1648 # @param auto_groups boolean parameter for creating/not creating
1649 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1650 # the typical use is auto_groups=false.
1651 # @param version MED format version(MED_V2_1 or MED_V2_2)
1652 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1653 self.mesh.ExportToMED(f, auto_groups, version)
1655 ## Export the mesh in a file with the DAT format
1656 # @param f is the file name
1657 def ExportDAT(self, f):
1658 self.mesh.ExportDAT(f)
1660 ## Export the mesh in a file with the UNV format
1661 # @param f is the file name
1662 def ExportUNV(self, f):
1663 self.mesh.ExportUNV(f)
1665 ## Export the mesh in a file with the STL format
1666 # @param f is the file name
1667 # @param ascii defined the kind of file contents
1668 def ExportSTL(self, f, ascii=1):
1669 self.mesh.ExportSTL(f, ascii)
1672 # Operations with groups:
1673 # ----------------------
1675 ## Creates an empty mesh group
1676 # @param elementType is the type of elements in the group
1677 # @param name is the name of the mesh group
1678 # @return SMESH_Group
1679 def CreateEmptyGroup(self, elementType, name):
1680 return self.mesh.CreateGroup(elementType, name)
1682 ## Creates a mesh group based on geometric object \a grp
1683 # and give a \a name, \n if this parameter is not defined
1684 # the name is the same as the geometric group name
1685 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1686 # @param name is the name of the mesh group
1687 # @return SMESH_GroupOnGeom
1688 def GroupOnGeom(self, grp, name="", type=None):
1690 name = grp.GetName()
1693 tgeo = str(grp.GetShapeType())
1694 if tgeo == "VERTEX":
1696 elif tgeo == "EDGE":
1698 elif tgeo == "FACE":
1700 elif tgeo == "SOLID":
1702 elif tgeo == "SHELL":
1704 elif tgeo == "COMPOUND":
1705 if len( geompy.GetObjectIDs( grp )) == 0:
1706 print "Mesh.Group: empty geometric group", GetName( grp )
1708 tgeo = geompy.GetType(grp)
1709 if tgeo == geompy.ShapeType["VERTEX"]:
1711 elif tgeo == geompy.ShapeType["EDGE"]:
1713 elif tgeo == geompy.ShapeType["FACE"]:
1715 elif tgeo == geompy.ShapeType["SOLID"]:
1719 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1722 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1724 ## Create a mesh group by the given ids of elements
1725 # @param groupName is the name of the mesh group
1726 # @param elementType is the type of elements in the group
1727 # @param elemIDs is the list of ids
1728 # @return SMESH_Group
1729 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1730 group = self.mesh.CreateGroup(elementType, groupName)
1734 ## Create a mesh group by the given conditions
1735 # @param groupName is the name of the mesh group
1736 # @param elementType is the type of elements in the group
1737 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1738 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1739 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1740 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1741 # @return SMESH_Group
1745 CritType=FT_Undefined,
1748 UnaryOp=FT_Undefined):
1749 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1750 group = self.MakeGroupByCriterion(groupName, aCriterion)
1753 ## Create a mesh group by the given criterion
1754 # @param groupName is the name of the mesh group
1755 # @param Criterion is the instance of Criterion class
1756 # @return SMESH_Group
1757 def MakeGroupByCriterion(self, groupName, Criterion):
1758 aFilterMgr = smesh.CreateFilterManager()
1759 aFilter = aFilterMgr.CreateFilter()
1761 aCriteria.append(Criterion)
1762 aFilter.SetCriteria(aCriteria)
1763 group = self.MakeGroupByFilter(groupName, aFilter)
1766 ## Create a mesh group by the given criteria(list of criterions)
1767 # @param groupName is the name of the mesh group
1768 # @param Criteria is the list of criterions
1769 # @return SMESH_Group
1770 def MakeGroupByCriteria(self, groupName, theCriteria):
1771 aFilterMgr = smesh.CreateFilterManager()
1772 aFilter = aFilterMgr.CreateFilter()
1773 aFilter.SetCriteria(theCriteria)
1774 group = self.MakeGroupByFilter(groupName, aFilter)
1777 ## Create a mesh group by the given filter
1778 # @param groupName is the name of the mesh group
1779 # @param Criterion is the instance of Filter class
1780 # @return SMESH_Group
1781 def MakeGroupByFilter(self, groupName, theFilter):
1782 anIds = theFilter.GetElementsId(self.mesh)
1783 anElemType = theFilter.GetElementType()
1784 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1787 ## Pass mesh elements through the given filter and return ids
1788 # @param theFilter is SMESH_Filter
1789 # @return list of ids
1790 def GetIdsFromFilter(self, theFilter):
1791 return theFilter.GetElementsId(self.mesh)
1793 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1794 # Returns list of special structures(borders).
1795 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1796 def GetFreeBorders(self):
1797 aFilterMgr = smesh.CreateFilterManager()
1798 aPredicate = aFilterMgr.CreateFreeEdges()
1799 aPredicate.SetMesh(self.mesh)
1800 aBorders = aPredicate.GetBorders()
1804 def RemoveGroup(self, group):
1805 self.mesh.RemoveGroup(group)
1807 ## Remove group with its contents
1808 def RemoveGroupWithContents(self, group):
1809 self.mesh.RemoveGroupWithContents(group)
1811 ## Get the list of groups existing in the mesh
1812 def GetGroups(self):
1813 return self.mesh.GetGroups()
1815 ## Get the list of names of groups existing in the mesh
1816 def GetGroupNames(self):
1817 groups = self.GetGroups()
1819 for group in groups:
1820 names.append(group.GetName())
1823 ## Union of two groups
1824 # New group is created. All mesh elements that are
1825 # present in initial groups are added to the new one
1826 def UnionGroups(self, group1, group2, name):
1827 return self.mesh.UnionGroups(group1, group2, name)
1829 ## Intersection of two groups
1830 # New group is created. All mesh elements that are
1831 # present in both initial groups are added to the new one.
1832 def IntersectGroups(self, group1, group2, name):
1833 return self.mesh.IntersectGroups(group1, group2, name)
1835 ## Cut of two groups
1836 # New group is created. All mesh elements that are present in
1837 # main group but do not present in tool group are added to the new one
1838 def CutGroups(self, mainGroup, toolGroup, name):
1839 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1842 # Get some info about mesh:
1843 # ------------------------
1845 ## Get the log of nodes and elements added or removed since previous
1847 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1848 # @return list of log_block structures:
1853 def GetLog(self, clearAfterGet):
1854 return self.mesh.GetLog(clearAfterGet)
1856 ## Clear the log of nodes and elements added or removed since previous
1857 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1859 self.mesh.ClearLog()
1861 ## Get the internal Id
1863 return self.mesh.GetId()
1866 def GetStudyId(self):
1867 return self.mesh.GetStudyId()
1869 ## Check group names for duplications.
1870 # Consider maximum group name length stored in MED file.
1871 def HasDuplicatedGroupNamesMED(self):
1872 return self.mesh.HasDuplicatedGroupNamesMED()
1874 ## Obtain instance of SMESH_MeshEditor
1875 def GetMeshEditor(self):
1876 return self.mesh.GetMeshEditor()
1879 def GetMEDMesh(self):
1880 return self.mesh.GetMEDMesh()
1883 # Get informations about mesh contents:
1884 # ------------------------------------
1886 ## Returns number of nodes in mesh
1888 return self.mesh.NbNodes()
1890 ## Returns number of elements in mesh
1891 def NbElements(self):
1892 return self.mesh.NbElements()
1894 ## Returns number of edges in mesh
1896 return self.mesh.NbEdges()
1898 ## Returns number of edges with given order in mesh
1899 # @param elementOrder is order of elements:
1900 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1901 def NbEdgesOfOrder(self, elementOrder):
1902 return self.mesh.NbEdgesOfOrder(elementOrder)
1904 ## Returns number of faces in mesh
1906 return self.mesh.NbFaces()
1908 ## Returns number of faces with given order in mesh
1909 # @param elementOrder is order of elements:
1910 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1911 def NbFacesOfOrder(self, elementOrder):
1912 return self.mesh.NbFacesOfOrder(elementOrder)
1914 ## Returns number of triangles in mesh
1915 def NbTriangles(self):
1916 return self.mesh.NbTriangles()
1918 ## Returns number of triangles with given order in mesh
1919 # @param elementOrder is order of elements:
1920 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1921 def NbTrianglesOfOrder(self, elementOrder):
1922 return self.mesh.NbTrianglesOfOrder(elementOrder)
1924 ## Returns number of quadrangles in mesh
1925 def NbQuadrangles(self):
1926 return self.mesh.NbQuadrangles()
1928 ## Returns number of quadrangles with given order in mesh
1929 # @param elementOrder is order of elements:
1930 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1931 def NbQuadranglesOfOrder(self, elementOrder):
1932 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1934 ## Returns number of polygons in mesh
1935 def NbPolygons(self):
1936 return self.mesh.NbPolygons()
1938 ## Returns number of volumes in mesh
1939 def NbVolumes(self):
1940 return self.mesh.NbVolumes()
1942 ## Returns number of volumes with given order in mesh
1943 # @param elementOrder is order of elements:
1944 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1945 def NbVolumesOfOrder(self, elementOrder):
1946 return self.mesh.NbVolumesOfOrder(elementOrder)
1948 ## Returns number of tetrahedrons in mesh
1950 return self.mesh.NbTetras()
1952 ## Returns number of tetrahedrons with given order in mesh
1953 # @param elementOrder is order of elements:
1954 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1955 def NbTetrasOfOrder(self, elementOrder):
1956 return self.mesh.NbTetrasOfOrder(elementOrder)
1958 ## Returns number of hexahedrons in mesh
1960 return self.mesh.NbHexas()
1962 ## Returns number of hexahedrons with given order in mesh
1963 # @param elementOrder is order of elements:
1964 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1965 def NbHexasOfOrder(self, elementOrder):
1966 return self.mesh.NbHexasOfOrder(elementOrder)
1968 ## Returns number of pyramids in mesh
1969 def NbPyramids(self):
1970 return self.mesh.NbPyramids()
1972 ## Returns number of pyramids with given order in mesh
1973 # @param elementOrder is order of elements:
1974 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1975 def NbPyramidsOfOrder(self, elementOrder):
1976 return self.mesh.NbPyramidsOfOrder(elementOrder)
1978 ## Returns number of prisms in mesh
1980 return self.mesh.NbPrisms()
1982 ## Returns number of prisms with given order in mesh
1983 # @param elementOrder is order of elements:
1984 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1985 def NbPrismsOfOrder(self, elementOrder):
1986 return self.mesh.NbPrismsOfOrder(elementOrder)
1988 ## Returns number of polyhedrons in mesh
1989 def NbPolyhedrons(self):
1990 return self.mesh.NbPolyhedrons()
1992 ## Returns number of submeshes in mesh
1993 def NbSubMesh(self):
1994 return self.mesh.NbSubMesh()
1996 ## Returns list of mesh elements ids
1997 def GetElementsId(self):
1998 return self.mesh.GetElementsId()
2000 ## Returns list of ids of mesh elements with given type
2001 # @param elementType is required type of elements
2002 def GetElementsByType(self, elementType):
2003 return self.mesh.GetElementsByType(elementType)
2005 ## Returns list of mesh nodes ids
2006 def GetNodesId(self):
2007 return self.mesh.GetNodesId()
2009 # Get informations about mesh elements:
2010 # ------------------------------------
2012 ## Returns type of mesh element
2013 def GetElementType(self, id, iselem):
2014 return self.mesh.GetElementType(id, iselem)
2016 ## Returns list of submesh elements ids
2017 # @param shapeID is geom object(subshape) IOR
2018 def GetSubMeshElementsId(self, shapeID):
2019 return self.mesh.GetSubMeshElementsId(shapeID)
2021 ## Returns list of submesh nodes ids
2022 # @param shapeID is geom object(subshape) IOR
2023 def GetSubMeshNodesId(self, shapeID, all):
2024 return self.mesh.GetSubMeshNodesId(shapeID, all)
2026 ## Returns list of ids of submesh elements with given type
2027 # @param shapeID is geom object(subshape) IOR
2028 def GetSubMeshElementType(self, shapeID):
2029 return self.mesh.GetSubMeshElementType(shapeID)
2031 ## Get mesh description
2033 return self.mesh.Dump()
2036 # Get information about nodes and elements of mesh by its ids:
2037 # -----------------------------------------------------------
2039 ## Get XYZ coordinates of node as list of double
2040 # \n If there is not node for given ID - returns empty list
2041 def GetNodeXYZ(self, id):
2042 return self.mesh.GetNodeXYZ(id)
2044 ## For given node returns list of IDs of inverse elements
2045 # \n If there is not node for given ID - returns empty list
2046 def GetNodeInverseElements(self, id):
2047 return self.mesh.GetNodeInverseElements(id)
2049 ## If given element is node returns IDs of shape from position
2050 # \n If there is not node for given ID - returns -1
2051 def GetShapeID(self, id):
2052 return self.mesh.GetShapeID(id)
2054 ## For given element returns ID of result shape after
2055 # FindShape() from SMESH_MeshEditor
2056 # \n If there is not element for given ID - returns -1
2057 def GetShapeIDForElem(self,id):
2058 return self.mesh.GetShapeIDForElem(id)
2060 ## Returns number of nodes for given element
2061 # \n If there is not element for given ID - returns -1
2062 def GetElemNbNodes(self, id):
2063 return self.mesh.GetElemNbNodes(id)
2065 ## Returns ID of node by given index for given element
2066 # \n If there is not element for given ID - returns -1
2067 # \n If there is not node for given index - returns -2
2068 def GetElemNode(self, id, index):
2069 return self.mesh.GetElemNode(id, index)
2071 ## Returns IDs of nodes of given element
2072 def GetElemNodes(self, id):
2073 return self.mesh.GetElemNodes(id)
2075 ## Returns true if given node is medium node
2076 # in given quadratic element
2077 def IsMediumNode(self, elementID, nodeID):
2078 return self.mesh.IsMediumNode(elementID, nodeID)
2080 ## Returns true if given node is medium node
2081 # in one of quadratic elements
2082 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2083 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2085 ## Returns number of edges for given element
2086 def ElemNbEdges(self, id):
2087 return self.mesh.ElemNbEdges(id)
2089 ## Returns number of faces for given element
2090 def ElemNbFaces(self, id):
2091 return self.mesh.ElemNbFaces(id)
2093 ## Returns true if given element is polygon
2094 def IsPoly(self, id):
2095 return self.mesh.IsPoly(id)
2097 ## Returns true if given element is quadratic
2098 def IsQuadratic(self, id):
2099 return self.mesh.IsQuadratic(id)
2101 ## Returns XYZ coordinates of bary center for given element
2103 # \n If there is not element for given ID - returns empty list
2104 def BaryCenter(self, id):
2105 return self.mesh.BaryCenter(id)
2108 # Mesh edition (SMESH_MeshEditor functionality):
2109 # ---------------------------------------------
2111 ## Removes elements from mesh by ids
2112 # @param IDsOfElements is list of ids of elements to remove
2113 def RemoveElements(self, IDsOfElements):
2114 return self.editor.RemoveElements(IDsOfElements)
2116 ## Removes nodes from mesh by ids
2117 # @param IDsOfNodes is list of ids of nodes to remove
2118 def RemoveNodes(self, IDsOfNodes):
2119 return self.editor.RemoveNodes(IDsOfNodes)
2121 ## Add node to mesh by coordinates
2122 def AddNode(self, x, y, z):
2123 return self.editor.AddNode( x, y, z)
2126 ## Create edge both similar and quadratic (this is determed
2127 # by number of given nodes).
2128 # @param IdsOfNodes List of node IDs for creation of element.
2129 # Needed order of nodes in this list corresponds to description
2130 # of MED. \n This description is located by the following link:
2131 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2132 def AddEdge(self, IDsOfNodes):
2133 return self.editor.AddEdge(IDsOfNodes)
2135 ## Create face both similar and quadratic (this is determed
2136 # by number of given nodes).
2137 # @param IdsOfNodes List of node IDs for creation of element.
2138 # Needed order of nodes in this list corresponds to description
2139 # of MED. \n This description is located by the following link:
2140 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2141 def AddFace(self, IDsOfNodes):
2142 return self.editor.AddFace(IDsOfNodes)
2144 ## Add polygonal face to mesh by list of nodes ids
2145 def AddPolygonalFace(self, IdsOfNodes):
2146 return self.editor.AddPolygonalFace(IdsOfNodes)
2148 ## Create volume both similar and quadratic (this is determed
2149 # by number of given nodes).
2150 # @param IdsOfNodes List of node IDs for creation of element.
2151 # Needed order of nodes in this list corresponds to description
2152 # of MED. \n This description is located by the following link:
2153 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2154 def AddVolume(self, IDsOfNodes):
2155 return self.editor.AddVolume(IDsOfNodes)
2157 ## Create volume of many faces, giving nodes for each face.
2158 # @param IdsOfNodes List of node IDs for volume creation face by face.
2159 # @param Quantities List of integer values, Quantities[i]
2160 # gives quantity of nodes in face number i.
2161 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2162 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2164 ## Create volume of many faces, giving IDs of existing faces.
2165 # @param IdsOfFaces List of face IDs for volume creation.
2167 # Note: The created volume will refer only to nodes
2168 # of the given faces, not to the faces itself.
2169 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2170 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2172 ## Move node with given id
2173 # @param NodeID id of the node
2174 # @param x new X coordinate
2175 # @param y new Y coordinate
2176 # @param z new Z coordinate
2177 def MoveNode(self, NodeID, x, y, z):
2178 return self.editor.MoveNode(NodeID, x, y, z)
2180 ## Find a node closest to a point
2181 # @param x X coordinate of a point
2182 # @param y Y coordinate of a point
2183 # @param z Z coordinate of a point
2184 # @return id of a node
2185 def FindNodeClosestTo(self, x, y, z):
2186 preview = self.mesh.GetMeshEditPreviewer()
2187 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2189 ## Find a node closest to a point and move it to a point location
2190 # @param x X coordinate of a point
2191 # @param y Y coordinate of a point
2192 # @param z Z coordinate of a point
2193 # @return id of a moved node
2194 def MeshToPassThroughAPoint(self, x, y, z):
2195 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2197 ## Replace two neighbour triangles sharing Node1-Node2 link
2198 # with ones built on the same 4 nodes but having other common link.
2199 # @param NodeID1 first node id
2200 # @param NodeID2 second node id
2201 # @return false if proper faces not found
2202 def InverseDiag(self, NodeID1, NodeID2):
2203 return self.editor.InverseDiag(NodeID1, NodeID2)
2205 ## Replace two neighbour triangles sharing Node1-Node2 link
2206 # with a quadrangle built on the same 4 nodes.
2207 # @param NodeID1 first node id
2208 # @param NodeID2 second node id
2209 # @return false if proper faces not found
2210 def DeleteDiag(self, NodeID1, NodeID2):
2211 return self.editor.DeleteDiag(NodeID1, NodeID2)
2213 ## Reorient elements by ids
2214 # @param IDsOfElements if undefined reorient all mesh elements
2215 def Reorient(self, IDsOfElements=None):
2216 if IDsOfElements == None:
2217 IDsOfElements = self.GetElementsId()
2218 return self.editor.Reorient(IDsOfElements)
2220 ## Reorient all elements of the object
2221 # @param theObject is mesh, submesh or group
2222 def ReorientObject(self, theObject):
2223 return self.editor.ReorientObject(theObject)
2225 ## Fuse neighbour triangles into quadrangles.
2226 # @param IDsOfElements The triangles to be fused,
2227 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2228 # @param MaxAngle is a max angle between element normals at which fusion
2229 # is still performed; theMaxAngle is mesured in radians.
2230 # @return TRUE in case of success, FALSE otherwise.
2231 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2232 if IDsOfElements == []:
2233 IDsOfElements = self.GetElementsId()
2234 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
2236 ## Fuse neighbour triangles of the object into quadrangles
2237 # @param theObject is mesh, submesh or group
2238 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2239 # @param MaxAngle is a max angle between element normals at which fusion
2240 # is still performed; theMaxAngle is mesured in radians.
2241 # @return TRUE in case of success, FALSE otherwise.
2242 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2243 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
2245 ## Split quadrangles into triangles.
2246 # @param IDsOfElements the faces to be splitted.
2247 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2248 # @param @return TRUE in case of success, FALSE otherwise.
2249 def QuadToTri (self, IDsOfElements, theCriterion):
2250 if IDsOfElements == []:
2251 IDsOfElements = self.GetElementsId()
2252 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
2254 ## Split quadrangles into triangles.
2255 # @param theObject object to taking list of elements from, is mesh, submesh or group
2256 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2257 def QuadToTriObject (self, theObject, theCriterion):
2258 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
2260 ## Split quadrangles into triangles.
2261 # @param theElems The faces to be splitted
2262 # @param the13Diag is used to choose a diagonal for splitting.
2263 # @return TRUE in case of success, FALSE otherwise.
2264 def SplitQuad (self, IDsOfElements, Diag13):
2265 if IDsOfElements == []:
2266 IDsOfElements = self.GetElementsId()
2267 return self.editor.SplitQuad(IDsOfElements, Diag13)
2269 ## Split quadrangles into triangles.
2270 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2271 def SplitQuadObject (self, theObject, Diag13):
2272 return self.editor.SplitQuadObject(theObject, Diag13)
2274 ## Find better splitting of the given quadrangle.
2275 # @param IDOfQuad ID of the quadrangle to be splitted.
2276 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2277 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2278 # diagonal is better, 0 if error occurs.
2279 def BestSplit (self, IDOfQuad, theCriterion):
2280 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2282 ## Split quafrangle faces near triangular facets of volumes
2284 def SplitQuadsNearTriangularFacets(self):
2285 faces_array = self.GetElementsByType(SMESH.FACE)
2286 for face_id in faces_array:
2287 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2288 quad_nodes = self.mesh.GetElemNodes(face_id)
2289 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2290 isVolumeFound = False
2291 for node1_elem in node1_elems:
2292 if not isVolumeFound:
2293 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2294 nb_nodes = self.GetElemNbNodes(node1_elem)
2295 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2296 volume_elem = node1_elem
2297 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2298 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2299 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2300 isVolumeFound = True
2301 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2302 self.SplitQuad([face_id], False) # diagonal 2-4
2303 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2304 isVolumeFound = True
2305 self.SplitQuad([face_id], True) # diagonal 1-3
2306 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2307 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2308 isVolumeFound = True
2309 self.SplitQuad([face_id], True) # diagonal 1-3
2311 ## @brief Split hexahedrons into tetrahedrons.
2313 # Use pattern mapping functionality for splitting.
2314 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2315 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2316 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2317 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2318 # key-point will be mapped into <theNode001>-th node of each volume.
2319 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2320 # @return TRUE in case of success, FALSE otherwise.
2321 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2322 # Pattern: 5.---------.6
2327 # (0,0,1) 4.---------.7 * |
2334 # (0,0,0) 0.---------.3
2335 pattern_tetra = "!!! Nb of points: \n 8 \n\
2345 !!! Indices of points of 6 tetras: \n\
2353 pattern = GetPattern()
2354 isDone = pattern.LoadFromFile(pattern_tetra)
2356 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2359 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2360 isDone = pattern.MakeMesh(self.mesh, False, False)
2361 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2363 # split quafrangle faces near triangular facets of volumes
2364 self.SplitQuadsNearTriangularFacets()
2368 ## @brief Split hexahedrons into prisms.
2370 # Use pattern mapping functionality for splitting.
2371 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2372 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2373 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2374 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2375 # key-point will be mapped into <theNode001>-th node of each volume.
2376 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2377 # @param @return TRUE in case of success, FALSE otherwise.
2378 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2379 # Pattern: 5.---------.6
2384 # (0,0,1) 4.---------.7 |
2391 # (0,0,0) 0.---------.3
2392 pattern_prism = "!!! Nb of points: \n 8 \n\
2402 !!! Indices of points of 2 prisms: \n\
2406 pattern = GetPattern()
2407 isDone = pattern.LoadFromFile(pattern_prism)
2409 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2412 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2413 isDone = pattern.MakeMesh(self.mesh, False, False)
2414 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2416 # split quafrangle faces near triangular facets of volumes
2417 self.SplitQuadsNearTriangularFacets()
2422 # @param IDsOfElements list if ids of elements to smooth
2423 # @param IDsOfFixedNodes list of ids of fixed nodes.
2424 # Note that nodes built on edges and boundary nodes are always fixed.
2425 # @param MaxNbOfIterations maximum number of iterations
2426 # @param MaxAspectRatio varies in range [1.0, inf]
2427 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2428 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2429 MaxNbOfIterations, MaxAspectRatio, Method):
2430 if IDsOfElements == []:
2431 IDsOfElements = self.GetElementsId()
2432 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2433 MaxNbOfIterations, MaxAspectRatio, Method)
2435 ## Smooth elements belong to given object
2436 # @param theObject object to smooth
2437 # @param IDsOfFixedNodes list of ids of fixed nodes.
2438 # Note that nodes built on edges and boundary nodes are always fixed.
2439 # @param MaxNbOfIterations maximum number of iterations
2440 # @param MaxAspectRatio varies in range [1.0, inf]
2441 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2442 def SmoothObject(self, theObject, IDsOfFixedNodes,
2443 MaxNbOfIterations, MaxxAspectRatio, Method):
2444 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2445 MaxNbOfIterations, MaxxAspectRatio, Method)
2447 ## Parametric smooth the given elements
2448 # @param IDsOfElements list if ids of elements to smooth
2449 # @param IDsOfFixedNodes list of ids of fixed nodes.
2450 # Note that nodes built on edges and boundary nodes are always fixed.
2451 # @param MaxNbOfIterations maximum number of iterations
2452 # @param MaxAspectRatio varies in range [1.0, inf]
2453 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2454 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2455 MaxNbOfIterations, MaxAspectRatio, Method):
2456 if IDsOfElements == []:
2457 IDsOfElements = self.GetElementsId()
2458 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2459 MaxNbOfIterations, MaxAspectRatio, Method)
2461 ## Parametric smooth elements belong to given object
2462 # @param theObject object to smooth
2463 # @param IDsOfFixedNodes list of ids of fixed nodes.
2464 # Note that nodes built on edges and boundary nodes are always fixed.
2465 # @param MaxNbOfIterations maximum number of iterations
2466 # @param MaxAspectRatio varies in range [1.0, inf]
2467 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2468 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2469 MaxNbOfIterations, MaxAspectRatio, Method):
2470 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2471 MaxNbOfIterations, MaxAspectRatio, Method)
2473 ## Converts all mesh to quadratic one, deletes old elements, replacing
2474 # them with quadratic ones with the same id.
2475 def ConvertToQuadratic(self, theForce3d):
2476 self.editor.ConvertToQuadratic(theForce3d)
2478 ## Converts all mesh from quadratic to ordinary ones,
2479 # deletes old quadratic elements, \n replacing
2480 # them with ordinary mesh elements with the same id.
2481 def ConvertFromQuadratic(self):
2482 return self.editor.ConvertFromQuadratic()
2484 ## Renumber mesh nodes
2485 def RenumberNodes(self):
2486 self.editor.RenumberNodes()
2488 ## Renumber mesh elements
2489 def RenumberElements(self):
2490 self.editor.RenumberElements()
2492 ## Generate new elements by rotation of the elements around the axis
2493 # @param IDsOfElements list of ids of elements to sweep
2494 # @param Axix axis of rotation, AxisStruct or line(geom object)
2495 # @param AngleInRadians angle of Rotation
2496 # @param NbOfSteps number of steps
2497 # @param Tolerance tolerance
2498 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2499 if IDsOfElements == []:
2500 IDsOfElements = self.GetElementsId()
2501 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2502 Axix = GetAxisStruct(Axix)
2503 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2505 ## Generate new elements by rotation of the elements of object around the axis
2506 # @param theObject object wich elements should be sweeped
2507 # @param Axix axis of rotation, AxisStruct or line(geom object)
2508 # @param AngleInRadians angle of Rotation
2509 # @param NbOfSteps number of steps
2510 # @param Tolerance tolerance
2511 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2512 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2513 Axix = GetAxisStruct(Axix)
2514 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2516 ## Generate new elements by extrusion of the elements with given ids
2517 # @param IDsOfElements list of elements ids for extrusion
2518 # @param StepVector vector, defining the direction and value of extrusion
2519 # @param NbOfSteps the number of steps
2520 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2521 if IDsOfElements == []:
2522 IDsOfElements = self.GetElementsId()
2523 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2524 StepVector = GetDirStruct(StepVector)
2525 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2527 ## Generate new elements by extrusion of the elements with given ids
2528 # @param IDsOfElements is ids of elements
2529 # @param StepVector vector, defining the direction and value of extrusion
2530 # @param NbOfSteps the number of steps
2531 # @param ExtrFlags set flags for performing extrusion
2532 # @param SewTolerance uses for comparing locations of nodes if flag
2533 # EXTRUSION_FLAG_SEW is set
2534 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2535 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2536 StepVector = GetDirStruct(StepVector)
2537 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2539 ## Generate new elements by extrusion of the elements belong to object
2540 # @param theObject object wich elements should be processed
2541 # @param StepVector vector, defining the direction and value of extrusion
2542 # @param NbOfSteps the number of steps
2543 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2544 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2545 StepVector = GetDirStruct(StepVector)
2546 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2548 ## Generate new elements by extrusion of the elements belong to object
2549 # @param theObject object wich elements should be processed
2550 # @param StepVector vector, defining the direction and value of extrusion
2551 # @param NbOfSteps the number of steps
2552 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2553 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2554 StepVector = GetDirStruct(StepVector)
2555 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2557 ## Generate new elements by extrusion of the elements belong to object
2558 # @param theObject object wich elements should be processed
2559 # @param StepVector vector, defining the direction and value of extrusion
2560 # @param NbOfSteps the number of steps
2561 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2562 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2563 StepVector = GetDirStruct(StepVector)
2564 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2566 ## Generate new elements by extrusion of the given elements
2567 # A path of extrusion must be a meshed edge.
2568 # @param IDsOfElements is ids of elements
2569 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2570 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2571 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2572 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2573 # @param Angles list of angles
2574 # @param HasRefPoint allows to use base point
2575 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2576 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2577 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2578 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2579 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2580 if IDsOfElements == []:
2581 IDsOfElements = self.GetElementsId()
2582 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2583 RefPoint = GetPointStruct(RefPoint)
2585 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2586 HasAngles, Angles, HasRefPoint, RefPoint)
2588 ## Generate new elements by extrusion of the elements belong to object
2589 # A path of extrusion must be a meshed edge.
2590 # @param IDsOfElements is ids of elements
2591 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2592 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2593 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2594 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2595 # @param Angles list of angles
2596 # @param HasRefPoint allows to use base point
2597 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2598 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2599 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2600 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2601 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2602 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2603 RefPoint = GetPointStruct(RefPoint)
2604 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2605 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation)
2607 ## Symmetrical copy of mesh elements
2608 # @param IDsOfElements list of elements ids
2609 # @param Mirror is AxisStruct or geom object(point, line, plane)
2610 # @param theMirrorType is POINT, AXIS or PLANE
2611 # If the Mirror is geom object this parameter is unnecessary
2612 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2613 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2614 if IDsOfElements == []:
2615 IDsOfElements = self.GetElementsId()
2616 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2617 Mirror = GetAxisStruct(Mirror)
2618 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2620 ## Symmetrical copy of object
2621 # @param theObject mesh, submesh or group
2622 # @param Mirror is AxisStruct or geom object(point, line, plane)
2623 # @param theMirrorType is POINT, AXIS or PLANE
2624 # If the Mirror is geom object this parameter is unnecessary
2625 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2626 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2627 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2628 Mirror = GetAxisStruct(Mirror)
2629 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2631 ## Translates the elements
2632 # @param IDsOfElements list of elements ids
2633 # @param Vector direction of translation(DirStruct or vector)
2634 # @param Copy allows to copy the translated elements
2635 def Translate(self, IDsOfElements, Vector, Copy):
2636 if IDsOfElements == []:
2637 IDsOfElements = self.GetElementsId()
2638 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2639 Vector = GetDirStruct(Vector)
2640 self.editor.Translate(IDsOfElements, Vector, Copy)
2642 ## Translates the object
2643 # @param theObject object to translate(mesh, submesh, or group)
2644 # @param Vector direction of translation(DirStruct or geom vector)
2645 # @param Copy allows to copy the translated elements
2646 def TranslateObject(self, theObject, Vector, Copy):
2647 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2648 Vector = GetDirStruct(Vector)
2649 self.editor.TranslateObject(theObject, Vector, Copy)
2651 ## Rotates the elements
2652 # @param IDsOfElements list of elements ids
2653 # @param Axis axis of rotation(AxisStruct or geom line)
2654 # @param AngleInRadians angle of rotation(in radians)
2655 # @param Copy allows to copy the rotated elements
2656 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2657 if IDsOfElements == []:
2658 IDsOfElements = self.GetElementsId()
2659 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2660 Axis = GetAxisStruct(Axis)
2661 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2663 ## Rotates the object
2664 # @param theObject object to rotate(mesh, submesh, or group)
2665 # @param Axis axis of rotation(AxisStruct or geom line)
2666 # @param AngleInRadians angle of rotation(in radians)
2667 # @param Copy allows to copy the rotated elements
2668 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2669 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2671 ## Find group of nodes close to each other within Tolerance.
2672 # @param Tolerance tolerance value
2673 # @param list of group of nodes
2674 def FindCoincidentNodes (self, Tolerance):
2675 return self.editor.FindCoincidentNodes(Tolerance)
2677 ## Find group of nodes close to each other within Tolerance.
2678 # @param Tolerance tolerance value
2679 # @param SubMeshOrGroup SubMesh or Group
2680 # @param list of group of nodes
2681 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2682 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2685 # @param list of group of nodes
2686 def MergeNodes (self, GroupsOfNodes):
2687 self.editor.MergeNodes(GroupsOfNodes)
2689 ## Find elements built on the same nodes.
2690 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2691 # @return a list of groups of equal elements
2692 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2693 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2695 ## Merge elements in each given group.
2696 # @param GroupsOfElementsID groups of elements for merging
2697 def MergeElements(self, GroupsOfElementsID):
2698 self.editor.MergeElements(GroupsOfElementsID)
2700 ## Remove all but one of elements built on the same nodes.
2701 def MergeEqualElements(self):
2702 self.editor.MergeEqualElements()
2705 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2706 FirstNodeID2, SecondNodeID2, LastNodeID2,
2707 CreatePolygons, CreatePolyedrs):
2708 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2709 FirstNodeID2, SecondNodeID2, LastNodeID2,
2710 CreatePolygons, CreatePolyedrs)
2712 ## Sew conform free borders
2713 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2714 FirstNodeID2, SecondNodeID2):
2715 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2716 FirstNodeID2, SecondNodeID2)
2718 ## Sew border to side
2719 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2720 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2721 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2722 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2724 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2725 # merged with nodes of elements of Side2.
2726 # Number of elements in theSide1 and in theSide2 must be
2727 # equal and they should have similar node connectivity.
2728 # The nodes to merge should belong to sides borders and
2729 # the first node should be linked to the second.
2730 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2731 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2732 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2733 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2734 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2735 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2737 ## Set new nodes for given element.
2738 # @param ide the element id
2739 # @param newIDs nodes ids
2740 # @return If number of nodes is not corresponded to type of element - returns false
2741 def ChangeElemNodes(self, ide, newIDs):
2742 return self.editor.ChangeElemNodes(ide, newIDs)
2744 ## If during last operation of MeshEditor some nodes were
2745 # created this method returns list of its IDs, \n
2746 # if new nodes not created - returns empty list
2747 def GetLastCreatedNodes(self):
2748 return self.editor.GetLastCreatedNodes()
2750 ## If during last operation of MeshEditor some elements were
2751 # created this method returns list of its IDs, \n
2752 # if new elements not creared - returns empty list
2753 def GetLastCreatedElems(self):
2754 return self.editor.GetLastCreatedElems()