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 ## Make DirStruct from a triplet
132 # @param x,y,z are vector components
133 # @return SMESH.DirStruct
134 def MakeDirStruct(x,y,z):
135 pnt = PointStruct(x,y,z)
136 return DirStruct(pnt)
138 ## Get AxisStruct from object
139 # @param theObj is GEOM object(line or plane)
140 # @return SMESH.AxisStruct
141 def GetAxisStruct(theObj):
142 edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
144 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
145 vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
146 vertex1 = geompy.PointCoordinates(vertex1)
147 vertex2 = geompy.PointCoordinates(vertex2)
148 vertex3 = geompy.PointCoordinates(vertex3)
149 vertex4 = geompy.PointCoordinates(vertex4)
150 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
151 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
152 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] ]
153 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
155 elif len(edges) == 1:
156 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
157 p1 = geompy.PointCoordinates( vertex1 )
158 p2 = geompy.PointCoordinates( vertex2 )
159 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
163 # From SMESH_Gen interface:
164 # ------------------------
166 ## Set the current mode
167 def SetEmbeddedMode( theMode ):
168 smesh.SetEmbeddedMode(theMode)
170 ## Get the current mode
171 def IsEmbeddedMode():
172 return smesh.IsEmbeddedMode()
174 ## Set the current study
175 def SetCurrentStudy( theStudy ):
176 smesh.SetCurrentStudy(theStudy)
178 ## Get the current study
179 def GetCurrentStudy():
180 return smesh.GetCurrentStudy()
182 ## Create Mesh object importing data from given UNV file
183 # @return an instance of Mesh class
184 def CreateMeshesFromUNV( theFileName ):
185 aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
186 aMesh = Mesh(aSmeshMesh)
189 ## Create Mesh object(s) importing data from given MED file
190 # @return a list of Mesh class instances
191 def CreateMeshesFromMED( theFileName ):
192 aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
194 for iMesh in range(len(aSmeshMeshes)) :
195 aMesh = Mesh(aSmeshMeshes[iMesh])
196 aMeshes.append(aMesh)
197 return aMeshes, aStatus
199 ## Create Mesh object importing data from given STL file
200 # @return an instance of Mesh class
201 def CreateMeshesFromSTL( theFileName ):
202 aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
203 aMesh = Mesh(aSmeshMesh)
206 ## From SMESH_Gen interface
207 def GetSubShapesId( theMainObject, theListOfSubObjects ):
208 return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
210 ## From SMESH_Gen interface. Creates pattern
212 return smesh.GetPattern()
216 # Filtering. Auxiliary functions:
217 # ------------------------------
219 ## Creates an empty criterion
220 # @return SMESH.Filter.Criterion
221 def GetEmptyCriterion():
222 Type = EnumToLong(FT_Undefined)
223 Compare = EnumToLong(FT_Undefined)
227 UnaryOp = EnumToLong(FT_Undefined)
228 BinaryOp = EnumToLong(FT_Undefined)
231 Precision = -1 ##@1e-07
232 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
233 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
235 ## Creates a criterion by given parameters
236 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
237 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
238 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
239 # @param Treshold is threshold value (range of ids as string, shape, numeric)
240 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
241 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
242 # FT_Undefined(must be for the last criterion in criteria)
243 # @return SMESH.Filter.Criterion
244 def GetCriterion(elementType,
246 Compare = FT_EqualTo,
248 UnaryOp=FT_Undefined,
249 BinaryOp=FT_Undefined):
250 aCriterion = GetEmptyCriterion()
251 aCriterion.TypeOfElement = elementType
252 aCriterion.Type = EnumToLong(CritType)
256 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
257 aCriterion.Compare = EnumToLong(Compare)
258 elif Compare == "=" or Compare == "==":
259 aCriterion.Compare = EnumToLong(FT_EqualTo)
261 aCriterion.Compare = EnumToLong(FT_LessThan)
263 aCriterion.Compare = EnumToLong(FT_MoreThan)
265 aCriterion.Compare = EnumToLong(FT_EqualTo)
268 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
269 FT_BelongToCylinder, FT_LyingOnGeom]:
271 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
272 aCriterion.ThresholdStr = GetName(aTreshold)
273 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
275 print "Error: Treshold should be a shape."
277 elif CritType == FT_RangeOfIds:
279 if isinstance(aTreshold, str):
280 aCriterion.ThresholdStr = aTreshold
282 print "Error: Treshold should be a string."
284 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
285 # Here we do not need treshold
286 if aTreshold == FT_LogicalNOT:
287 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
288 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
289 aCriterion.BinaryOp = aTreshold
293 aTreshold = float(aTreshold)
294 aCriterion.Threshold = aTreshold
296 print "Error: Treshold should be a number."
299 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
300 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
302 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
303 aCriterion.BinaryOp = EnumToLong(Treshold)
305 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
306 aCriterion.BinaryOp = EnumToLong(UnaryOp)
308 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
309 aCriterion.BinaryOp = EnumToLong(BinaryOp)
313 ## Creates filter by given parameters of criterion
314 # @param elementType is the type of elements in the group
315 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
316 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
317 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
318 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
319 # @return SMESH_Filter
320 def GetFilter(elementType,
321 CritType=FT_Undefined,
324 UnaryOp=FT_Undefined):
325 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
326 aFilterMgr = smesh.CreateFilterManager()
327 aFilter = aFilterMgr.CreateFilter()
329 aCriteria.append(aCriterion)
330 aFilter.SetCriteria(aCriteria)
333 ## Creates numerical functor by its type
334 # @param theCrierion is FT_...; functor type
335 # @return SMESH_NumericalFunctor
336 def GetFunctor(theCriterion):
337 aFilterMgr = smesh.CreateFilterManager()
338 if theCriterion == FT_AspectRatio:
339 return aFilterMgr.CreateAspectRatio()
340 elif theCriterion == FT_AspectRatio3D:
341 return aFilterMgr.CreateAspectRatio3D()
342 elif theCriterion == FT_Warping:
343 return aFilterMgr.CreateWarping()
344 elif theCriterion == FT_MinimumAngle:
345 return aFilterMgr.CreateMinimumAngle()
346 elif theCriterion == FT_Taper:
347 return aFilterMgr.CreateTaper()
348 elif theCriterion == FT_Skew:
349 return aFilterMgr.CreateSkew()
350 elif theCriterion == FT_Area:
351 return aFilterMgr.CreateArea()
352 elif theCriterion == FT_Volume3D:
353 return aFilterMgr.CreateVolume3D()
354 elif theCriterion == FT_MultiConnection:
355 return aFilterMgr.CreateMultiConnection()
356 elif theCriterion == FT_MultiConnection2D:
357 return aFilterMgr.CreateMultiConnection2D()
358 elif theCriterion == FT_Length:
359 return aFilterMgr.CreateLength()
360 elif theCriterion == FT_Length2D:
361 return aFilterMgr.CreateLength2D()
363 print "Error: given parameter is not numerucal functor type."
366 ## Print error message if a hypothesis was not assigned.
367 def TreatHypoStatus(status, hypName, geomName, isAlgo):
369 hypType = "algorithm"
371 hypType = "hypothesis"
373 if status == HYP_UNKNOWN_FATAL :
374 reason = "for unknown reason"
375 elif status == HYP_INCOMPATIBLE :
376 reason = "this hypothesis mismatches algorithm"
377 elif status == HYP_NOTCONFORM :
378 reason = "not conform mesh would be built"
379 elif status == HYP_ALREADY_EXIST :
380 reason = hypType + " of the same dimension already assigned to this shape"
381 elif status == HYP_BAD_DIM :
382 reason = hypType + " mismatches shape"
383 elif status == HYP_CONCURENT :
384 reason = "there are concurrent hypotheses on sub-shapes"
385 elif status == HYP_BAD_SUBSHAPE :
386 reason = "shape is neither the main one, nor its subshape, nor a valid group"
387 elif status == HYP_BAD_GEOMETRY:
388 reason = "geometry mismatches algorithm's expectation"
389 elif status == HYP_HIDDEN_ALGO:
390 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
391 elif status == HYP_HIDING_ALGO:
392 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
395 hypName = '"' + hypName + '"'
396 geomName= '"' + geomName+ '"'
397 if status < HYP_UNKNOWN_FATAL:
398 print hypName, "was assigned to", geomName,"but", reason
400 print hypName, "was not assigned to",geomName,":", reason
405 ## Mother class to define algorithm, recommended to do not use directly.
408 class Mesh_Algorithm:
409 # @class Mesh_Algorithm
410 # @brief Class Mesh_Algorithm
418 def FindHypothesis(self,hypname, args):
419 key = "%s %s %s" % (self.__class__.__name__, hypname, args)
420 if Mesh_Algorithm.hypos.has_key( key ):
421 return Mesh_Algorithm.hypos[ key ]
424 ## If the algorithm is global, return 0; \n
425 # else return the submesh associated to this algorithm.
426 def GetSubMesh(self):
429 ## Return the wrapped mesher.
430 def GetAlgorithm(self):
433 ## Get list of hypothesis that can be used with this algorithm
434 def GetCompatibleHypothesis(self):
437 list = self.algo.GetCompatibleHypothesis()
445 def SetName(self, name):
446 SetName(self.algo, name)
450 return self.algo.GetId()
453 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
455 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
456 algo = smesh.CreateHypothesis(hypo, so)
457 self.Assign(algo, mesh, geom)
461 def Assign(self, algo, mesh, geom):
463 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
472 name = geompy.SubShapeName(geom, piece)
473 geompy.addToStudyInFather(piece, geom, name)
474 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
477 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
478 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
481 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so", UseExisting=0):
484 hypo = self.FindHypothesis(hyp, args)
485 if hypo!=None: CreateNew = 0
488 hypo = smesh.CreateHypothesis(hyp, so)
489 key = "%s %s %s" % (self.__class__.__name__, hyp, args)
490 Mesh_Algorithm.hypos[key] = hypo
496 a = a + s + str(args[i])
499 name = GetName(self.geom)
500 #SetName(hypo, name + "/" + hyp + a) - NPAL16198
501 SetName(hypo, hyp + a)
503 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
504 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
508 # Public class: Mesh_Segment
509 # --------------------------
511 ## Class to define a segment 1D algorithm for discretization
514 class Mesh_Segment(Mesh_Algorithm):
516 algo = 0 # algorithm object common for all Mesh_Segments
518 ## Private constructor.
519 def __init__(self, mesh, geom=0):
520 if not Mesh_Segment.algo:
521 Mesh_Segment.algo = self.Create(mesh, geom, "Regular_1D")
523 self.Assign( Mesh_Segment.algo, mesh, geom)
526 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
527 # @param l for the length of segments that cut an edge
528 # @param UseExisting if ==true - search existing hypothesis created with
529 # same parameters, else (default) - create new
530 def LocalLength(self, l, UseExisting=0):
531 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting)
535 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
536 # @param n for the number of segments that cut an edge
537 # @param s for the scale factor (optional)
538 # @param UseExisting if ==true - search existing hypothesis created with
539 # same parameters, else (default) - create new
540 def NumberOfSegments(self, n, s=[], UseExisting=0):
542 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting)
544 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting)
545 hyp.SetDistrType( 1 )
546 hyp.SetScaleFactor(s)
547 hyp.SetNumberOfSegments(n)
550 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
551 # @param start for the length of the first segment
552 # @param end for the length of the last segment
553 # @param UseExisting if ==true - search existing hypothesis created with
554 # same parameters, else (default) - create new
555 def Arithmetic1D(self, start, end, UseExisting=0):
556 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting)
557 hyp.SetLength(start, 1)
558 hyp.SetLength(end , 0)
561 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
562 # @param start for the length of the first segment
563 # @param end for the length of the last segment
564 # @param UseExisting if ==true - search existing hypothesis created with
565 # same parameters, else (default) - create new
566 def StartEndLength(self, start, end, UseExisting=0):
567 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting)
568 hyp.SetLength(start, 1)
569 hyp.SetLength(end , 0)
572 ## Define "Deflection1D" hypothesis
573 # @param d for the deflection
574 # @param UseExisting if ==true - search existing hypothesis created with
575 # same parameters, else (default) - create new
576 def Deflection1D(self, d, UseExisting=0):
577 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting)
581 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
582 # the opposite side in the case of quadrangular faces
583 def Propagation(self):
584 return self.Hypothesis("Propagation", UseExisting=1)
586 ## Define "AutomaticLength" hypothesis
587 # @param fineness for the fineness [0-1]
588 # @param UseExisting if ==true - search existing hypothesis created with
589 # same parameters, else (default) - create new
590 def AutomaticLength(self, fineness=0, UseExisting=0):
591 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting)
592 hyp.SetFineness( fineness )
595 ## Define "SegmentLengthAroundVertex" hypothesis
596 # @param length for the segment length
597 # @param vertex for the length localization: vertex index [0,1] | verext object
598 # @param UseExisting if ==true - search existing hypothesis created with
599 # same parameters, else (default) - create new
600 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
602 store_geom = self.geom
604 if type(vertex) is types.IntType:
605 vertex = geompy.SubShapeAllSorted(self.geom,geompy.ShapeType["VERTEX"])[vertex]
609 hyp = self.Hypothesis("SegmentAroundVertex_0D",[length],UseExisting=UseExisting)
610 hyp = self.Hypothesis("SegmentLengthAroundVertex",[length],UseExisting=UseExisting)
611 self.geom = store_geom
612 hyp.SetLength( length )
615 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
616 # If the 2D mesher sees that all boundary edges are quadratic ones,
617 # it generates quadratic faces, else it generates linear faces using
618 # medium nodes as if they were vertex ones.
619 # The 3D mesher generates quadratic volumes only if all boundary faces
620 # are quadratic ones, else it fails.
621 def QuadraticMesh(self):
622 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1)
625 # Public class: Mesh_CompositeSegment
626 # --------------------------
628 ## Class to define a segment 1D algorithm for discretization
631 class Mesh_CompositeSegment(Mesh_Segment):
633 algo = 0 # algorithm object common for all Mesh_CompositeSegments
635 ## Private constructor.
636 def __init__(self, mesh, geom=0):
637 if not Mesh_CompositeSegment.algo:
638 Mesh_CompositeSegment.algo = self.Create(mesh, geom, "CompositeSegment_1D")
640 self.Assign( Mesh_CompositeSegment.algo, mesh, geom)
644 # Public class: Mesh_Segment_Python
645 # ---------------------------------
647 ## Class to define a segment 1D algorithm for discretization with python function
650 class Mesh_Segment_Python(Mesh_Segment):
652 algo = 0 # algorithm object common for all Mesh_Segment_Pythons
654 ## Private constructor.
655 def __init__(self, mesh, geom=0):
656 import Python1dPlugin
657 if not Mesh_Segment_Python.algo:
658 Mesh_Segment_Python.algo = self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
660 self.Assign( Mesh_Segment_Python.algo, mesh, geom)
663 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
664 # @param n for the number of segments that cut an edge
665 # @param func for the python function that calculate the length of all segments
666 # @param UseExisting if ==true - search existing hypothesis created with
667 # same parameters, else (default) - create new
668 def PythonSplit1D(self, n, func, UseExisting=0):
669 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so", UseExisting=UseExisting)
670 hyp.SetNumberOfSegments(n)
671 hyp.SetPythonLog10RatioFunction(func)
674 # Public class: Mesh_Triangle
675 # ---------------------------
677 ## Class to define a triangle 2D algorithm
680 class Mesh_Triangle(Mesh_Algorithm):
686 # algorithm objects common for all instances of Mesh_Triangle
691 ## Private constructor.
692 def __init__(self, mesh, algoType, geom=0):
693 if algoType == MEFISTO:
694 if not Mesh_Triangle.algoMEF:
695 Mesh_Triangle.algoMEF = self.Create(mesh, geom, "MEFISTO_2D")
697 self.Assign( Mesh_Triangle.algoMEF, mesh, geom)
701 elif algoType == NETGEN:
703 print "Warning: NETGENPlugin module unavailable"
705 if not Mesh_Triangle.algoNET:
706 Mesh_Triangle.algoNET = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
708 self.Assign( Mesh_Triangle.algoNET, mesh, geom)
711 elif algoType == NETGEN_2D:
713 print "Warning: NETGENPlugin module unavailable"
715 if not Mesh_Triangle.algoNET_2D:
716 Mesh_Triangle.algoNET_2D = self.Create(mesh, geom,
717 "NETGEN_2D_ONLY", "libNETGENEngine.so")
719 self.Assign( Mesh_Triangle.algoNET_2D, mesh, geom)
723 self.algoType = algoType
725 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
726 # @param area for the maximum area of each triangles
727 # @param UseExisting if ==true - search existing hypothesis created with
728 # same parameters, else (default) - create new
730 # Only for algoType == MEFISTO || NETGEN_2D
731 def MaxElementArea(self, area, UseExisting=0):
732 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
733 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting)
734 hyp.SetMaxElementArea(area)
736 elif self.algoType == NETGEN:
737 print "Netgen 1D-2D algo doesn't support this hypothesis"
740 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
742 # Only for algoType == MEFISTO || NETGEN_2D
743 def LengthFromEdges(self):
744 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
745 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1)
747 elif self.algoType == NETGEN:
748 print "Netgen 1D-2D algo doesn't support this hypothesis"
751 ## Set QuadAllowed flag
753 # Only for algoType == NETGEN || NETGEN_2D
754 def SetQuadAllowed(self, toAllow=True):
755 if self.algoType == NETGEN_2D:
756 if toAllow: # add QuadranglePreference
757 self.Hypothesis("QuadranglePreference", UseExisting=1)
758 else: # remove QuadranglePreference
759 for hyp in self.mesh.GetHypothesisList( self.geom ):
760 if hyp.GetName() == "QuadranglePreference":
761 self.mesh.RemoveHypothesis( self.geom, hyp )
766 if self.params == 0 and self.Parameters():
767 self.params.SetQuadAllowed(toAllow)
770 ## Define "Netgen 2D Parameters" hypothesis
772 # Only for algoType == NETGEN
773 def Parameters(self):
774 if self.algoType == NETGEN:
775 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
776 "libNETGENEngine.so", UseExisting=0)
778 elif self.algoType == MEFISTO:
779 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
781 elif self.algoType == NETGEN_2D:
782 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
783 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
789 # Only for algoType == NETGEN
790 def SetMaxSize(self, theSize):
791 if self.params == 0 and self.Parameters():
792 self.params.SetMaxSize(theSize)
794 ## Set SecondOrder flag
796 # Only for algoType == NETGEN
797 def SetSecondOrder(self, theVal):
798 if self.params == 0 and self.Parameters():
799 self.params.SetSecondOrder(theVal)
804 # Only for algoType == NETGEN
805 def SetOptimize(self, theVal):
806 if self.params == 0 and self.Parameters():
807 self.params.SetOptimize(theVal)
810 # @param theFineness is:
811 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
813 # Only for algoType == NETGEN
814 def SetFineness(self, theFineness):
815 if self.params == 0 and self.Parameters():
816 self.params.SetFineness(theFineness)
820 # Only for algoType == NETGEN
821 def SetGrowthRate(self, theRate):
822 if self.params == 0 and self.Parameters():
823 self.params.SetGrowthRate(theRate)
827 # Only for algoType == NETGEN
828 def SetNbSegPerEdge(self, theVal):
829 if self.params == 0 and self.Parameters():
830 self.params.SetNbSegPerEdge(theVal)
832 ## Set NbSegPerRadius
834 # Only for algoType == NETGEN
835 def SetNbSegPerRadius(self, theVal):
836 if self.params == 0 and self.Parameters():
837 self.params.SetNbSegPerRadius(theVal)
842 # Public class: Mesh_Quadrangle
843 # -----------------------------
845 ## Class to define a quadrangle 2D algorithm
848 class Mesh_Quadrangle(Mesh_Algorithm):
850 algo = 0 # algorithm object common for all Mesh_Quadrangles
852 ## Private constructor.
853 def __init__(self, mesh, geom=0):
854 if not Mesh_Quadrangle.algo:
855 Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
857 self.Assign( Mesh_Quadrangle.algo, mesh, geom)
860 ## Define "QuadranglePreference" hypothesis, forcing construction
861 # of quadrangles if the number of nodes on opposite edges is not the same
862 # in the case where the global number of nodes on edges is even
863 def QuadranglePreference(self):
864 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
867 # Public class: Mesh_Tetrahedron
868 # ------------------------------
870 ## Class to define a tetrahedron 3D algorithm
873 class Mesh_Tetrahedron(Mesh_Algorithm):
878 algoNET = 0 # algorithm object common for all Mesh_Tetrahedrons
879 algoGHS = 0 # algorithm object common for all Mesh_Tetrahedrons
880 algoFNET = 0 # algorithm object common for all Mesh_Tetrahedrons
882 ## Private constructor.
883 def __init__(self, mesh, algoType, geom=0):
884 if algoType == NETGEN:
885 if not Mesh_Tetrahedron.algoNET:
886 Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
888 self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
892 elif algoType == GHS3D:
893 if not Mesh_Tetrahedron.algoGHS:
895 Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
897 self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
901 elif algoType == FULL_NETGEN:
903 print "Warning: NETGENPlugin module has not been imported."
904 if not Mesh_Tetrahedron.algoFNET:
905 Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
907 self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
911 self.algoType = algoType
913 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
914 # @param vol for the maximum volume of each tetrahedral
915 # @param UseExisting if ==true - search existing hypothesis created with
916 # same parameters, else (default) - create new
917 def MaxElementVolume(self, vol, UseExisting=0):
918 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
919 hyp.SetMaxElementVolume(vol)
922 ## Define "Netgen 3D Parameters" hypothesis
923 def Parameters(self):
924 if (self.algoType == FULL_NETGEN):
925 self.params = self.Hypothesis("NETGEN_Parameters", [],
926 "libNETGENEngine.so", UseExisting=0)
929 print "Algo doesn't support this hypothesis"
933 def SetMaxSize(self, theSize):
936 self.params.SetMaxSize(theSize)
938 ## Set SecondOrder flag
939 def SetSecondOrder(self, theVal):
942 self.params.SetSecondOrder(theVal)
945 def SetOptimize(self, theVal):
948 self.params.SetOptimize(theVal)
951 # @param theFineness is:
952 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
953 def SetFineness(self, theFineness):
956 self.params.SetFineness(theFineness)
959 def SetGrowthRate(self, theRate):
962 self.params.SetGrowthRate(theRate)
965 def SetNbSegPerEdge(self, theVal):
968 self.params.SetNbSegPerEdge(theVal)
970 ## Set NbSegPerRadius
971 def SetNbSegPerRadius(self, theVal):
974 self.params.SetNbSegPerRadius(theVal)
976 # Public class: Mesh_Hexahedron
977 # ------------------------------
979 ## Class to define a hexahedron 3D algorithm
982 class Mesh_Hexahedron(Mesh_Algorithm):
984 algo = 0 # algorithm object common for all Mesh_Hexahedrons
986 ## Private constructor.
987 def __init__(self, mesh, geom=0):
988 if not Mesh_Hexahedron.algo:
989 Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
991 self.Assign( Mesh_Hexahedron.algo, mesh, geom)
994 # Deprecated, only for compatibility!
995 # Public class: Mesh_Netgen
996 # ------------------------------
998 ## Class to define a NETGEN-based 2D or 3D algorithm
999 # that need no discrete boundary (i.e. independent)
1001 # This class is deprecated, only for compatibility!
1004 class Mesh_Netgen(Mesh_Algorithm):
1008 algoNET23 = 0 # algorithm object common for all Mesh_Netgens
1009 algoNET2 = 0 # algorithm object common for all Mesh_Netgens
1011 ## Private constructor.
1012 def __init__(self, mesh, is3D, geom=0):
1014 print "Warning: NETGENPlugin module has not been imported."
1018 if not Mesh_Netgen.algoNET23:
1019 Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1021 self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1026 if not Mesh_Netgen.algoNET2:
1027 Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1029 self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1033 ## Define hypothesis containing parameters of the algorithm
1034 def Parameters(self):
1036 hyp = self.Hypothesis("NETGEN_Parameters", [],
1037 "libNETGENEngine.so", UseExisting=0)
1039 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1040 "libNETGENEngine.so", UseExisting=0)
1043 # Public class: Mesh_Projection1D
1044 # ------------------------------
1046 ## Class to define a projection 1D algorithm
1049 class Mesh_Projection1D(Mesh_Algorithm):
1051 algo = 0 # algorithm object common for all Mesh_Projection1Ds
1053 ## Private constructor.
1054 def __init__(self, mesh, geom=0):
1055 if not Mesh_Projection1D.algo:
1056 Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1058 self.Assign( Mesh_Projection1D.algo, mesh, geom)
1061 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1062 # take a mesh pattern from, and optionally association of vertices
1063 # between the source edge and a target one (where a hipothesis is assigned to)
1064 # @param edge to take nodes distribution from
1065 # @param mesh to take nodes distribution from (optional)
1066 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1067 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1068 # to associate with \a srcV (optional)
1069 # @param UseExisting if ==true - search existing hypothesis created with
1070 # same parameters, else (default) - create new
1071 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1072 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1073 hyp.SetSourceEdge( edge )
1074 if not mesh is None and isinstance(mesh, Mesh):
1075 mesh = mesh.GetMesh()
1076 hyp.SetSourceMesh( mesh )
1077 hyp.SetVertexAssociation( srcV, tgtV )
1081 # Public class: Mesh_Projection2D
1082 # ------------------------------
1084 ## Class to define a projection 2D algorithm
1087 class Mesh_Projection2D(Mesh_Algorithm):
1089 algo = 0 # algorithm object common for all Mesh_Projection2Ds
1091 ## Private constructor.
1092 def __init__(self, mesh, geom=0):
1093 if not Mesh_Projection2D.algo:
1094 Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1096 self.Assign( Mesh_Projection2D.algo, mesh, geom)
1099 ## Define "Source Face" hypothesis, specifying a meshed face to
1100 # take a mesh pattern from, and optionally association of vertices
1101 # between the source face and a target one (where a hipothesis is assigned to)
1102 # @param face to take mesh pattern from
1103 # @param mesh to take mesh pattern from (optional)
1104 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1105 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1106 # to associate with \a srcV1 (optional)
1107 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1108 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1109 # to associate with \a srcV2 (optional)
1110 # @param UseExisting if ==true - search existing hypothesis created with
1111 # same parameters, else (default) - create new
1113 # Note: association vertices must belong to one edge of a face
1114 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1115 srcV2=None, tgtV2=None, UseExisting=0):
1116 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1117 UseExisting=UseExisting)
1118 hyp.SetSourceFace( face )
1119 if not mesh is None and isinstance(mesh, Mesh):
1120 mesh = mesh.GetMesh()
1121 hyp.SetSourceMesh( mesh )
1122 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1125 # Public class: Mesh_Projection3D
1126 # ------------------------------
1128 ## Class to define a projection 3D algorithm
1131 class Mesh_Projection3D(Mesh_Algorithm):
1133 algo = 0 # algorithm object common for all Mesh_Projection3Ds
1135 ## Private constructor.
1136 def __init__(self, mesh, geom=0):
1137 if not Mesh_Projection3D.algo:
1138 Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1140 self.Assign( Mesh_Projection3D.algo, mesh, geom)
1143 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1144 # take a mesh pattern from, and optionally association of vertices
1145 # between the source solid and a target one (where a hipothesis is assigned to)
1146 # @param solid to take mesh pattern from
1147 # @param mesh to take mesh pattern from (optional)
1148 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1149 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1150 # to associate with \a srcV1 (optional)
1151 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1152 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1153 # to associate with \a srcV2 (optional)
1154 # @param UseExisting - if ==true - search existing hypothesis created with
1155 # same parameters, else (default) - create new
1157 # Note: association vertices must belong to one edge of a solid
1158 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1159 srcV2=0, tgtV2=0, UseExisting=0):
1160 hyp = self.Hypothesis("ProjectionSource3D",
1161 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1162 UseExisting=UseExisting)
1163 hyp.SetSource3DShape( solid )
1164 if not mesh is None and isinstance(mesh, Mesh):
1165 mesh = mesh.GetMesh()
1166 hyp.SetSourceMesh( mesh )
1167 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1171 # Public class: Mesh_Prism
1172 # ------------------------
1174 ## Class to define a 3D extrusion algorithm
1177 class Mesh_Prism3D(Mesh_Algorithm):
1179 algo = 0 # algorithm object common for all Mesh_Prism3Ds
1181 ## Private constructor.
1182 def __init__(self, mesh, geom=0):
1183 if not Mesh_Prism3D.algo:
1184 Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1186 self.Assign( Mesh_Prism3D.algo, mesh, geom)
1189 # Public class: Mesh_RadialPrism
1190 # -------------------------------
1192 ## Class to define a Radial Prism 3D algorithm
1195 class Mesh_RadialPrism3D(Mesh_Algorithm):
1197 algo = 0 # algorithm object common for all Mesh_RadialPrism3Ds
1199 ## Private constructor.
1200 def __init__(self, mesh, geom=0):
1201 if not Mesh_RadialPrism3D.algo:
1202 Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1204 self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1206 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1207 self.nbLayers = None
1209 ## Return 3D hypothesis holding the 1D one
1210 def Get3DHypothesis(self):
1211 return self.distribHyp
1213 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1214 # hypothes. Returns the created hypothes
1215 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1216 if not self.nbLayers is None:
1217 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1218 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1219 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
1220 hyp = smesh.CreateHypothesis(hypType, so)
1221 SetCurrentStudy( study ) # anable publishing
1222 self.distribHyp.SetLayerDistribution( hyp )
1225 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1226 # prisms to build between the inner and outer shells
1227 # @param UseExisting if ==true - search existing hypothesis created with
1228 # same parameters, else (default) - create new
1229 def NumberOfLayers(self, n, UseExisting=0):
1230 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1231 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1232 self.nbLayers.SetNumberOfLayers( n )
1233 return self.nbLayers
1235 ## Define "LocalLength" hypothesis, specifying segment length
1236 # to build between the inner and outer shells
1237 # @param l for the length of segments
1238 def LocalLength(self, l):
1239 hyp = self.OwnHypothesis("LocalLength", [l] )
1243 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1244 # prisms to build between the inner and outer shells
1245 # @param n for the number of segments
1246 # @param s for the scale factor (optional)
1247 def NumberOfSegments(self, n, s=[]):
1249 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1251 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1252 hyp.SetDistrType( 1 )
1253 hyp.SetScaleFactor(s)
1254 hyp.SetNumberOfSegments(n)
1257 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1258 # to build between the inner and outer shells as arithmetic length increasing
1259 # @param start for the length of the first segment
1260 # @param end for the length of the last segment
1261 def Arithmetic1D(self, start, end ):
1262 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1263 hyp.SetLength(start, 1)
1264 hyp.SetLength(end , 0)
1267 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1268 # to build between the inner and outer shells as geometric length increasing
1269 # @param start for the length of the first segment
1270 # @param end for the length of the last segment
1271 def StartEndLength(self, start, end):
1272 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1273 hyp.SetLength(start, 1)
1274 hyp.SetLength(end , 0)
1277 ## Define "AutomaticLength" hypothesis, specifying number of segments
1278 # to build between the inner and outer shells
1279 # @param fineness for the fineness [0-1]
1280 def AutomaticLength(self, fineness=0):
1281 hyp = self.OwnHypothesis("AutomaticLength")
1282 hyp.SetFineness( fineness )
1286 # Public class: Mesh
1287 # ==================
1289 ## Class to define a mesh
1291 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1301 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1302 # sets GUI name of this mesh to \a name.
1303 # @param obj Shape to be meshed or SMESH_Mesh object
1304 # @param name Study name of the mesh
1305 def __init__(self, obj=0, name=0):
1309 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1311 self.mesh = smesh.CreateMesh(self.geom)
1312 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1315 self.mesh = smesh.CreateEmptyMesh()
1317 SetName(self.mesh, name)
1319 SetName(self.mesh, GetName(obj))
1321 self.editor = self.mesh.GetMeshEditor()
1323 ## Method that inits the Mesh object from SMESH_Mesh interface
1324 # @param theMesh is SMESH_Mesh object
1325 def SetMesh(self, theMesh):
1327 self.geom = self.mesh.GetShapeToMesh()
1329 ## Method that returns the mesh
1330 # @return SMESH_Mesh object
1336 name = GetName(self.GetMesh())
1340 def SetName(self, name):
1341 SetName(self.GetMesh(), name)
1343 ## Get the subMesh object associated to a subShape. The subMesh object
1344 # gives access to nodes and elements IDs.
1345 # \n SubMesh will be used instead of SubShape in a next idl version to
1346 # adress a specific subMesh...
1347 def GetSubMesh(self, theSubObject, name):
1348 submesh = self.mesh.GetSubMesh(theSubObject, name)
1351 ## Method that returns the shape associated to the mesh
1352 # @return GEOM_Object
1356 ## Method that associates given shape to the mesh(entails the mesh recreation)
1357 # @param geom shape to be meshed(GEOM_Object)
1358 def SetShape(self, geom):
1359 self.mesh = smesh.CreateMesh(geom)
1361 ## Return true if hypotheses are defined well
1362 # @param theMesh is an instance of Mesh class
1363 # @param theSubObject subshape of a mesh shape
1364 def IsReadyToCompute(self, theSubObject):
1365 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1367 ## Return errors of hypotheses definintion
1368 # error list is empty if everything is OK
1369 # @param theMesh is an instance of Mesh class
1370 # @param theSubObject subshape of a mesh shape
1371 # @return a list of errors
1372 def GetAlgoState(self, theSubObject):
1373 return smesh.GetAlgoState(self.mesh, theSubObject)
1375 ## Return geometrical object the given element is built on.
1376 # The returned geometrical object, if not nil, is either found in the
1377 # study or is published by this method with the given name
1378 # @param theMesh is an instance of Mesh class
1379 # @param theElementID an id of the mesh element
1380 # @param theGeomName user defined name of geometrical object
1381 # @return GEOM::GEOM_Object instance
1382 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1383 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1385 ## Returns mesh dimension depending on shape one
1386 def MeshDimension(self):
1387 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1388 if len( shells ) > 0 :
1390 elif geompy.NumberOfFaces( self.geom ) > 0 :
1392 elif geompy.NumberOfEdges( self.geom ) > 0 :
1398 ## Creates a segment discretization 1D algorithm.
1399 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1400 # If the optional \a geom parameter is not sets, this algorithm is global.
1401 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1402 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1403 # @param geom If defined, subshape to be meshed
1404 def Segment(self, algo=REGULAR, geom=0):
1405 ## if Segment(geom) is called by mistake
1406 if isinstance( algo, geompy.GEOM._objref_GEOM_Object):
1407 algo, geom = geom, algo
1408 if not algo: algo = REGULAR
1411 return Mesh_Segment(self, geom)
1412 elif algo == PYTHON:
1413 return Mesh_Segment_Python(self, geom)
1414 elif algo == COMPOSITE:
1415 return Mesh_CompositeSegment(self, geom)
1417 return Mesh_Segment(self, geom)
1419 ## Creates a triangle 2D algorithm for faces.
1420 # If the optional \a geom parameter is not sets, this algorithm is global.
1421 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1422 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1423 # @param geom If defined, subshape to be meshed
1424 def Triangle(self, algo=MEFISTO, geom=0):
1425 ## if Triangle(geom) is called by mistake
1426 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1430 return Mesh_Triangle(self, algo, geom)
1432 ## Creates a quadrangle 2D algorithm for faces.
1433 # If the optional \a geom parameter is not sets, this algorithm is global.
1434 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1435 # @param geom If defined, subshape to be meshed
1436 def Quadrangle(self, geom=0):
1437 return Mesh_Quadrangle(self, geom)
1439 ## Creates a tetrahedron 3D algorithm for solids.
1440 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1441 # If the optional \a geom parameter is not sets, this algorithm is global.
1442 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1443 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1444 # @param geom If defined, subshape to be meshed
1445 def Tetrahedron(self, algo=NETGEN, geom=0):
1446 ## if Tetrahedron(geom) is called by mistake
1447 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1448 algo, geom = geom, algo
1449 if not algo: algo = NETGEN
1451 return Mesh_Tetrahedron(self, algo, geom)
1453 ## Creates a hexahedron 3D algorithm for solids.
1454 # If the optional \a geom parameter is not sets, this algorithm is global.
1455 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1456 # @param geom If defined, subshape to be meshed
1457 def Hexahedron(self, geom=0):
1458 return Mesh_Hexahedron(self, geom)
1460 ## Deprecated, only for compatibility!
1461 def Netgen(self, is3D, geom=0):
1462 return Mesh_Netgen(self, is3D, geom)
1464 ## Creates a projection 1D algorithm for edges.
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 Projection1D(self, geom=0):
1469 return Mesh_Projection1D(self, geom)
1471 ## Creates a projection 2D algorithm for faces.
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 Projection2D(self, geom=0):
1476 return Mesh_Projection2D(self, geom)
1478 ## Creates a projection 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 Projection3D(self, geom=0):
1483 return Mesh_Projection3D(self, geom)
1485 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1486 # If the optional \a geom parameter is not sets, this algorithm is global.
1487 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1488 # @param geom If defined, subshape to be meshed
1489 def Prism(self, geom=0):
1493 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1494 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1495 if nbSolids == 0 or nbSolids == nbShells:
1496 return Mesh_Prism3D(self, geom)
1497 return Mesh_RadialPrism3D(self, geom)
1499 ## Compute the mesh and return the status of the computation
1500 def Compute(self, geom=0):
1501 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1503 print "Compute impossible: mesh is not constructed on geom shape."
1509 ok = smesh.Compute(self.mesh, geom)
1510 except SALOME.SALOME_Exception, ex:
1511 print "Mesh computation failed, exception caught:"
1512 print " ", ex.details.text
1515 print "Mesh computation failed, exception caught:"
1516 traceback.print_exc()
1518 errors = smesh.GetAlgoState( self.mesh, geom )
1521 if err.isGlobalAlgo:
1529 reason = '%s %sD algorithm is missing' % (glob, dim)
1530 elif err.state == HYP_MISSING:
1531 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1532 % (glob, dim, name, dim))
1533 elif err.state == HYP_NOTCONFORM:
1534 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1535 elif err.state == HYP_BAD_PARAMETER:
1536 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1537 % ( glob, dim, name ))
1538 elif err.state == HYP_BAD_GEOMETRY:
1539 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1540 'its expectation' % ( glob, dim, name ))
1542 reason = "For unknown reason."+\
1543 " Revise Mesh.Compute() implementation in smesh.py!"
1545 if allReasons != "":
1548 allReasons += reason
1550 if allReasons != "":
1551 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1554 print '"' + GetName(self.mesh) + '"',"has not been computed."
1557 if salome.sg.hasDesktop():
1558 smeshgui = salome.ImportComponentGUI("SMESH")
1559 smeshgui.Init(salome.myStudyId)
1560 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1561 salome.sg.updateObjBrowser(1)
1565 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1566 # The parameter \a fineness [0,-1] defines mesh fineness
1567 def AutomaticTetrahedralization(self, fineness=0):
1568 dim = self.MeshDimension()
1570 self.RemoveGlobalHypotheses()
1571 self.Segment().AutomaticLength(fineness)
1573 self.Triangle().LengthFromEdges()
1576 self.Tetrahedron(NETGEN)
1578 return self.Compute()
1580 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1581 # The parameter \a fineness [0,-1] defines mesh fineness
1582 def AutomaticHexahedralization(self, fineness=0):
1583 dim = self.MeshDimension()
1585 self.RemoveGlobalHypotheses()
1586 self.Segment().AutomaticLength(fineness)
1593 return self.Compute()
1595 ## Assign hypothesis
1596 # @param hyp is a hypothesis to assign
1597 # @param geom is subhape of mesh geometry
1598 def AddHypothesis(self, hyp, geom=0 ):
1599 if isinstance( hyp, Mesh_Algorithm ):
1600 hyp = hyp.GetAlgorithm()
1605 status = self.mesh.AddHypothesis(geom, hyp)
1606 isAlgo = hyp._narrow( SMESH_Algo )
1607 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1610 ## Unassign hypothesis
1611 # @param hyp is a hypothesis to unassign
1612 # @param geom is subhape of mesh geometry
1613 def RemoveHypothesis(self, hyp, geom=0 ):
1614 if isinstance( hyp, Mesh_Algorithm ):
1615 hyp = hyp.GetAlgorithm()
1620 status = self.mesh.RemoveHypothesis(geom, hyp)
1623 ## Get the list of hypothesis added on a geom
1624 # @param geom is subhape of mesh geometry
1625 def GetHypothesisList(self, geom):
1626 return self.mesh.GetHypothesisList( geom )
1628 ## Removes all global hypotheses
1629 def RemoveGlobalHypotheses(self):
1630 current_hyps = self.mesh.GetHypothesisList( self.geom )
1631 for hyp in current_hyps:
1632 self.mesh.RemoveHypothesis( self.geom, hyp )
1636 ## Create a mesh group based on geometric object \a grp
1637 # and give a \a name, \n if this parameter is not defined
1638 # the name is the same as the geometric group name \n
1639 # Note: Works like GroupOnGeom().
1640 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1641 # @param name is the name of the mesh group
1642 # @return SMESH_GroupOnGeom
1643 def Group(self, grp, name=""):
1644 return self.GroupOnGeom(grp, name)
1646 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1647 # Export the mesh in a file with the MED format and choice the \a version of MED format
1648 # @param f is the file name
1649 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1650 def ExportToMED(self, f, version, opt=0):
1651 self.mesh.ExportToMED(f, opt, version)
1653 ## Export the mesh in a file with the MED format
1654 # @param f is the file name
1655 # @param auto_groups boolean parameter for creating/not creating
1656 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1657 # the typical use is auto_groups=false.
1658 # @param version MED format version(MED_V2_1 or MED_V2_2)
1659 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1660 self.mesh.ExportToMED(f, auto_groups, version)
1662 ## Export the mesh in a file with the DAT format
1663 # @param f is the file name
1664 def ExportDAT(self, f):
1665 self.mesh.ExportDAT(f)
1667 ## Export the mesh in a file with the UNV format
1668 # @param f is the file name
1669 def ExportUNV(self, f):
1670 self.mesh.ExportUNV(f)
1672 ## Export the mesh in a file with the STL format
1673 # @param f is the file name
1674 # @param ascii defined the kind of file contents
1675 def ExportSTL(self, f, ascii=1):
1676 self.mesh.ExportSTL(f, ascii)
1679 # Operations with groups:
1680 # ----------------------
1682 ## Creates an empty mesh group
1683 # @param elementType is the type of elements in the group
1684 # @param name is the name of the mesh group
1685 # @return SMESH_Group
1686 def CreateEmptyGroup(self, elementType, name):
1687 return self.mesh.CreateGroup(elementType, name)
1689 ## Creates a mesh group based on geometric object \a grp
1690 # and give a \a name, \n if this parameter is not defined
1691 # the name is the same as the geometric group name
1692 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1693 # @param name is the name of the mesh group
1694 # @return SMESH_GroupOnGeom
1695 def GroupOnGeom(self, grp, name="", type=None):
1697 name = grp.GetName()
1700 tgeo = str(grp.GetShapeType())
1701 if tgeo == "VERTEX":
1703 elif tgeo == "EDGE":
1705 elif tgeo == "FACE":
1707 elif tgeo == "SOLID":
1709 elif tgeo == "SHELL":
1711 elif tgeo == "COMPOUND":
1712 if len( geompy.GetObjectIDs( grp )) == 0:
1713 print "Mesh.Group: empty geometric group", GetName( grp )
1715 tgeo = geompy.GetType(grp)
1716 if tgeo == geompy.ShapeType["VERTEX"]:
1718 elif tgeo == geompy.ShapeType["EDGE"]:
1720 elif tgeo == geompy.ShapeType["FACE"]:
1722 elif tgeo == geompy.ShapeType["SOLID"]:
1726 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1729 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1731 ## Create a mesh group by the given ids of elements
1732 # @param groupName is the name of the mesh group
1733 # @param elementType is the type of elements in the group
1734 # @param elemIDs is the list of ids
1735 # @return SMESH_Group
1736 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1737 group = self.mesh.CreateGroup(elementType, groupName)
1741 ## Create a mesh group by the given conditions
1742 # @param groupName is the name of the mesh group
1743 # @param elementType is the type of elements in the group
1744 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1745 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1746 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1747 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1748 # @return SMESH_Group
1752 CritType=FT_Undefined,
1755 UnaryOp=FT_Undefined):
1756 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1757 group = self.MakeGroupByCriterion(groupName, aCriterion)
1760 ## Create a mesh group by the given criterion
1761 # @param groupName is the name of the mesh group
1762 # @param Criterion is the instance of Criterion class
1763 # @return SMESH_Group
1764 def MakeGroupByCriterion(self, groupName, Criterion):
1765 aFilterMgr = smesh.CreateFilterManager()
1766 aFilter = aFilterMgr.CreateFilter()
1768 aCriteria.append(Criterion)
1769 aFilter.SetCriteria(aCriteria)
1770 group = self.MakeGroupByFilter(groupName, aFilter)
1773 ## Create a mesh group by the given criteria(list of criterions)
1774 # @param groupName is the name of the mesh group
1775 # @param Criteria is the list of criterions
1776 # @return SMESH_Group
1777 def MakeGroupByCriteria(self, groupName, theCriteria):
1778 aFilterMgr = smesh.CreateFilterManager()
1779 aFilter = aFilterMgr.CreateFilter()
1780 aFilter.SetCriteria(theCriteria)
1781 group = self.MakeGroupByFilter(groupName, aFilter)
1784 ## Create a mesh group by the given filter
1785 # @param groupName is the name of the mesh group
1786 # @param Criterion is the instance of Filter class
1787 # @return SMESH_Group
1788 def MakeGroupByFilter(self, groupName, theFilter):
1789 anIds = theFilter.GetElementsId(self.mesh)
1790 anElemType = theFilter.GetElementType()
1791 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1794 ## Pass mesh elements through the given filter and return ids
1795 # @param theFilter is SMESH_Filter
1796 # @return list of ids
1797 def GetIdsFromFilter(self, theFilter):
1798 return theFilter.GetElementsId(self.mesh)
1800 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1801 # Returns list of special structures(borders).
1802 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1803 def GetFreeBorders(self):
1804 aFilterMgr = smesh.CreateFilterManager()
1805 aPredicate = aFilterMgr.CreateFreeEdges()
1806 aPredicate.SetMesh(self.mesh)
1807 aBorders = aPredicate.GetBorders()
1811 def RemoveGroup(self, group):
1812 self.mesh.RemoveGroup(group)
1814 ## Remove group with its contents
1815 def RemoveGroupWithContents(self, group):
1816 self.mesh.RemoveGroupWithContents(group)
1818 ## Get the list of groups existing in the mesh
1819 def GetGroups(self):
1820 return self.mesh.GetGroups()
1822 ## Get number of groups existing in the mesh
1824 return self.mesh.NbGroups()
1826 ## Get the list of names of groups existing in the mesh
1827 def GetGroupNames(self):
1828 groups = self.GetGroups()
1830 for group in groups:
1831 names.append(group.GetName())
1834 ## Union of two groups
1835 # New group is created. All mesh elements that are
1836 # present in initial groups are added to the new one
1837 def UnionGroups(self, group1, group2, name):
1838 return self.mesh.UnionGroups(group1, group2, name)
1840 ## Intersection of two groups
1841 # New group is created. All mesh elements that are
1842 # present in both initial groups are added to the new one.
1843 def IntersectGroups(self, group1, group2, name):
1844 return self.mesh.IntersectGroups(group1, group2, name)
1846 ## Cut of two groups
1847 # New group is created. All mesh elements that are present in
1848 # main group but do not present in tool group are added to the new one
1849 def CutGroups(self, mainGroup, toolGroup, name):
1850 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1853 # Get some info about mesh:
1854 # ------------------------
1856 ## Get the log of nodes and elements added or removed since previous
1858 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1859 # @return list of log_block structures:
1864 def GetLog(self, clearAfterGet):
1865 return self.mesh.GetLog(clearAfterGet)
1867 ## Clear the log of nodes and elements added or removed since previous
1868 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1870 self.mesh.ClearLog()
1872 ## Get the internal Id
1874 return self.mesh.GetId()
1877 def GetStudyId(self):
1878 return self.mesh.GetStudyId()
1880 ## Check group names for duplications.
1881 # Consider maximum group name length stored in MED file.
1882 def HasDuplicatedGroupNamesMED(self):
1883 return self.mesh.HasDuplicatedGroupNamesMED()
1885 ## Obtain instance of SMESH_MeshEditor
1886 def GetMeshEditor(self):
1887 return self.mesh.GetMeshEditor()
1890 def GetMEDMesh(self):
1891 return self.mesh.GetMEDMesh()
1894 # Get informations about mesh contents:
1895 # ------------------------------------
1897 ## Returns number of nodes in mesh
1899 return self.mesh.NbNodes()
1901 ## Returns number of elements in mesh
1902 def NbElements(self):
1903 return self.mesh.NbElements()
1905 ## Returns number of edges in mesh
1907 return self.mesh.NbEdges()
1909 ## Returns number of edges with given order in mesh
1910 # @param elementOrder is order of elements:
1911 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1912 def NbEdgesOfOrder(self, elementOrder):
1913 return self.mesh.NbEdgesOfOrder(elementOrder)
1915 ## Returns number of faces in mesh
1917 return self.mesh.NbFaces()
1919 ## Returns number of faces with given order in mesh
1920 # @param elementOrder is order of elements:
1921 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1922 def NbFacesOfOrder(self, elementOrder):
1923 return self.mesh.NbFacesOfOrder(elementOrder)
1925 ## Returns number of triangles in mesh
1926 def NbTriangles(self):
1927 return self.mesh.NbTriangles()
1929 ## Returns number of triangles with given order in mesh
1930 # @param elementOrder is order of elements:
1931 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1932 def NbTrianglesOfOrder(self, elementOrder):
1933 return self.mesh.NbTrianglesOfOrder(elementOrder)
1935 ## Returns number of quadrangles in mesh
1936 def NbQuadrangles(self):
1937 return self.mesh.NbQuadrangles()
1939 ## Returns number of quadrangles with given order in mesh
1940 # @param elementOrder is order of elements:
1941 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1942 def NbQuadranglesOfOrder(self, elementOrder):
1943 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1945 ## Returns number of polygons in mesh
1946 def NbPolygons(self):
1947 return self.mesh.NbPolygons()
1949 ## Returns number of volumes in mesh
1950 def NbVolumes(self):
1951 return self.mesh.NbVolumes()
1953 ## Returns number of volumes with given order in mesh
1954 # @param elementOrder is order of elements:
1955 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1956 def NbVolumesOfOrder(self, elementOrder):
1957 return self.mesh.NbVolumesOfOrder(elementOrder)
1959 ## Returns number of tetrahedrons in mesh
1961 return self.mesh.NbTetras()
1963 ## Returns number of tetrahedrons with given order in mesh
1964 # @param elementOrder is order of elements:
1965 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1966 def NbTetrasOfOrder(self, elementOrder):
1967 return self.mesh.NbTetrasOfOrder(elementOrder)
1969 ## Returns number of hexahedrons in mesh
1971 return self.mesh.NbHexas()
1973 ## Returns number of hexahedrons with given order in mesh
1974 # @param elementOrder is order of elements:
1975 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1976 def NbHexasOfOrder(self, elementOrder):
1977 return self.mesh.NbHexasOfOrder(elementOrder)
1979 ## Returns number of pyramids in mesh
1980 def NbPyramids(self):
1981 return self.mesh.NbPyramids()
1983 ## Returns number of pyramids with given order in mesh
1984 # @param elementOrder is order of elements:
1985 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1986 def NbPyramidsOfOrder(self, elementOrder):
1987 return self.mesh.NbPyramidsOfOrder(elementOrder)
1989 ## Returns number of prisms in mesh
1991 return self.mesh.NbPrisms()
1993 ## Returns number of prisms with given order in mesh
1994 # @param elementOrder is order of elements:
1995 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1996 def NbPrismsOfOrder(self, elementOrder):
1997 return self.mesh.NbPrismsOfOrder(elementOrder)
1999 ## Returns number of polyhedrons in mesh
2000 def NbPolyhedrons(self):
2001 return self.mesh.NbPolyhedrons()
2003 ## Returns number of submeshes in mesh
2004 def NbSubMesh(self):
2005 return self.mesh.NbSubMesh()
2007 ## Returns list of mesh elements ids
2008 def GetElementsId(self):
2009 return self.mesh.GetElementsId()
2011 ## Returns list of ids of mesh elements with given type
2012 # @param elementType is required type of elements
2013 def GetElementsByType(self, elementType):
2014 return self.mesh.GetElementsByType(elementType)
2016 ## Returns list of mesh nodes ids
2017 def GetNodesId(self):
2018 return self.mesh.GetNodesId()
2020 # Get informations about mesh elements:
2021 # ------------------------------------
2023 ## Returns type of mesh element
2024 def GetElementType(self, id, iselem):
2025 return self.mesh.GetElementType(id, iselem)
2027 ## Returns list of submesh elements ids
2028 # @param shapeID is geom object(subshape) IOR
2029 def GetSubMeshElementsId(self, shapeID):
2030 return self.mesh.GetSubMeshElementsId(shapeID)
2032 ## Returns list of submesh nodes ids
2033 # @param shapeID is geom object(subshape) IOR
2034 def GetSubMeshNodesId(self, shapeID, all):
2035 return self.mesh.GetSubMeshNodesId(shapeID, all)
2037 ## Returns list of ids of submesh elements with given type
2038 # @param shapeID is geom object(subshape) IOR
2039 def GetSubMeshElementType(self, shapeID):
2040 return self.mesh.GetSubMeshElementType(shapeID)
2042 ## Get mesh description
2044 return self.mesh.Dump()
2047 # Get information about nodes and elements of mesh by its ids:
2048 # -----------------------------------------------------------
2050 ## Get XYZ coordinates of node as list of double
2051 # \n If there is not node for given ID - returns empty list
2052 def GetNodeXYZ(self, id):
2053 return self.mesh.GetNodeXYZ(id)
2055 ## For given node returns list of IDs of inverse elements
2056 # \n If there is not node for given ID - returns empty list
2057 def GetNodeInverseElements(self, id):
2058 return self.mesh.GetNodeInverseElements(id)
2060 ## If given element is node returns IDs of shape from position
2061 # \n If there is not node for given ID - returns -1
2062 def GetShapeID(self, id):
2063 return self.mesh.GetShapeID(id)
2065 ## For given element returns ID of result shape after
2066 # FindShape() from SMESH_MeshEditor
2067 # \n If there is not element for given ID - returns -1
2068 def GetShapeIDForElem(self,id):
2069 return self.mesh.GetShapeIDForElem(id)
2071 ## Returns number of nodes for given element
2072 # \n If there is not element for given ID - returns -1
2073 def GetElemNbNodes(self, id):
2074 return self.mesh.GetElemNbNodes(id)
2076 ## Returns ID of node by given index for given element
2077 # \n If there is not element for given ID - returns -1
2078 # \n If there is not node for given index - returns -2
2079 def GetElemNode(self, id, index):
2080 return self.mesh.GetElemNode(id, index)
2082 ## Returns IDs of nodes of given element
2083 def GetElemNodes(self, id):
2084 return self.mesh.GetElemNodes(id)
2086 ## Returns true if given node is medium node
2087 # in given quadratic element
2088 def IsMediumNode(self, elementID, nodeID):
2089 return self.mesh.IsMediumNode(elementID, nodeID)
2091 ## Returns true if given node is medium node
2092 # in one of quadratic elements
2093 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2094 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2096 ## Returns number of edges for given element
2097 def ElemNbEdges(self, id):
2098 return self.mesh.ElemNbEdges(id)
2100 ## Returns number of faces for given element
2101 def ElemNbFaces(self, id):
2102 return self.mesh.ElemNbFaces(id)
2104 ## Returns true if given element is polygon
2105 def IsPoly(self, id):
2106 return self.mesh.IsPoly(id)
2108 ## Returns true if given element is quadratic
2109 def IsQuadratic(self, id):
2110 return self.mesh.IsQuadratic(id)
2112 ## Returns XYZ coordinates of bary center for given element
2114 # \n If there is not element for given ID - returns empty list
2115 def BaryCenter(self, id):
2116 return self.mesh.BaryCenter(id)
2119 # Mesh edition (SMESH_MeshEditor functionality):
2120 # ---------------------------------------------
2122 ## Removes elements from mesh by ids
2123 # @param IDsOfElements is list of ids of elements to remove
2124 def RemoveElements(self, IDsOfElements):
2125 return self.editor.RemoveElements(IDsOfElements)
2127 ## Removes nodes from mesh by ids
2128 # @param IDsOfNodes is list of ids of nodes to remove
2129 def RemoveNodes(self, IDsOfNodes):
2130 return self.editor.RemoveNodes(IDsOfNodes)
2132 ## Add node to mesh by coordinates
2133 def AddNode(self, x, y, z):
2134 return self.editor.AddNode( x, y, z)
2137 ## Create edge both similar and quadratic (this is determed
2138 # by number of given nodes).
2139 # @param IdsOfNodes List of node IDs for creation of element.
2140 # Needed order of nodes in this list corresponds to description
2141 # of MED. \n This description is located by the following link:
2142 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2143 def AddEdge(self, IDsOfNodes):
2144 return self.editor.AddEdge(IDsOfNodes)
2146 ## Create face both similar and quadratic (this is determed
2147 # by number of given nodes).
2148 # @param IdsOfNodes List of node IDs for creation of element.
2149 # Needed order of nodes in this list corresponds to description
2150 # of MED. \n This description is located by the following link:
2151 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2152 def AddFace(self, IDsOfNodes):
2153 return self.editor.AddFace(IDsOfNodes)
2155 ## Add polygonal face to mesh by list of nodes ids
2156 def AddPolygonalFace(self, IdsOfNodes):
2157 return self.editor.AddPolygonalFace(IdsOfNodes)
2159 ## Create volume both similar and quadratic (this is determed
2160 # by number of given nodes).
2161 # @param IdsOfNodes List of node IDs for creation of element.
2162 # Needed order of nodes in this list corresponds to description
2163 # of MED. \n This description is located by the following link:
2164 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2165 def AddVolume(self, IDsOfNodes):
2166 return self.editor.AddVolume(IDsOfNodes)
2168 ## Create volume of many faces, giving nodes for each face.
2169 # @param IdsOfNodes List of node IDs for volume creation face by face.
2170 # @param Quantities List of integer values, Quantities[i]
2171 # gives quantity of nodes in face number i.
2172 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2173 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2175 ## Create volume of many faces, giving IDs of existing faces.
2176 # @param IdsOfFaces List of face IDs for volume creation.
2178 # Note: The created volume will refer only to nodes
2179 # of the given faces, not to the faces itself.
2180 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2181 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2183 ## Move node with given id
2184 # @param NodeID id of the node
2185 # @param x new X coordinate
2186 # @param y new Y coordinate
2187 # @param z new Z coordinate
2188 def MoveNode(self, NodeID, x, y, z):
2189 return self.editor.MoveNode(NodeID, x, y, z)
2191 ## Find a node closest to a point
2192 # @param x X coordinate of a point
2193 # @param y Y coordinate of a point
2194 # @param z Z coordinate of a point
2195 # @return id of a node
2196 def FindNodeClosestTo(self, x, y, z):
2197 preview = self.mesh.GetMeshEditPreviewer()
2198 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2200 ## Find a node closest to a point and move it to a point location
2201 # @param x X coordinate of a point
2202 # @param y Y coordinate of a point
2203 # @param z Z coordinate of a point
2204 # @return id of a moved node
2205 def MeshToPassThroughAPoint(self, x, y, z):
2206 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2208 ## Replace two neighbour triangles sharing Node1-Node2 link
2209 # with ones built on the same 4 nodes but having other common link.
2210 # @param NodeID1 first node id
2211 # @param NodeID2 second node id
2212 # @return false if proper faces not found
2213 def InverseDiag(self, NodeID1, NodeID2):
2214 return self.editor.InverseDiag(NodeID1, NodeID2)
2216 ## Replace two neighbour triangles sharing Node1-Node2 link
2217 # with a quadrangle built on the same 4 nodes.
2218 # @param NodeID1 first node id
2219 # @param NodeID2 second node id
2220 # @return false if proper faces not found
2221 def DeleteDiag(self, NodeID1, NodeID2):
2222 return self.editor.DeleteDiag(NodeID1, NodeID2)
2224 ## Reorient elements by ids
2225 # @param IDsOfElements if undefined reorient all mesh elements
2226 def Reorient(self, IDsOfElements=None):
2227 if IDsOfElements == None:
2228 IDsOfElements = self.GetElementsId()
2229 return self.editor.Reorient(IDsOfElements)
2231 ## Reorient all elements of the object
2232 # @param theObject is mesh, submesh or group
2233 def ReorientObject(self, theObject):
2234 return self.editor.ReorientObject(theObject)
2236 ## Fuse neighbour triangles into quadrangles.
2237 # @param IDsOfElements The triangles to be fused,
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 TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2243 if IDsOfElements == []:
2244 IDsOfElements = self.GetElementsId()
2245 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
2247 ## Fuse neighbour triangles of the object into quadrangles
2248 # @param theObject is mesh, submesh or group
2249 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2250 # @param MaxAngle is a max angle between element normals at which fusion
2251 # is still performed; theMaxAngle is mesured in radians.
2252 # @return TRUE in case of success, FALSE otherwise.
2253 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2254 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
2256 ## Split quadrangles into triangles.
2257 # @param IDsOfElements the faces to be splitted.
2258 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2259 # @param @return TRUE in case of success, FALSE otherwise.
2260 def QuadToTri (self, IDsOfElements, theCriterion):
2261 if IDsOfElements == []:
2262 IDsOfElements = self.GetElementsId()
2263 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
2265 ## Split quadrangles into triangles.
2266 # @param theObject object to taking list of elements from, is mesh, submesh or group
2267 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2268 def QuadToTriObject (self, theObject, theCriterion):
2269 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
2271 ## Split quadrangles into triangles.
2272 # @param theElems The faces to be splitted
2273 # @param the13Diag is used to choose a diagonal for splitting.
2274 # @return TRUE in case of success, FALSE otherwise.
2275 def SplitQuad (self, IDsOfElements, Diag13):
2276 if IDsOfElements == []:
2277 IDsOfElements = self.GetElementsId()
2278 return self.editor.SplitQuad(IDsOfElements, Diag13)
2280 ## Split quadrangles into triangles.
2281 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2282 def SplitQuadObject (self, theObject, Diag13):
2283 return self.editor.SplitQuadObject(theObject, Diag13)
2285 ## Find better splitting of the given quadrangle.
2286 # @param IDOfQuad ID of the quadrangle to be splitted.
2287 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2288 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2289 # diagonal is better, 0 if error occurs.
2290 def BestSplit (self, IDOfQuad, theCriterion):
2291 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2293 ## Split quafrangle faces near triangular facets of volumes
2295 def SplitQuadsNearTriangularFacets(self):
2296 faces_array = self.GetElementsByType(SMESH.FACE)
2297 for face_id in faces_array:
2298 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2299 quad_nodes = self.mesh.GetElemNodes(face_id)
2300 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2301 isVolumeFound = False
2302 for node1_elem in node1_elems:
2303 if not isVolumeFound:
2304 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2305 nb_nodes = self.GetElemNbNodes(node1_elem)
2306 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2307 volume_elem = node1_elem
2308 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2309 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2310 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2311 isVolumeFound = True
2312 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2313 self.SplitQuad([face_id], False) # diagonal 2-4
2314 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2315 isVolumeFound = True
2316 self.SplitQuad([face_id], True) # diagonal 1-3
2317 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2318 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2319 isVolumeFound = True
2320 self.SplitQuad([face_id], True) # diagonal 1-3
2322 ## @brief Split hexahedrons into tetrahedrons.
2324 # Use pattern mapping functionality for splitting.
2325 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2326 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2327 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2328 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2329 # key-point will be mapped into <theNode001>-th node of each volume.
2330 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2331 # @return TRUE in case of success, FALSE otherwise.
2332 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2333 # Pattern: 5.---------.6
2338 # (0,0,1) 4.---------.7 * |
2345 # (0,0,0) 0.---------.3
2346 pattern_tetra = "!!! Nb of points: \n 8 \n\
2356 !!! Indices of points of 6 tetras: \n\
2364 pattern = GetPattern()
2365 isDone = pattern.LoadFromFile(pattern_tetra)
2367 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2370 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2371 isDone = pattern.MakeMesh(self.mesh, False, False)
2372 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2374 # split quafrangle faces near triangular facets of volumes
2375 self.SplitQuadsNearTriangularFacets()
2379 ## @brief Split hexahedrons into prisms.
2381 # Use pattern mapping functionality for splitting.
2382 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2383 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2384 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2385 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2386 # key-point will be mapped into <theNode001>-th node of each volume.
2387 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2388 # @param @return TRUE in case of success, FALSE otherwise.
2389 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2390 # Pattern: 5.---------.6
2395 # (0,0,1) 4.---------.7 |
2402 # (0,0,0) 0.---------.3
2403 pattern_prism = "!!! Nb of points: \n 8 \n\
2413 !!! Indices of points of 2 prisms: \n\
2417 pattern = GetPattern()
2418 isDone = pattern.LoadFromFile(pattern_prism)
2420 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2423 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2424 isDone = pattern.MakeMesh(self.mesh, False, False)
2425 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2427 # split quafrangle faces near triangular facets of volumes
2428 self.SplitQuadsNearTriangularFacets()
2433 # @param IDsOfElements list if ids of elements to smooth
2434 # @param IDsOfFixedNodes list of ids of fixed nodes.
2435 # Note that nodes built on edges and boundary nodes are always fixed.
2436 # @param MaxNbOfIterations maximum number of iterations
2437 # @param MaxAspectRatio varies in range [1.0, inf]
2438 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2439 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2440 MaxNbOfIterations, MaxAspectRatio, Method):
2441 if IDsOfElements == []:
2442 IDsOfElements = self.GetElementsId()
2443 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2444 MaxNbOfIterations, MaxAspectRatio, Method)
2446 ## Smooth elements belong to given object
2447 # @param theObject object to smooth
2448 # @param IDsOfFixedNodes list of ids of fixed nodes.
2449 # Note that nodes built on edges and boundary nodes are always fixed.
2450 # @param MaxNbOfIterations maximum number of iterations
2451 # @param MaxAspectRatio varies in range [1.0, inf]
2452 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2453 def SmoothObject(self, theObject, IDsOfFixedNodes,
2454 MaxNbOfIterations, MaxxAspectRatio, Method):
2455 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2456 MaxNbOfIterations, MaxxAspectRatio, Method)
2458 ## Parametric smooth the given elements
2459 # @param IDsOfElements list if ids of elements to smooth
2460 # @param IDsOfFixedNodes list of ids of fixed nodes.
2461 # Note that nodes built on edges and boundary nodes are always fixed.
2462 # @param MaxNbOfIterations maximum number of iterations
2463 # @param MaxAspectRatio varies in range [1.0, inf]
2464 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2465 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2466 MaxNbOfIterations, MaxAspectRatio, Method):
2467 if IDsOfElements == []:
2468 IDsOfElements = self.GetElementsId()
2469 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2470 MaxNbOfIterations, MaxAspectRatio, Method)
2472 ## Parametric smooth elements belong to given object
2473 # @param theObject object to smooth
2474 # @param IDsOfFixedNodes list of ids of fixed nodes.
2475 # Note that nodes built on edges and boundary nodes are always fixed.
2476 # @param MaxNbOfIterations maximum number of iterations
2477 # @param MaxAspectRatio varies in range [1.0, inf]
2478 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2479 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2480 MaxNbOfIterations, MaxAspectRatio, Method):
2481 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2482 MaxNbOfIterations, MaxAspectRatio, Method)
2484 ## Converts all mesh to quadratic one, deletes old elements, replacing
2485 # them with quadratic ones with the same id.
2486 def ConvertToQuadratic(self, theForce3d):
2487 self.editor.ConvertToQuadratic(theForce3d)
2489 ## Converts all mesh from quadratic to ordinary ones,
2490 # deletes old quadratic elements, \n replacing
2491 # them with ordinary mesh elements with the same id.
2492 def ConvertFromQuadratic(self):
2493 return self.editor.ConvertFromQuadratic()
2495 ## Renumber mesh nodes
2496 def RenumberNodes(self):
2497 self.editor.RenumberNodes()
2499 ## Renumber mesh elements
2500 def RenumberElements(self):
2501 self.editor.RenumberElements()
2503 ## Generate new elements by rotation of the elements around the axis
2504 # @param IDsOfElements list of ids of elements to sweep
2505 # @param Axix axis of rotation, AxisStruct or line(geom object)
2506 # @param AngleInRadians angle of Rotation
2507 # @param NbOfSteps number of steps
2508 # @param Tolerance tolerance
2509 # @param MakeGroups to generate new groups from existing ones
2510 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2511 if IDsOfElements == []:
2512 IDsOfElements = self.GetElementsId()
2513 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2514 Axix = GetAxisStruct(Axix)
2516 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2517 AngleInRadians, NbOfSteps, Tolerance)
2518 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2521 ## Generate new elements by rotation of the elements of object around the axis
2522 # @param theObject object wich elements should be sweeped
2523 # @param Axix axis of rotation, AxisStruct or line(geom object)
2524 # @param AngleInRadians angle of Rotation
2525 # @param NbOfSteps number of steps
2526 # @param Tolerance tolerance
2527 # @param MakeGroups to generate new groups from existing ones
2528 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2529 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2530 Axix = GetAxisStruct(Axix)
2532 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2533 NbOfSteps, Tolerance)
2534 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2537 ## Generate new elements by extrusion of the elements with given ids
2538 # @param IDsOfElements list of elements ids for extrusion
2539 # @param StepVector vector, defining the direction and value of extrusion
2540 # @param NbOfSteps the number of steps
2541 # @param MakeGroups to generate new groups from existing ones
2542 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2543 if IDsOfElements == []:
2544 IDsOfElements = self.GetElementsId()
2545 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2546 StepVector = GetDirStruct(StepVector)
2548 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2549 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2552 ## Generate new elements by extrusion of the elements with given ids
2553 # @param IDsOfElements is ids of elements
2554 # @param StepVector vector, defining the direction and value of extrusion
2555 # @param NbOfSteps the number of steps
2556 # @param ExtrFlags set flags for performing extrusion
2557 # @param SewTolerance uses for comparing locations of nodes if flag
2558 # EXTRUSION_FLAG_SEW is set
2559 # @param MakeGroups to generate new groups from existing ones
2560 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2561 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2562 StepVector = GetDirStruct(StepVector)
2564 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2565 ExtrFlags, SewTolerance)
2566 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2567 ExtrFlags, SewTolerance)
2570 ## Generate new elements by extrusion of the elements belong to object
2571 # @param theObject object wich elements should be processed
2572 # @param StepVector vector, defining the direction and value of extrusion
2573 # @param NbOfSteps the number of steps
2574 # @param MakeGroups to generate new groups from existing ones
2575 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2576 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2577 StepVector = GetDirStruct(StepVector)
2579 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2580 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2583 ## Generate new elements by extrusion of the elements belong to object
2584 # @param theObject object wich elements should be processed
2585 # @param StepVector vector, defining the direction and value of extrusion
2586 # @param NbOfSteps the number of steps
2587 # @param MakeGroups to generate new groups from existing ones
2588 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2589 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2590 StepVector = GetDirStruct(StepVector)
2592 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2593 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2596 ## Generate new elements by extrusion of the elements belong to object
2597 # @param theObject object wich elements should be processed
2598 # @param StepVector vector, defining the direction and value of extrusion
2599 # @param NbOfSteps the number of steps
2600 # @param MakeGroups to generate new groups from existing ones
2601 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2602 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2603 StepVector = GetDirStruct(StepVector)
2605 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2606 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2609 ## Generate new elements by extrusion of the given elements
2610 # A path of extrusion must be a meshed edge.
2611 # @param IDsOfElements is ids of elements
2612 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2613 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2614 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2615 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2616 # @param Angles list of angles
2617 # @param HasRefPoint allows to use base point
2618 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2619 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2620 # @param MakeGroups to generate new groups from existing ones
2621 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2622 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2623 HasAngles, Angles, HasRefPoint, RefPoint,
2624 MakeGroups=False, LinearVariation=False):
2625 if IDsOfElements == []:
2626 IDsOfElements = self.GetElementsId()
2627 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2628 RefPoint = GetPointStruct(RefPoint)
2631 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
2632 PathShape, NodeStart, HasAngles,
2633 Angles, HasRefPoint, RefPoint)
2634 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
2635 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2637 ## Generate new elements by extrusion of the elements belong to object
2638 # A path of extrusion must be a meshed edge.
2639 # @param IDsOfElements is ids of elements
2640 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2641 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2642 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2643 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2644 # @param Angles list of angles
2645 # @param HasRefPoint allows to use base point
2646 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2647 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2648 # @param MakeGroups to generate new groups from existing ones
2649 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2650 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2651 HasAngles, Angles, HasRefPoint, RefPoint,
2652 MakeGroups=False, LinearVariation=False):
2653 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2654 RefPoint = GetPointStruct(RefPoint)
2656 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
2657 PathShape, NodeStart, HasAngles,
2658 Angles, HasRefPoint, RefPoint)
2659 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
2660 NodeStart, HasAngles, Angles, HasRefPoint,
2663 ## Symmetrical copy of mesh elements
2664 # @param IDsOfElements list of elements ids
2665 # @param Mirror is AxisStruct or geom object(point, line, plane)
2666 # @param theMirrorType is POINT, AXIS or PLANE
2667 # If the Mirror is geom object this parameter is unnecessary
2668 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2669 # @param MakeGroups to generate new groups from existing ones (if Copy)
2670 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2671 if IDsOfElements == []:
2672 IDsOfElements = self.GetElementsId()
2673 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2674 Mirror = GetAxisStruct(Mirror)
2675 if Copy and MakeGroups:
2676 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2677 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2680 ## Symmetrical copy of object
2681 # @param theObject mesh, submesh or group
2682 # @param Mirror is AxisStruct or geom object(point, line, plane)
2683 # @param theMirrorType is POINT, AXIS or PLANE
2684 # If the Mirror is geom object this parameter is unnecessary
2685 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2686 # @param MakeGroups to generate new groups from existing ones (if Copy)
2687 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2688 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2689 Mirror = GetAxisStruct(Mirror)
2690 if Copy and MakeGroups:
2691 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2692 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2695 ## Translates the elements
2696 # @param IDsOfElements list of elements ids
2697 # @param Vector direction of translation(DirStruct or vector)
2698 # @param Copy allows to copy the translated elements
2699 # @param MakeGroups to generate new groups from existing ones (if Copy)
2700 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2701 if IDsOfElements == []:
2702 IDsOfElements = self.GetElementsId()
2703 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2704 Vector = GetDirStruct(Vector)
2705 if Copy and MakeGroups:
2706 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2707 self.editor.Translate(IDsOfElements, Vector, Copy)
2710 ## Translates the object
2711 # @param theObject object to translate(mesh, submesh, or group)
2712 # @param Vector direction of translation(DirStruct or geom vector)
2713 # @param Copy allows to copy the translated elements
2714 # @param MakeGroups to generate new groups from existing ones (if Copy)
2715 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2716 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2717 Vector = GetDirStruct(Vector)
2718 if Copy and MakeGroups:
2719 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2720 self.editor.TranslateObject(theObject, Vector, Copy)
2723 ## Rotates the elements
2724 # @param IDsOfElements list of elements ids
2725 # @param Axis axis of rotation(AxisStruct or geom line)
2726 # @param AngleInRadians angle of rotation(in radians)
2727 # @param Copy allows to copy the rotated elements
2728 # @param MakeGroups to generate new groups from existing ones (if Copy)
2729 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2730 if IDsOfElements == []:
2731 IDsOfElements = self.GetElementsId()
2732 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2733 Axis = GetAxisStruct(Axis)
2734 if Copy and MakeGroups:
2735 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2736 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2739 ## Rotates the object
2740 # @param theObject object to rotate(mesh, submesh, or group)
2741 # @param Axis axis of rotation(AxisStruct or geom line)
2742 # @param AngleInRadians angle of rotation(in radians)
2743 # @param Copy allows to copy the rotated elements
2744 # @param MakeGroups to generate new groups from existing ones (if Copy)
2745 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2746 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2747 Axis = GetAxisStruct(Axis)
2748 if Copy and MakeGroups:
2749 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2750 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2753 ## Find group of nodes close to each other within Tolerance.
2754 # @param Tolerance tolerance value
2755 # @param list of group of nodes
2756 def FindCoincidentNodes (self, Tolerance):
2757 return self.editor.FindCoincidentNodes(Tolerance)
2759 ## Find group of nodes close to each other within Tolerance.
2760 # @param Tolerance tolerance value
2761 # @param SubMeshOrGroup SubMesh or Group
2762 # @param list of group of nodes
2763 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2764 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2767 # @param list of group of nodes
2768 def MergeNodes (self, GroupsOfNodes):
2769 self.editor.MergeNodes(GroupsOfNodes)
2771 ## Find elements built on the same nodes.
2772 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2773 # @return a list of groups of equal elements
2774 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2775 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2777 ## Merge elements in each given group.
2778 # @param GroupsOfElementsID groups of elements for merging
2779 def MergeElements(self, GroupsOfElementsID):
2780 self.editor.MergeElements(GroupsOfElementsID)
2782 ## Remove all but one of elements built on the same nodes.
2783 def MergeEqualElements(self):
2784 self.editor.MergeEqualElements()
2787 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2788 FirstNodeID2, SecondNodeID2, LastNodeID2,
2789 CreatePolygons, CreatePolyedrs):
2790 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2791 FirstNodeID2, SecondNodeID2, LastNodeID2,
2792 CreatePolygons, CreatePolyedrs)
2794 ## Sew conform free borders
2795 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2796 FirstNodeID2, SecondNodeID2):
2797 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2798 FirstNodeID2, SecondNodeID2)
2800 ## Sew border to side
2801 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2802 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2803 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2804 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2806 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2807 # merged with nodes of elements of Side2.
2808 # Number of elements in theSide1 and in theSide2 must be
2809 # equal and they should have similar node connectivity.
2810 # The nodes to merge should belong to sides borders and
2811 # the first node should be linked to the second.
2812 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2813 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2814 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2815 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2816 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2817 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2819 ## Set new nodes for given element.
2820 # @param ide the element id
2821 # @param newIDs nodes ids
2822 # @return If number of nodes is not corresponded to type of element - returns false
2823 def ChangeElemNodes(self, ide, newIDs):
2824 return self.editor.ChangeElemNodes(ide, newIDs)
2826 ## If during last operation of MeshEditor some nodes were
2827 # created this method returns list of its IDs, \n
2828 # if new nodes not created - returns empty list
2829 def GetLastCreatedNodes(self):
2830 return self.editor.GetLastCreatedNodes()
2832 ## If during last operation of MeshEditor some elements were
2833 # created this method returns list of its IDs, \n
2834 # if new elements not creared - returns empty list
2835 def GetLastCreatedElems(self):
2836 return self.editor.GetLastCreatedElems()