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
38 # import NETGENPlugin module if possible
57 NETGEN_1D2D3D = FULL_NETGEN
58 NETGEN_FULL = FULL_NETGEN
60 # MirrorType enumeration
61 POINT = SMESH_MeshEditor.POINT
62 AXIS = SMESH_MeshEditor.AXIS
63 PLANE = SMESH_MeshEditor.PLANE
65 # Smooth_Method enumeration
66 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
67 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
69 # Fineness enumeration(for NETGEN)
81 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
82 smesh.SetCurrentStudy(salome.myStudy)
88 ior = salome.orb.object_to_string(obj)
89 sobj = salome.myStudy.FindObjectIOR(ior)
93 attr = sobj.FindAttribute("AttributeName")[1]
96 ## Sets name to object
97 def SetName(obj, name):
98 ior = salome.orb.object_to_string(obj)
99 sobj = salome.myStudy.FindObjectIOR(ior)
101 attr = sobj.FindAttribute("AttributeName")[1]
104 ## Returns long value from enumeration
105 # Uses for SMESH.FunctorType enumeration
106 def EnumToLong(theItem):
109 ## Get PointStruct from vertex
110 # @param theVertex is GEOM object(vertex)
111 # @return SMESH.PointStruct
112 def GetPointStruct(theVertex):
113 [x, y, z] = geompy.PointCoordinates(theVertex)
114 return PointStruct(x,y,z)
116 ## Get DirStruct from vector
117 # @param theVector is GEOM object(vector)
118 # @return SMESH.DirStruct
119 def GetDirStruct(theVector):
120 vertices = geompy.SubShapeAll( theVector, geompy.ShapeType["VERTEX"] )
121 if(len(vertices) != 2):
122 print "Error: vector object is incorrect."
124 p1 = geompy.PointCoordinates(vertices[0])
125 p2 = geompy.PointCoordinates(vertices[1])
126 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
130 ## Get AxisStruct from object
131 # @param theObj is GEOM object(line or plane)
132 # @return SMESH.AxisStruct
133 def GetAxisStruct(theObj):
134 edges = geompy.SubShapeAll( theObj, geompy.ShapeType["EDGE"] )
136 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
137 vertex3, vertex4 = geompy.SubShapeAll( edges[1], geompy.ShapeType["VERTEX"] )
138 vertex1 = geompy.PointCoordinates(vertex1)
139 vertex2 = geompy.PointCoordinates(vertex2)
140 vertex3 = geompy.PointCoordinates(vertex3)
141 vertex4 = geompy.PointCoordinates(vertex4)
142 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
143 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
144 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] ]
145 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
147 elif len(edges) == 1:
148 vertex1, vertex2 = geompy.SubShapeAll( edges[0], geompy.ShapeType["VERTEX"] )
149 p1 = geompy.PointCoordinates( vertex1 )
150 p2 = geompy.PointCoordinates( vertex2 )
151 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
155 # From SMESH_Gen interface:
156 # ------------------------
158 ## Set the current mode
159 def SetEmbeddedMode( theMode ):
160 smesh.SetEmbeddedMode(theMode)
162 ## Get the current mode
163 def IsEmbeddedMode():
164 return smesh.IsEmbeddedMode()
166 ## Set the current study
167 def SetCurrentStudy( theStudy ):
168 smesh.SetCurrentStudy(theStudy)
170 ## Get the current study
171 def GetCurrentStudy():
172 return smesh.GetCurrentStudy()
174 ## Create Mesh object importing data from given UNV file
175 # @return an instance of Mesh class
176 def CreateMeshesFromUNV( theFileName ):
177 aSmeshMesh = smesh.CreateMeshesFromUNV(theFileName)
178 aMesh = Mesh(aSmeshMesh)
181 ## Create Mesh object(s) importing data from given MED file
182 # @return a list of Mesh class instances
183 def CreateMeshesFromMED( theFileName ):
184 aSmeshMeshes, aStatus = smesh.CreateMeshesFromMED(theFileName)
186 for iMesh in range(len(aSmeshMeshes)) :
187 aMesh = Mesh(aSmeshMeshes[iMesh])
188 aMeshes.append(aMesh)
189 return aMeshes, aStatus
191 ## Create Mesh object importing data from given STL file
192 # @return an instance of Mesh class
193 def CreateMeshesFromSTL( theFileName ):
194 aSmeshMesh = smesh.CreateMeshesFromSTL(theFileName)
195 aMesh = Mesh(aSmeshMesh)
198 ## From SMESH_Gen interface
199 def GetSubShapesId( theMainObject, theListOfSubObjects ):
200 return smesh.GetSubShapesId(theMainObject, theListOfSubObjects)
202 ## From SMESH_Gen interface. Creates pattern
204 return smesh.GetPattern()
208 # Filtering. Auxiliary functions:
209 # ------------------------------
211 ## Creates an empty criterion
212 # @return SMESH.Filter.Criterion
213 def GetEmptyCriterion():
214 Type = EnumToLong(FT_Undefined)
215 Compare = EnumToLong(FT_Undefined)
219 UnaryOp = EnumToLong(FT_Undefined)
220 BinaryOp = EnumToLong(FT_Undefined)
223 Precision = -1 ##@1e-07
224 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
225 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
227 ## Creates a criterion by given parameters
228 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
229 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
230 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
231 # @param Treshold is threshold value (range of ids as string, shape, numeric)
232 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
233 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
234 # FT_Undefined(must be for the last criterion in criteria)
235 # @return SMESH.Filter.Criterion
236 def GetCriterion(elementType,
238 Compare = FT_EqualTo,
240 UnaryOp=FT_Undefined,
241 BinaryOp=FT_Undefined):
242 aCriterion = GetEmptyCriterion()
243 aCriterion.TypeOfElement = elementType
244 aCriterion.Type = EnumToLong(CritType)
248 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
249 aCriterion.Compare = EnumToLong(Compare)
250 elif Compare == "=" or Compare == "==":
251 aCriterion.Compare = EnumToLong(FT_EqualTo)
253 aCriterion.Compare = EnumToLong(FT_LessThan)
255 aCriterion.Compare = EnumToLong(FT_MoreThan)
257 aCriterion.Compare = EnumToLong(FT_EqualTo)
260 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
261 FT_BelongToCylinder, FT_LyingOnGeom]:
263 if isinstance(aTreshold, geompy.GEOM._objref_GEOM_Object):
264 aCriterion.ThresholdStr = GetName(aTreshold)
265 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
267 print "Error: Treshold should be a shape."
269 elif CritType == FT_RangeOfIds:
271 if isinstance(aTreshold, str):
272 aCriterion.ThresholdStr = aTreshold
274 print "Error: Treshold should be a string."
276 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
277 # Here we don't need treshold
278 if aTreshold == FT_LogicalNOT:
279 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
280 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
281 aCriterion.BinaryOp = aTreshold
285 aTreshold = float(aTreshold)
286 aCriterion.Threshold = aTreshold
288 print "Error: Treshold should be a number."
291 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
292 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
294 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
295 aCriterion.BinaryOp = EnumToLong(Treshold)
297 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
298 aCriterion.BinaryOp = EnumToLong(UnaryOp)
300 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
301 aCriterion.BinaryOp = EnumToLong(BinaryOp)
305 ## Creates filter by given parameters of criterion
306 # @param elementType is the type of elements in the group
307 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
308 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
309 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
310 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
311 # @return SMESH_Filter
312 def GetFilter(elementType,
313 CritType=FT_Undefined,
316 UnaryOp=FT_Undefined):
317 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
318 aFilterMgr = smesh.CreateFilterManager()
319 aFilter = aFilterMgr.CreateFilter()
321 aCriteria.append(aCriterion)
322 aFilter.SetCriteria(aCriteria)
325 ## Creates numerical functor by its type
326 # @param theCrierion is FT_...; functor type
327 # @return SMESH_NumericalFunctor
328 def GetFunctor(theCriterion):
329 aFilterMgr = smesh.CreateFilterManager()
330 if theCriterion == FT_AspectRatio:
331 return aFilterMgr.CreateAspectRatio()
332 elif theCriterion == FT_AspectRatio3D:
333 return aFilterMgr.CreateAspectRatio3D()
334 elif theCriterion == FT_Warping:
335 return aFilterMgr.CreateWarping()
336 elif theCriterion == FT_MinimumAngle:
337 return aFilterMgr.CreateMinimumAngle()
338 elif theCriterion == FT_Taper:
339 return aFilterMgr.CreateTaper()
340 elif theCriterion == FT_Skew:
341 return aFilterMgr.CreateSkew()
342 elif theCriterion == FT_Area:
343 return aFilterMgr.CreateArea()
344 elif theCriterion == FT_Volume3D:
345 return aFilterMgr.CreateVolume3D()
346 elif theCriterion == FT_MultiConnection:
347 return aFilterMgr.CreateMultiConnection()
348 elif theCriterion == FT_MultiConnection2D:
349 return aFilterMgr.CreateMultiConnection2D()
350 elif theCriterion == FT_Length:
351 return aFilterMgr.CreateLength()
352 elif theCriterion == FT_Length2D:
353 return aFilterMgr.CreateLength2D()
355 print "Error: given parameter is not numerucal functor type."
358 ## Print error message if a hypothesis was not assigned.
359 def TreatHypoStatus(status, hypName, geomName, isAlgo):
361 hypType = "algorithm"
363 hypType = "hypothesis"
365 if status == HYP_UNKNOWN_FATAL :
366 reason = "for unknown reason"
367 elif status == HYP_INCOMPATIBLE :
368 reason = "this hypothesis mismatches algorithm"
369 elif status == HYP_NOTCONFORM :
370 reason = "not conform mesh would be built"
371 elif status == HYP_ALREADY_EXIST :
372 reason = hypType + " of the same dimension already assigned to this shape"
373 elif status == HYP_BAD_DIM :
374 reason = hypType + " mismatches shape"
375 elif status == HYP_CONCURENT :
376 reason = "there are concurrent hypotheses on sub-shapes"
377 elif status == HYP_BAD_SUBSHAPE :
378 reason = "shape is neither the main one, nor its subshape, nor a valid group"
379 elif status == HYP_BAD_GEOMETRY:
380 reason = "geometry mismatches algorithm's expectation"
381 elif status == HYP_HIDDEN_ALGO:
382 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
383 elif status == HYP_HIDING_ALGO:
384 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
387 hypName = '"' + hypName + '"'
388 geomName= '"' + geomName+ '"'
389 if status < HYP_UNKNOWN_FATAL:
390 print hypName, "was assigned to", geomName,"but", reason
392 print hypName, "was not assigned to",geomName,":", reason
397 ## Mother class to define algorithm, recommended to don't use directly.
400 class Mesh_Algorithm:
401 # @class Mesh_Algorithm
402 # @brief Class Mesh_Algorithm
410 def FindHypothesis(self,hypname, args):
411 key = "%s %s %s" % (self.__class__.__name__, hypname, args)
412 if Mesh_Algorithm.hypos.has_key( key ):
413 return Mesh_Algorithm.hypos[ key ]
416 ## If the algorithm is global, return 0; \n
417 # else return the submesh associated to this algorithm.
418 def GetSubMesh(self):
421 ## Return the wrapped mesher.
422 def GetAlgorithm(self):
425 ## Get list of hypothesis that can be used with this algorithm
426 def GetCompatibleHypothesis(self):
429 list = self.algo.GetCompatibleHypothesis()
437 def SetName(self, name):
438 SetName(self.algo, name)
442 return self.algo.GetId()
445 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
447 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
448 algo = smesh.CreateHypothesis(hypo, so)
449 self.Assign(algo, mesh, geom)
453 def Assign(self, algo, mesh, geom):
455 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
464 name = geompy.SubShapeName(geom, piece)
465 geompy.addToStudyInFather(piece, geom, name)
466 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
469 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
470 TreatHypoStatus( status, algo.GetName(), GetName(algo), True )
473 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so", UseExisting=0):
476 hypo = self.FindHypothesis(hyp, args)
477 if hypo!=None: CreateNew = 0
480 hypo = smesh.CreateHypothesis(hyp, so)
481 key = "%s %s %s" % (self.__class__.__name__, hyp, args)
482 Mesh_Algorithm.hypos[key] = hypo
488 a = a + s + str(args[i])
491 name = GetName(self.geom)
492 #SetName(hypo, name + "/" + hyp + a) - NPAL16198
493 SetName(hypo, hyp + a)
495 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
496 TreatHypoStatus( status, hyp, GetName(hypo), 0 )
500 # Public class: Mesh_Segment
501 # --------------------------
503 ## Class to define a segment 1D algorithm for discretization
506 class Mesh_Segment(Mesh_Algorithm):
508 algo = 0 # algorithm object common for all Mesh_Segment's
510 ## Private constructor.
511 def __init__(self, mesh, geom=0):
512 if not Mesh_Segment.algo:
513 Mesh_Segment.algo = self.Create(mesh, geom, "Regular_1D")
515 self.Assign( Mesh_Segment.algo, mesh, geom)
518 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
519 # @param l for the length of segments that cut an edge
520 # @param UseExisting if ==true - search existing hypothesis created with
521 # same parameters, else (default) - create new
522 def LocalLength(self, l, UseExisting=0):
523 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting)
527 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
528 # @param n for the number of segments that cut an edge
529 # @param s for the scale factor (optional)
530 # @param UseExisting if ==true - search existing hypothesis created with
531 # same parameters, else (default) - create new
532 def NumberOfSegments(self, n, s=[], UseExisting=0):
534 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting)
536 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting)
537 hyp.SetDistrType( 1 )
538 hyp.SetScaleFactor(s)
539 hyp.SetNumberOfSegments(n)
542 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
543 # @param start for the length of the first segment
544 # @param end for the length of the last segment
545 # @param UseExisting if ==true - search existing hypothesis created with
546 # same parameters, else (default) - create new
547 def Arithmetic1D(self, start, end, UseExisting=0):
548 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting)
549 hyp.SetLength(start, 1)
550 hyp.SetLength(end , 0)
553 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
554 # @param start for the length of the first segment
555 # @param end for the length of the last segment
556 # @param UseExisting if ==true - search existing hypothesis created with
557 # same parameters, else (default) - create new
558 def StartEndLength(self, start, end, UseExisting=0):
559 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting)
560 hyp.SetLength(start, 1)
561 hyp.SetLength(end , 0)
564 ## Define "Deflection1D" hypothesis
565 # @param d for the deflection
566 # @param UseExisting if ==true - search existing hypothesis created with
567 # same parameters, else (default) - create new
568 def Deflection1D(self, d, UseExisting=0):
569 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting)
573 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
574 # the opposite side in the case of quadrangular faces
575 def Propagation(self):
576 return self.Hypothesis("Propagation", UseExisting=1)
578 ## Define "AutomaticLength" hypothesis
579 # @param fineness for the fineness [0-1]
580 # @param UseExisting if ==true - search existing hypothesis created with
581 # same parameters, else (default) - create new
582 def AutomaticLength(self, fineness=0, UseExisting=0):
583 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting)
584 hyp.SetFineness( fineness )
587 ## Define "SegmentLengthAroundVertex" hypothesis
588 # @param length for the segment length
589 # @param vertex for the length localization: vertex index [0,1] | verext object
590 # @param UseExisting if ==true - search existing hypothesis created with
591 # same parameters, else (default) - create new
592 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
594 store_geom = self.geom
596 if type(vertex) is types.IntType:
597 vertex = geompy.SubShapeAllSorted(self.geom,geompy.ShapeType["VERTEX"])[vertex]
601 hyp = self.Hypothesis("SegmentAroundVertex_0D",[length],UseExisting=UseExisting)
602 hyp = self.Hypothesis("SegmentLengthAroundVertex",[length],UseExisting=UseExisting)
603 self.geom = store_geom
604 hyp.SetLength( length )
607 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
608 # If the 2D mesher sees that all boundary edges are quadratic ones,
609 # it generates quadratic faces, else it generates linear faces using
610 # medium nodes as if they were vertex ones.
611 # The 3D mesher generates quadratic volumes only if all boundary faces
612 # are quadratic ones, else it fails.
613 def QuadraticMesh(self):
614 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1)
617 # Public class: Mesh_CompositeSegment
618 # --------------------------
620 ## Class to define a segment 1D algorithm for discretization
623 class Mesh_CompositeSegment(Mesh_Segment):
625 algo = 0 # algorithm object common for all Mesh_CompositeSegment's
627 ## Private constructor.
628 def __init__(self, mesh, geom=0):
629 if not Mesh_CompositeSegment.algo:
630 Mesh_CompositeSegment.algo = self.Create(mesh, geom, "CompositeSegment_1D")
632 self.Assign( Mesh_CompositeSegment.algo, mesh, geom)
636 # Public class: Mesh_Segment_Python
637 # ---------------------------------
639 ## Class to define a segment 1D algorithm for discretization with python function
642 class Mesh_Segment_Python(Mesh_Segment):
644 algo = 0 # algorithm object common for all Mesh_Segment_Python's
646 ## Private constructor.
647 def __init__(self, mesh, geom=0):
648 import Python1dPlugin
649 if not Mesh_Segment_Python.algo:
650 Mesh_Segment_Python.algo = self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
652 self.Assign( Mesh_Segment_Python.algo, mesh, geom)
655 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
656 # @param n for the number of segments that cut an edge
657 # @param func for the python function that calculate the length of all segments
658 # @param UseExisting if ==true - search existing hypothesis created with
659 # same parameters, else (default) - create new
660 def PythonSplit1D(self, n, func, UseExisting=0):
661 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so", UseExisting=UseExisting)
662 hyp.SetNumberOfSegments(n)
663 hyp.SetPythonLog10RatioFunction(func)
666 # Public class: Mesh_Triangle
667 # ---------------------------
669 ## Class to define a triangle 2D algorithm
672 class Mesh_Triangle(Mesh_Algorithm):
678 # algorithm objects common for all instances of Mesh_Triangle
683 ## Private constructor.
684 def __init__(self, mesh, algoType, geom=0):
685 if algoType == MEFISTO:
686 if not Mesh_Triangle.algoMEF:
687 Mesh_Triangle.algoMEF = self.Create(mesh, geom, "MEFISTO_2D")
689 self.Assign( Mesh_Triangle.algoMEF, mesh, geom)
693 elif algoType == NETGEN:
695 print "Warning: NETGENPlugin module unavailable"
697 if not Mesh_Triangle.algoNET:
698 Mesh_Triangle.algoNET = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
700 self.Assign( Mesh_Triangle.algoNET, mesh, geom)
703 elif algoType == NETGEN_2D:
705 print "Warning: NETGENPlugin module unavailable"
707 if not Mesh_Triangle.algoNET_2D:
708 Mesh_Triangle.algoNET_2D = self.Create(mesh, geom,
709 "NETGEN_2D_ONLY", "libNETGENEngine.so")
711 self.Assign( Mesh_Triangle.algoNET_2D, mesh, geom)
715 self.algoType = algoType
717 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
718 # @param area for the maximum area of each triangles
719 # @param UseExisting if ==true - search existing hypothesis created with
720 # same parameters, else (default) - create new
722 # Only for algoType == MEFISTO || NETGEN_2D
723 def MaxElementArea(self, area, UseExisting=0):
724 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
725 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting)
726 hyp.SetMaxElementArea(area)
728 elif self.algoType == NETGEN:
729 print "Netgen 1D-2D algo doesn't support this hypothesis"
732 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
734 # Only for algoType == MEFISTO || NETGEN_2D
735 def LengthFromEdges(self):
736 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
737 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1)
739 elif self.algoType == NETGEN:
740 print "Netgen 1D-2D algo doesn't support this hypothesis"
743 ## Set QuadAllowed flag
745 # Only for algoType == NETGEN || NETGEN_2D
746 def SetQuadAllowed(self, toAllow=True):
747 if self.algoType == NETGEN_2D:
748 if toAllow: # add QuadranglePreference
749 self.Hypothesis("QuadranglePreference", UseExisting=1)
750 else: # remove QuadranglePreference
751 for hyp in self.mesh.GetHypothesisList( self.geom ):
752 if hyp.GetName() == "QuadranglePreference":
753 self.mesh.RemoveHypothesis( self.geom, hyp )
758 if self.params == 0 and self.Parameters():
759 self.params.SetQuadAllowed(toAllow)
762 ## Define "Netgen 2D Parameters" hypothesis
764 # Only for algoType == NETGEN
765 def Parameters(self):
766 if self.algoType == NETGEN:
767 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
768 "libNETGENEngine.so", UseExisting=0)
770 elif self.algoType == MEFISTO:
771 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
773 elif self.algoType == NETGEN_2D:
774 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
775 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
781 # Only for algoType == NETGEN
782 def SetMaxSize(self, theSize):
783 if self.params == 0 and self.Parameters():
784 self.params.SetMaxSize(theSize)
786 ## Set SecondOrder flag
788 # Only for algoType == NETGEN
789 def SetSecondOrder(self, theVal):
790 if self.params == 0 and self.Parameters():
791 self.params.SetSecondOrder(theVal)
796 # Only for algoType == NETGEN
797 def SetOptimize(self, theVal):
798 if self.params == 0 and self.Parameters():
799 self.params.SetOptimize(theVal)
802 # @param theFineness is:
803 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
805 # Only for algoType == NETGEN
806 def SetFineness(self, theFineness):
807 if self.params == 0 and self.Parameters():
808 self.params.SetFineness(theFineness)
812 # Only for algoType == NETGEN
813 def SetGrowthRate(self, theRate):
814 if self.params == 0 and self.Parameters():
815 self.params.SetGrowthRate(theRate)
819 # Only for algoType == NETGEN
820 def SetNbSegPerEdge(self, theVal):
821 if self.params == 0 and self.Parameters():
822 self.params.SetNbSegPerEdge(theVal)
824 ## Set NbSegPerRadius
826 # Only for algoType == NETGEN
827 def SetNbSegPerRadius(self, theVal):
828 if self.params == 0 and self.Parameters():
829 self.params.SetNbSegPerRadius(theVal)
834 # Public class: Mesh_Quadrangle
835 # -----------------------------
837 ## Class to define a quadrangle 2D algorithm
840 class Mesh_Quadrangle(Mesh_Algorithm):
842 algo = 0 # algorithm object common for all Mesh_Quadrangle's
844 ## Private constructor.
845 def __init__(self, mesh, geom=0):
846 if not Mesh_Quadrangle.algo:
847 Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
849 self.Assign( Mesh_Quadrangle.algo, mesh, geom)
852 ## Define "QuadranglePreference" hypothesis, forcing construction
853 # of quadrangles if the number of nodes on opposite edges is not the same
854 # in the case where the global number of nodes on edges is even
855 def QuadranglePreference(self):
856 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
859 # Public class: Mesh_Tetrahedron
860 # ------------------------------
862 ## Class to define a tetrahedron 3D algorithm
865 class Mesh_Tetrahedron(Mesh_Algorithm):
870 algoNET = 0 # algorithm object common for all Mesh_Tetrahedron's
871 algoGHS = 0 # algorithm object common for all Mesh_Tetrahedron's
872 algoFNET = 0 # algorithm object common for all Mesh_Tetrahedron's
874 ## Private constructor.
875 def __init__(self, mesh, algoType, geom=0):
876 if algoType == NETGEN:
877 if not Mesh_Tetrahedron.algoNET:
878 Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
880 self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
884 elif algoType == GHS3D:
885 if not Mesh_Tetrahedron.algoGHS:
887 Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
889 self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
893 elif algoType == FULL_NETGEN:
895 print "Warning: NETGENPlugin module has not been imported."
896 if not Mesh_Tetrahedron.algoFNET:
897 Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
899 self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
903 self.algoType = algoType
905 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
906 # @param vol for the maximum volume of each tetrahedral
907 # @param UseExisting if ==true - search existing hypothesis created with
908 # same parameters, else (default) - create new
909 def MaxElementVolume(self, vol, UseExisting=0):
910 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
911 hyp.SetMaxElementVolume(vol)
914 ## Define "Netgen 3D Parameters" hypothesis
915 def Parameters(self):
916 if (self.algoType == FULL_NETGEN):
917 self.params = self.Hypothesis("NETGEN_Parameters", [],
918 "libNETGENEngine.so", UseExisting=0)
921 print "Algo doesn't support this hypothesis"
925 def SetMaxSize(self, theSize):
928 self.params.SetMaxSize(theSize)
930 ## Set SecondOrder flag
931 def SetSecondOrder(self, theVal):
934 self.params.SetSecondOrder(theVal)
937 def SetOptimize(self, theVal):
940 self.params.SetOptimize(theVal)
943 # @param theFineness is:
944 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
945 def SetFineness(self, theFineness):
948 self.params.SetFineness(theFineness)
951 def SetGrowthRate(self, theRate):
954 self.params.SetGrowthRate(theRate)
957 def SetNbSegPerEdge(self, theVal):
960 self.params.SetNbSegPerEdge(theVal)
962 ## Set NbSegPerRadius
963 def SetNbSegPerRadius(self, theVal):
966 self.params.SetNbSegPerRadius(theVal)
968 # Public class: Mesh_Hexahedron
969 # ------------------------------
971 ## Class to define a hexahedron 3D algorithm
974 class Mesh_Hexahedron(Mesh_Algorithm):
976 algo = 0 # algorithm object common for all Mesh_Hexahedron's
978 ## Private constructor.
979 def __init__(self, mesh, geom=0):
980 if not Mesh_Hexahedron.algo:
981 Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
983 self.Assign( Mesh_Hexahedron.algo, mesh, geom)
986 # Deprecated, only for compatibility!
987 # Public class: Mesh_Netgen
988 # ------------------------------
990 ## Class to define a NETGEN-based 2D or 3D algorithm
991 # that need no discrete boundary (i.e. independent)
993 # This class is deprecated, only for compatibility!
996 class Mesh_Netgen(Mesh_Algorithm):
1000 algoNET23 = 0 # algorithm object common for all Mesh_Netgen's
1001 algoNET2 = 0 # algorithm object common for all Mesh_Netgen's
1003 ## Private constructor.
1004 def __init__(self, mesh, is3D, geom=0):
1006 print "Warning: NETGENPlugin module has not been imported."
1010 if not Mesh_Netgen.algoNET23:
1011 Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1013 self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1018 if not Mesh_Netgen.algoNET2:
1019 Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1021 self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1025 ## Define hypothesis containing parameters of the algorithm
1026 def Parameters(self):
1028 hyp = self.Hypothesis("NETGEN_Parameters", [],
1029 "libNETGENEngine.so", UseExisting=0)
1031 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1032 "libNETGENEngine.so", UseExisting=0)
1035 # Public class: Mesh_Projection1D
1036 # ------------------------------
1038 ## Class to define a projection 1D algorithm
1041 class Mesh_Projection1D(Mesh_Algorithm):
1043 algo = 0 # algorithm object common for all Mesh_Projection1D's
1045 ## Private constructor.
1046 def __init__(self, mesh, geom=0):
1047 if not Mesh_Projection1D.algo:
1048 Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1050 self.Assign( Mesh_Projection1D.algo, mesh, geom)
1053 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1054 # take a mesh pattern from, and optionally association of vertices
1055 # between the source edge and a target one (where a hipothesis is assigned to)
1056 # @param edge to take nodes distribution from
1057 # @param mesh to take nodes distribution from (optional)
1058 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1059 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1060 # to associate with \a srcV (optional)
1061 # @param UseExisting if ==true - search existing hypothesis created with
1062 # same parameters, else (default) - create new
1063 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1064 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1065 hyp.SetSourceEdge( edge )
1066 if not mesh is None and isinstance(mesh, Mesh):
1067 mesh = mesh.GetMesh()
1068 hyp.SetSourceMesh( mesh )
1069 hyp.SetVertexAssociation( srcV, tgtV )
1073 # Public class: Mesh_Projection2D
1074 # ------------------------------
1076 ## Class to define a projection 2D algorithm
1079 class Mesh_Projection2D(Mesh_Algorithm):
1081 algo = 0 # algorithm object common for all Mesh_Projection2D's
1083 ## Private constructor.
1084 def __init__(self, mesh, geom=0):
1085 if not Mesh_Projection2D.algo:
1086 Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1088 self.Assign( Mesh_Projection2D.algo, mesh, geom)
1091 ## Define "Source Face" hypothesis, specifying a meshed face to
1092 # take a mesh pattern from, and optionally association of vertices
1093 # between the source face and a target one (where a hipothesis is assigned to)
1094 # @param face to take mesh pattern from
1095 # @param mesh to take mesh pattern from (optional)
1096 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1097 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1098 # to associate with \a srcV1 (optional)
1099 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1100 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1101 # to associate with \a srcV2 (optional)
1102 # @param UseExisting if ==true - search existing hypothesis created with
1103 # same parameters, else (default) - create new
1105 # Note: association vertices must belong to one edge of a face
1106 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1107 srcV2=None, tgtV2=None, UseExisting=0):
1108 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1109 UseExisting=UseExisting)
1110 hyp.SetSourceFace( face )
1111 if not mesh is None and isinstance(mesh, Mesh):
1112 mesh = mesh.GetMesh()
1113 hyp.SetSourceMesh( mesh )
1114 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1117 # Public class: Mesh_Projection3D
1118 # ------------------------------
1120 ## Class to define a projection 3D algorithm
1123 class Mesh_Projection3D(Mesh_Algorithm):
1125 algo = 0 # algorithm object common for all Mesh_Projection3D's
1127 ## Private constructor.
1128 def __init__(self, mesh, geom=0):
1129 if not Mesh_Projection3D.algo:
1130 Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1132 self.Assign( Mesh_Projection3D.algo, mesh, geom)
1135 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1136 # take a mesh pattern from, and optionally association of vertices
1137 # between the source solid and a target one (where a hipothesis is assigned to)
1138 # @param solid to take mesh pattern from
1139 # @param mesh to take mesh pattern from (optional)
1140 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1141 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1142 # to associate with \a srcV1 (optional)
1143 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1144 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1145 # to associate with \a srcV2 (optional)
1146 # @param UseExisting - if ==true - search existing hypothesis created with
1147 # same parameters, else (default) - create new
1149 # Note: association vertices must belong to one edge of a solid
1150 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1151 srcV2=0, tgtV2=0, UseExisting=0):
1152 hyp = self.Hypothesis("ProjectionSource3D",
1153 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1154 UseExisting=UseExisting)
1155 hyp.SetSource3DShape( solid )
1156 if not mesh is None and isinstance(mesh, Mesh):
1157 mesh = mesh.GetMesh()
1158 hyp.SetSourceMesh( mesh )
1159 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1163 # Public class: Mesh_Prism
1164 # ------------------------
1166 ## Class to define a 3D extrusion algorithm
1169 class Mesh_Prism3D(Mesh_Algorithm):
1171 algo = 0 # algorithm object common for all Mesh_Prism3D's
1173 ## Private constructor.
1174 def __init__(self, mesh, geom=0):
1175 if not Mesh_Prism3D.algo:
1176 Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1178 self.Assign( Mesh_Prism3D.algo, mesh, geom)
1181 # Public class: Mesh_RadialPrism
1182 # -------------------------------
1184 ## Class to define a Radial Prism 3D algorithm
1187 class Mesh_RadialPrism3D(Mesh_Algorithm):
1189 algo = 0 # algorithm object common for all Mesh_RadialPrism3D's
1191 ## Private constructor.
1192 def __init__(self, mesh, geom=0):
1193 if not Mesh_RadialPrism3D.algo:
1194 Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1196 self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1198 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1199 self.nbLayers = None
1201 ## Return 3D hypothesis holding the 1D one
1202 def Get3DHypothesis(self):
1203 return self.distribHyp
1205 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1206 # hypothes. Returns the created hypothes
1207 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1208 if not self.nbLayers is None:
1209 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1210 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1211 study = GetCurrentStudy() # prevent publishing of own 1D hypothesis
1212 hyp = smesh.CreateHypothesis(hypType, so)
1213 SetCurrentStudy( study ) # anable publishing
1214 self.distribHyp.SetLayerDistribution( hyp )
1217 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1218 # prisms to build between the inner and outer shells
1219 # @param UseExisting if ==true - search existing hypothesis created with
1220 # same parameters, else (default) - create new
1221 def NumberOfLayers(self, n, UseExisting=0):
1222 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1223 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1224 self.nbLayers.SetNumberOfLayers( n )
1225 return self.nbLayers
1227 ## Define "LocalLength" hypothesis, specifying segment length
1228 # to build between the inner and outer shells
1229 # @param l for the length of segments
1230 def LocalLength(self, l):
1231 hyp = self.OwnHypothesis("LocalLength", [l] )
1235 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1236 # prisms to build between the inner and outer shells
1237 # @param n for the number of segments
1238 # @param s for the scale factor (optional)
1239 def NumberOfSegments(self, n, s=[]):
1241 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1243 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1244 hyp.SetDistrType( 1 )
1245 hyp.SetScaleFactor(s)
1246 hyp.SetNumberOfSegments(n)
1249 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1250 # to build between the inner and outer shells as arithmetic length increasing
1251 # @param start for the length of the first segment
1252 # @param end for the length of the last segment
1253 def Arithmetic1D(self, start, end ):
1254 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1255 hyp.SetLength(start, 1)
1256 hyp.SetLength(end , 0)
1259 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1260 # to build between the inner and outer shells as geometric length increasing
1261 # @param start for the length of the first segment
1262 # @param end for the length of the last segment
1263 def StartEndLength(self, start, end):
1264 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1265 hyp.SetLength(start, 1)
1266 hyp.SetLength(end , 0)
1269 ## Define "AutomaticLength" hypothesis, specifying number of segments
1270 # to build between the inner and outer shells
1271 # @param fineness for the fineness [0-1]
1272 def AutomaticLength(self, fineness=0):
1273 hyp = self.OwnHypothesis("AutomaticLength")
1274 hyp.SetFineness( fineness )
1278 # Public class: Mesh
1279 # ==================
1281 ## Class to define a mesh
1283 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1293 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1294 # sets GUI name of this mesh to \a name.
1295 # @param obj Shape to be meshed or SMESH_Mesh object
1296 # @param name Study name of the mesh
1297 def __init__(self, obj=0, name=0):
1301 if isinstance(obj, geompy.GEOM._objref_GEOM_Object):
1303 self.mesh = smesh.CreateMesh(self.geom)
1304 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1307 self.mesh = smesh.CreateEmptyMesh()
1309 SetName(self.mesh, name)
1311 SetName(self.mesh, GetName(obj))
1313 self.editor = self.mesh.GetMeshEditor()
1315 ## Method that inits the Mesh object from SMESH_Mesh interface
1316 # @param theMesh is SMESH_Mesh object
1317 def SetMesh(self, theMesh):
1319 self.geom = self.mesh.GetShapeToMesh()
1321 ## Method that returns the mesh
1322 # @return SMESH_Mesh object
1328 name = GetName(self.GetMesh())
1332 def SetName(self, name):
1333 SetName(self.GetMesh(), name)
1335 ## Get the subMesh object associated to a subShape. The subMesh object
1336 # gives access to nodes and elements IDs.
1337 # \n SubMesh will be used instead of SubShape in a next idl version to
1338 # adress a specific subMesh...
1339 def GetSubMesh(self, theSubObject, name):
1340 submesh = self.mesh.GetSubMesh(theSubObject, name)
1343 ## Method that returns the shape associated to the mesh
1344 # @return GEOM_Object
1348 ## Method that associates given shape to the mesh(entails the mesh recreation)
1349 # @param geom shape to be meshed(GEOM_Object)
1350 def SetShape(self, geom):
1351 self.mesh = smesh.CreateMesh(geom)
1353 ## Return true if hypotheses are defined well
1354 # @param theMesh is an instance of Mesh class
1355 # @param theSubObject subshape of a mesh shape
1356 def IsReadyToCompute(self, theSubObject):
1357 return smesh.IsReadyToCompute(self.mesh, theSubObject)
1359 ## Return errors of hypotheses definintion
1360 # error list is empty if everything is OK
1361 # @param theMesh is an instance of Mesh class
1362 # @param theSubObject subshape of a mesh shape
1363 # @return a list of errors
1364 def GetAlgoState(self, theSubObject):
1365 return smesh.GetAlgoState(self.mesh, theSubObject)
1367 ## Return geometrical object the given element is built on.
1368 # The returned geometrical object, if not nil, is either found in the
1369 # study or is published by this method with the given name
1370 # @param theMesh is an instance of Mesh class
1371 # @param theElementID an id of the mesh element
1372 # @param theGeomName user defined name of geometrical object
1373 # @return GEOM::GEOM_Object instance
1374 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1375 return smesh.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1377 ## Returns mesh dimension depending on shape one
1378 def MeshDimension(self):
1379 shells = geompy.SubShapeAllIDs( self.geom, geompy.ShapeType["SHELL"] )
1380 if len( shells ) > 0 :
1382 elif geompy.NumberOfFaces( self.geom ) > 0 :
1384 elif geompy.NumberOfEdges( self.geom ) > 0 :
1390 ## Creates a segment discretization 1D algorithm.
1391 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1392 # If the optional \a geom parameter is not sets, this algorithm is global.
1393 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1394 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1395 # @param geom If defined, subshape to be meshed
1396 def Segment(self, algo=REGULAR, geom=0):
1397 ## if Segment(geom) is called by mistake
1398 if isinstance( algo, geompy.GEOM._objref_GEOM_Object):
1399 algo, geom = geom, algo
1400 if not algo: algo = REGULAR
1403 return Mesh_Segment(self, geom)
1404 elif algo == PYTHON:
1405 return Mesh_Segment_Python(self, geom)
1406 elif algo == COMPOSITE:
1407 return Mesh_CompositeSegment(self, geom)
1409 return Mesh_Segment(self, geom)
1411 ## Creates a triangle 2D algorithm for faces.
1412 # If the optional \a geom parameter is not sets, this algorithm is global.
1413 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1414 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1415 # @param geom If defined, subshape to be meshed
1416 def Triangle(self, algo=MEFISTO, geom=0):
1417 ## if Triangle(geom) is called by mistake
1418 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1422 return Mesh_Triangle(self, algo, geom)
1424 ## Creates a quadrangle 2D algorithm for faces.
1425 # If the optional \a geom parameter is not sets, this algorithm is global.
1426 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1427 # @param geom If defined, subshape to be meshed
1428 def Quadrangle(self, geom=0):
1429 return Mesh_Quadrangle(self, geom)
1431 ## Creates a tetrahedron 3D algorithm for solids.
1432 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
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 algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1436 # @param geom If defined, subshape to be meshed
1437 def Tetrahedron(self, algo=NETGEN, geom=0):
1438 ## if Tetrahedron(geom) is called by mistake
1439 if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)):
1440 algo, geom = geom, algo
1441 if not algo: algo = NETGEN
1443 return Mesh_Tetrahedron(self, algo, geom)
1445 ## Creates a hexahedron 3D algorithm for solids.
1446 # If the optional \a geom parameter is not sets, this algorithm is global.
1447 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1448 # @param geom If defined, subshape to be meshed
1449 def Hexahedron(self, geom=0):
1450 return Mesh_Hexahedron(self, geom)
1452 ## Deprecated, only for compatibility!
1453 def Netgen(self, is3D, geom=0):
1454 return Mesh_Netgen(self, is3D, geom)
1456 ## Creates a projection 1D algorithm for edges.
1457 # If the optional \a geom parameter is not sets, this algorithm is global.
1458 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1459 # @param geom If defined, subshape to be meshed
1460 def Projection1D(self, geom=0):
1461 return Mesh_Projection1D(self, geom)
1463 ## Creates a projection 2D algorithm for faces.
1464 # If the optional \a geom parameter is not sets, this algorithm is global.
1465 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1466 # @param geom If defined, subshape to be meshed
1467 def Projection2D(self, geom=0):
1468 return Mesh_Projection2D(self, geom)
1470 ## Creates a projection 3D algorithm for solids.
1471 # If the optional \a geom parameter is not sets, this algorithm is global.
1472 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1473 # @param geom If defined, subshape to be meshed
1474 def Projection3D(self, geom=0):
1475 return Mesh_Projection3D(self, geom)
1477 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1478 # If the optional \a geom parameter is not sets, this algorithm is global.
1479 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1480 # @param geom If defined, subshape to be meshed
1481 def Prism(self, geom=0):
1485 nbSolids = len( geompy.SubShapeAll( shape, geompy.ShapeType["SOLID"] ))
1486 nbShells = len( geompy.SubShapeAll( shape, geompy.ShapeType["SHELL"] ))
1487 if nbSolids == 0 or nbSolids == nbShells:
1488 return Mesh_Prism3D(self, geom)
1489 return Mesh_RadialPrism3D(self, geom)
1491 ## Compute the mesh and return the status of the computation
1492 def Compute(self, geom=0):
1493 if geom == 0 or not isinstance(geom, geompy.GEOM._objref_GEOM_Object):
1495 print "Compute impossible: mesh is not constructed on geom shape."
1501 ok = smesh.Compute(self.mesh, geom)
1502 except SALOME.SALOME_Exception, ex:
1503 print "Mesh computation failed, exception cought:"
1504 print " ", ex.details.text
1507 print "Mesh computation failed, exception cought:"
1508 traceback.print_exc()
1510 errors = smesh.GetAlgoState( self.mesh, geom )
1513 if err.isGlobalAlgo:
1518 dim = str(err.algoDim)
1519 if err.name == MISSING_ALGO:
1520 reason = glob + dim + "D algorithm is missing"
1521 elif err.name == MISSING_HYPO:
1522 name = '"' + err.algoName + '"'
1523 reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis"
1524 elif err.name == NOT_CONFORM_MESH:
1525 reason = "Global \"Not Conform mesh allowed\" hypothesis is missing"
1526 elif err.name == BAD_PARAM_VALUE:
1527 name = '"' + err.algoName + '"'
1528 reason = "Hypothesis of" + glob + dim + "D algorithm " + name +\
1529 " has a bad parameter value"
1531 reason = "For unknown reason."+\
1532 " Revise Mesh.Compute() implementation in smesh.py!"
1534 if allReasons != "":
1537 allReasons += reason
1539 if allReasons != "":
1540 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1543 print '"' + GetName(self.mesh) + '"',"has not been computed."
1546 if salome.sg.hasDesktop():
1547 smeshgui = salome.ImportComponentGUI("SMESH")
1548 smeshgui.Init(salome.myStudyId)
1549 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1550 salome.sg.updateObjBrowser(1)
1554 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1555 # The parameter \a fineness [0,-1] defines mesh fineness
1556 def AutomaticTetrahedralization(self, fineness=0):
1557 dim = self.MeshDimension()
1559 self.RemoveGlobalHypotheses()
1560 self.Segment().AutomaticLength(fineness)
1562 self.Triangle().LengthFromEdges()
1565 self.Tetrahedron(NETGEN)
1567 return self.Compute()
1569 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1570 # The parameter \a fineness [0,-1] defines mesh fineness
1571 def AutomaticHexahedralization(self, fineness=0):
1572 dim = self.MeshDimension()
1574 self.RemoveGlobalHypotheses()
1575 self.Segment().AutomaticLength(fineness)
1582 return self.Compute()
1584 ## Assign hypothesis
1585 # @param hyp is a hypothesis to assign
1586 # @param geom is subhape of mesh geometry
1587 def AddHypothesis(self, hyp, geom=0 ):
1588 if isinstance( hyp, Mesh_Algorithm ):
1589 hyp = hyp.GetAlgorithm()
1594 status = self.mesh.AddHypothesis(geom, hyp)
1595 isAlgo = hyp._narrow( SMESH.SMESH_Algo )
1596 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1599 ## Unassign hypothesis
1600 # @param hyp is a hypothesis to unassign
1601 # @param geom is subhape of mesh geometry
1602 def RemoveHypothesis(self, hyp, geom=0 ):
1603 if isinstance( hyp, Mesh_Algorithm ):
1604 hyp = hyp.GetAlgorithm()
1609 status = self.mesh.RemoveHypothesis(geom, hyp)
1612 ## Get the list of hypothesis added on a geom
1613 # @param geom is subhape of mesh geometry
1614 def GetHypothesisList(self, geom):
1615 return self.mesh.GetHypothesisList( geom )
1617 ## Removes all global hypotheses
1618 def RemoveGlobalHypotheses(self):
1619 current_hyps = self.mesh.GetHypothesisList( self.geom )
1620 for hyp in current_hyps:
1621 self.mesh.RemoveHypothesis( self.geom, hyp )
1625 ## Create a mesh group based on geometric object \a grp
1626 # and give a \a name, \n if this parameter is not defined
1627 # the name is the same as the geometric group name \n
1628 # Note: Works like GroupOnGeom().
1629 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1630 # @param name is the name of the mesh group
1631 # @return SMESH_GroupOnGeom
1632 def Group(self, grp, name=""):
1633 return self.GroupOnGeom(grp, name)
1635 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1636 # Export the mesh in a file with the MED format and choice the \a version of MED format
1637 # @param f is the file name
1638 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1639 def ExportToMED(self, f, version, opt=0):
1640 self.mesh.ExportToMED(f, opt, version)
1642 ## Export the mesh in a file with the MED format
1643 # @param f is the file name
1644 # @param auto_groups boolean parameter for creating/not creating
1645 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1646 # the typical use is auto_groups=false.
1647 # @param version MED format version(MED_V2_1 or MED_V2_2)
1648 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1649 self.mesh.ExportToMED(f, auto_groups, version)
1651 ## Export the mesh in a file with the DAT format
1652 # @param f is the file name
1653 def ExportDAT(self, f):
1654 self.mesh.ExportDAT(f)
1656 ## Export the mesh in a file with the UNV format
1657 # @param f is the file name
1658 def ExportUNV(self, f):
1659 self.mesh.ExportUNV(f)
1661 ## Export the mesh in a file with the STL format
1662 # @param f is the file name
1663 # @param ascii defined the kind of file contents
1664 def ExportSTL(self, f, ascii=1):
1665 self.mesh.ExportSTL(f, ascii)
1668 # Operations with groups:
1669 # ----------------------
1671 ## Creates an empty mesh group
1672 # @param elementType is the type of elements in the group
1673 # @param name is the name of the mesh group
1674 # @return SMESH_Group
1675 def CreateEmptyGroup(self, elementType, name):
1676 return self.mesh.CreateGroup(elementType, name)
1678 ## Creates a mesh group based on geometric object \a grp
1679 # and give a \a name, \n if this parameter is not defined
1680 # the name is the same as the geometric group name
1681 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1682 # @param name is the name of the mesh group
1683 # @return SMESH_GroupOnGeom
1684 def GroupOnGeom(self, grp, name="", type=None):
1686 name = grp.GetName()
1689 tgeo = str(grp.GetShapeType())
1690 if tgeo == "VERTEX":
1692 elif tgeo == "EDGE":
1694 elif tgeo == "FACE":
1696 elif tgeo == "SOLID":
1698 elif tgeo == "SHELL":
1700 elif tgeo == "COMPOUND":
1701 if len( geompy.GetObjectIDs( grp )) == 0:
1702 print "Mesh.Group: empty geometric group", GetName( grp )
1704 tgeo = geompy.GetType(grp)
1705 if tgeo == geompy.ShapeType["VERTEX"]:
1707 elif tgeo == geompy.ShapeType["EDGE"]:
1709 elif tgeo == geompy.ShapeType["FACE"]:
1711 elif tgeo == geompy.ShapeType["SOLID"]:
1715 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1718 return self.mesh.CreateGroupFromGEOM(type, name, grp)
1720 ## Create a mesh group by the given ids of elements
1721 # @param groupName is the name of the mesh group
1722 # @param elementType is the type of elements in the group
1723 # @param elemIDs is the list of ids
1724 # @return SMESH_Group
1725 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1726 group = self.mesh.CreateGroup(elementType, groupName)
1730 ## Create a mesh group by the given conditions
1731 # @param groupName is the name of the mesh group
1732 # @param elementType is the type of elements in the group
1733 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1734 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1735 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1736 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1737 # @return SMESH_Group
1741 CritType=FT_Undefined,
1744 UnaryOp=FT_Undefined):
1745 aCriterion = GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1746 group = self.MakeGroupByCriterion(groupName, aCriterion)
1749 ## Create a mesh group by the given criterion
1750 # @param groupName is the name of the mesh group
1751 # @param Criterion is the instance of Criterion class
1752 # @return SMESH_Group
1753 def MakeGroupByCriterion(self, groupName, Criterion):
1754 aFilterMgr = smesh.CreateFilterManager()
1755 aFilter = aFilterMgr.CreateFilter()
1757 aCriteria.append(Criterion)
1758 aFilter.SetCriteria(aCriteria)
1759 group = self.MakeGroupByFilter(groupName, aFilter)
1762 ## Create a mesh group by the given criteria(list of criterions)
1763 # @param groupName is the name of the mesh group
1764 # @param Criteria is the list of criterions
1765 # @return SMESH_Group
1766 def MakeGroupByCriteria(self, groupName, theCriteria):
1767 aFilterMgr = smesh.CreateFilterManager()
1768 aFilter = aFilterMgr.CreateFilter()
1769 aFilter.SetCriteria(theCriteria)
1770 group = self.MakeGroupByFilter(groupName, aFilter)
1773 ## Create a mesh group by the given filter
1774 # @param groupName is the name of the mesh group
1775 # @param Criterion is the instance of Filter class
1776 # @return SMESH_Group
1777 def MakeGroupByFilter(self, groupName, theFilter):
1778 anIds = theFilter.GetElementsId(self.mesh)
1779 anElemType = theFilter.GetElementType()
1780 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1783 ## Pass mesh elements through the given filter and return ids
1784 # @param theFilter is SMESH_Filter
1785 # @return list of ids
1786 def GetIdsFromFilter(self, theFilter):
1787 return theFilter.GetElementsId(self.mesh)
1789 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1790 # Returns list of special structures(borders).
1791 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1792 def GetFreeBorders(self):
1793 aFilterMgr = smesh.CreateFilterManager()
1794 aPredicate = aFilterMgr.CreateFreeEdges()
1795 aPredicate.SetMesh(self.mesh)
1796 aBorders = aPredicate.GetBorders()
1800 def RemoveGroup(self, group):
1801 self.mesh.RemoveGroup(group)
1803 ## Remove group with its contents
1804 def RemoveGroupWithContents(self, group):
1805 self.mesh.RemoveGroupWithContents(group)
1807 ## Get the list of groups existing in the mesh
1808 def GetGroups(self):
1809 return self.mesh.GetGroups()
1811 ## Get the list of names of groups existing in the mesh
1812 def GetGroupNames(self):
1813 groups = self.GetGroups()
1815 for group in groups:
1816 names.append(group.GetName())
1819 ## Union of two groups
1820 # New group is created. All mesh elements that are
1821 # present in initial groups are added to the new one
1822 def UnionGroups(self, group1, group2, name):
1823 return self.mesh.UnionGroups(group1, group2, name)
1825 ## Intersection of two groups
1826 # New group is created. All mesh elements that are
1827 # present in both initial groups are added to the new one.
1828 def IntersectGroups(self, group1, group2, name):
1829 return self.mesh.IntersectGroups(group1, group2, name)
1831 ## Cut of two groups
1832 # New group is created. All mesh elements that are present in
1833 # main group but do not present in tool group are added to the new one
1834 def CutGroups(self, mainGroup, toolGroup, name):
1835 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1838 # Get some info about mesh:
1839 # ------------------------
1841 ## Get the log of nodes and elements added or removed since previous
1843 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1844 # @return list of log_block structures:
1849 def GetLog(self, clearAfterGet):
1850 return self.mesh.GetLog(clearAfterGet)
1852 ## Clear the log of nodes and elements added or removed since previous
1853 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1855 self.mesh.ClearLog()
1857 ## Get the internal Id
1859 return self.mesh.GetId()
1862 def GetStudyId(self):
1863 return self.mesh.GetStudyId()
1865 ## Check group names for duplications.
1866 # Consider maximum group name length stored in MED file.
1867 def HasDuplicatedGroupNamesMED(self):
1868 return self.mesh.HasDuplicatedGroupNamesMED()
1870 ## Obtain instance of SMESH_MeshEditor
1871 def GetMeshEditor(self):
1872 return self.mesh.GetMeshEditor()
1875 def GetMEDMesh(self):
1876 return self.mesh.GetMEDMesh()
1879 # Get informations about mesh contents:
1880 # ------------------------------------
1882 ## Returns number of nodes in mesh
1884 return self.mesh.NbNodes()
1886 ## Returns number of elements in mesh
1887 def NbElements(self):
1888 return self.mesh.NbElements()
1890 ## Returns number of edges in mesh
1892 return self.mesh.NbEdges()
1894 ## Returns number of edges with given order in mesh
1895 # @param elementOrder is order of elements:
1896 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1897 def NbEdgesOfOrder(self, elementOrder):
1898 return self.mesh.NbEdgesOfOrder(elementOrder)
1900 ## Returns number of faces in mesh
1902 return self.mesh.NbFaces()
1904 ## Returns number of faces with given order in mesh
1905 # @param elementOrder is order of elements:
1906 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1907 def NbFacesOfOrder(self, elementOrder):
1908 return self.mesh.NbFacesOfOrder(elementOrder)
1910 ## Returns number of triangles in mesh
1911 def NbTriangles(self):
1912 return self.mesh.NbTriangles()
1914 ## Returns number of triangles with given order in mesh
1915 # @param elementOrder is order of elements:
1916 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1917 def NbTrianglesOfOrder(self, elementOrder):
1918 return self.mesh.NbTrianglesOfOrder(elementOrder)
1920 ## Returns number of quadrangles in mesh
1921 def NbQuadrangles(self):
1922 return self.mesh.NbQuadrangles()
1924 ## Returns number of quadrangles with given order in mesh
1925 # @param elementOrder is order of elements:
1926 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1927 def NbQuadranglesOfOrder(self, elementOrder):
1928 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1930 ## Returns number of polygons in mesh
1931 def NbPolygons(self):
1932 return self.mesh.NbPolygons()
1934 ## Returns number of volumes in mesh
1935 def NbVolumes(self):
1936 return self.mesh.NbVolumes()
1938 ## Returns number of volumes with given order in mesh
1939 # @param elementOrder is order of elements:
1940 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1941 def NbVolumesOfOrder(self, elementOrder):
1942 return self.mesh.NbVolumesOfOrder(elementOrder)
1944 ## Returns number of tetrahedrons in mesh
1946 return self.mesh.NbTetras()
1948 ## Returns number of tetrahedrons with given order in mesh
1949 # @param elementOrder is order of elements:
1950 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1951 def NbTetrasOfOrder(self, elementOrder):
1952 return self.mesh.NbTetrasOfOrder(elementOrder)
1954 ## Returns number of hexahedrons in mesh
1956 return self.mesh.NbHexas()
1958 ## Returns number of hexahedrons with given order in mesh
1959 # @param elementOrder is order of elements:
1960 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1961 def NbHexasOfOrder(self, elementOrder):
1962 return self.mesh.NbHexasOfOrder(elementOrder)
1964 ## Returns number of pyramids in mesh
1965 def NbPyramids(self):
1966 return self.mesh.NbPyramids()
1968 ## Returns number of pyramids with given order in mesh
1969 # @param elementOrder is order of elements:
1970 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1971 def NbPyramidsOfOrder(self, elementOrder):
1972 return self.mesh.NbPyramidsOfOrder(elementOrder)
1974 ## Returns number of prisms in mesh
1976 return self.mesh.NbPrisms()
1978 ## Returns number of prisms with given order in mesh
1979 # @param elementOrder is order of elements:
1980 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1981 def NbPrismsOfOrder(self, elementOrder):
1982 return self.mesh.NbPrismsOfOrder(elementOrder)
1984 ## Returns number of polyhedrons in mesh
1985 def NbPolyhedrons(self):
1986 return self.mesh.NbPolyhedrons()
1988 ## Returns number of submeshes in mesh
1989 def NbSubMesh(self):
1990 return self.mesh.NbSubMesh()
1992 ## Returns list of mesh elements ids
1993 def GetElementsId(self):
1994 return self.mesh.GetElementsId()
1996 ## Returns list of ids of mesh elements with given type
1997 # @param elementType is required type of elements
1998 def GetElementsByType(self, elementType):
1999 return self.mesh.GetElementsByType(elementType)
2001 ## Returns list of mesh nodes ids
2002 def GetNodesId(self):
2003 return self.mesh.GetNodesId()
2005 # Get informations about mesh elements:
2006 # ------------------------------------
2008 ## Returns type of mesh element
2009 def GetElementType(self, id, iselem):
2010 return self.mesh.GetElementType(id, iselem)
2012 ## Returns list of submesh elements ids
2013 # @param shapeID is geom object(subshape) IOR
2014 def GetSubMeshElementsId(self, shapeID):
2015 return self.mesh.GetSubMeshElementsId(shapeID)
2017 ## Returns list of submesh nodes ids
2018 # @param shapeID is geom object(subshape) IOR
2019 def GetSubMeshNodesId(self, shapeID, all):
2020 return self.mesh.GetSubMeshNodesId(shapeID, all)
2022 ## Returns list of ids of submesh elements with given type
2023 # @param shapeID is geom object(subshape) IOR
2024 def GetSubMeshElementType(self, shapeID):
2025 return self.mesh.GetSubMeshElementType(shapeID)
2027 ## Get mesh description
2029 return self.mesh.Dump()
2032 # Get information about nodes and elements of mesh by its ids:
2033 # -----------------------------------------------------------
2035 ## Get XYZ coordinates of node as list of double
2036 # \n If there is not node for given ID - returns empty list
2037 def GetNodeXYZ(self, id):
2038 return self.mesh.GetNodeXYZ(id)
2040 ## For given node returns list of IDs of inverse elements
2041 # \n If there is not node for given ID - returns empty list
2042 def GetNodeInverseElements(self, id):
2043 return self.mesh.GetNodeInverseElements(id)
2045 ## If given element is node returns IDs of shape from position
2046 # \n If there is not node for given ID - returns -1
2047 def GetShapeID(self, id):
2048 return self.mesh.GetShapeID(id)
2050 ## For given element returns ID of result shape after
2051 # FindShape() from SMESH_MeshEditor
2052 # \n If there is not element for given ID - returns -1
2053 def GetShapeIDForElem(self,id):
2054 return self.mesh.GetShapeIDForElem(id)
2056 ## Returns number of nodes for given element
2057 # \n If there is not element for given ID - returns -1
2058 def GetElemNbNodes(self, id):
2059 return self.mesh.GetElemNbNodes(id)
2061 ## Returns ID of node by given index for given element
2062 # \n If there is not element for given ID - returns -1
2063 # \n If there is not node for given index - returns -2
2064 def GetElemNode(self, id, index):
2065 return self.mesh.GetElemNode(id, index)
2067 ## Returns IDs of nodes of given element
2068 def GetElemNodes(self, id):
2069 return self.mesh.GetElemNodes(id)
2071 ## Returns true if given node is medium node
2072 # in given quadratic element
2073 def IsMediumNode(self, elementID, nodeID):
2074 return self.mesh.IsMediumNode(elementID, nodeID)
2076 ## Returns true if given node is medium node
2077 # in one of quadratic elements
2078 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2079 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2081 ## Returns number of edges for given element
2082 def ElemNbEdges(self, id):
2083 return self.mesh.ElemNbEdges(id)
2085 ## Returns number of faces for given element
2086 def ElemNbFaces(self, id):
2087 return self.mesh.ElemNbFaces(id)
2089 ## Returns true if given element is polygon
2090 def IsPoly(self, id):
2091 return self.mesh.IsPoly(id)
2093 ## Returns true if given element is quadratic
2094 def IsQuadratic(self, id):
2095 return self.mesh.IsQuadratic(id)
2097 ## Returns XYZ coordinates of bary center for given element
2099 # \n If there is not element for given ID - returns empty list
2100 def BaryCenter(self, id):
2101 return self.mesh.BaryCenter(id)
2104 # Mesh edition (SMESH_MeshEditor functionality):
2105 # ---------------------------------------------
2107 ## Removes elements from mesh by ids
2108 # @param IDsOfElements is list of ids of elements to remove
2109 def RemoveElements(self, IDsOfElements):
2110 return self.editor.RemoveElements(IDsOfElements)
2112 ## Removes nodes from mesh by ids
2113 # @param IDsOfNodes is list of ids of nodes to remove
2114 def RemoveNodes(self, IDsOfNodes):
2115 return self.editor.RemoveNodes(IDsOfNodes)
2117 ## Add node to mesh by coordinates
2118 def AddNode(self, x, y, z):
2119 return self.editor.AddNode( x, y, z)
2122 ## Create edge both similar and quadratic (this is determed
2123 # by number of given nodes).
2124 # @param IdsOfNodes List of node IDs for creation of element.
2125 # Needed order of nodes in this list corresponds to description
2126 # of MED. \n This description is located by the following link:
2127 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2128 def AddEdge(self, IDsOfNodes):
2129 return self.editor.AddEdge(IDsOfNodes)
2131 ## Create face both similar and quadratic (this is determed
2132 # by number of given nodes).
2133 # @param IdsOfNodes List of node IDs for creation of element.
2134 # Needed order of nodes in this list corresponds to description
2135 # of MED. \n This description is located by the following link:
2136 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2137 def AddFace(self, IDsOfNodes):
2138 return self.editor.AddFace(IDsOfNodes)
2140 ## Add polygonal face to mesh by list of nodes ids
2141 def AddPolygonalFace(self, IdsOfNodes):
2142 return self.editor.AddPolygonalFace(IdsOfNodes)
2144 ## Create volume both similar and quadratic (this is determed
2145 # by number of given nodes).
2146 # @param IdsOfNodes List of node IDs for creation of element.
2147 # Needed order of nodes in this list corresponds to description
2148 # of MED. \n This description is located by the following link:
2149 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2150 def AddVolume(self, IDsOfNodes):
2151 return self.editor.AddVolume(IDsOfNodes)
2153 ## Create volume of many faces, giving nodes for each face.
2154 # @param IdsOfNodes List of node IDs for volume creation face by face.
2155 # @param Quantities List of integer values, Quantities[i]
2156 # gives quantity of nodes in face number i.
2157 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2158 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2160 ## Create volume of many faces, giving IDs of existing faces.
2161 # @param IdsOfFaces List of face IDs for volume creation.
2163 # Note: The created volume will refer only to nodes
2164 # of the given faces, not to the faces itself.
2165 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2166 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2168 ## Move node with given id
2169 # @param NodeID id of the node
2170 # @param x new X coordinate
2171 # @param y new Y coordinate
2172 # @param z new Z coordinate
2173 def MoveNode(self, NodeID, x, y, z):
2174 return self.editor.MoveNode(NodeID, x, y, z)
2176 ## Find a node closest to a point
2177 # @param x X coordinate of a point
2178 # @param y Y coordinate of a point
2179 # @param z Z coordinate of a point
2180 # @return id of a node
2181 def FindNodeClosestTo(self, x, y, z):
2182 preview = self.mesh.GetMeshEditPreviewer()
2183 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2185 ## Find a node closest to a point and move it to a point location
2186 # @param x X coordinate of a point
2187 # @param y Y coordinate of a point
2188 # @param z Z coordinate of a point
2189 # @return id of a moved node
2190 def MeshToPassThroughAPoint(self, x, y, z):
2191 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2193 ## Replace two neighbour triangles sharing Node1-Node2 link
2194 # with ones built on the same 4 nodes but having other common link.
2195 # @param NodeID1 first node id
2196 # @param NodeID2 second node id
2197 # @return false if proper faces not found
2198 def InverseDiag(self, NodeID1, NodeID2):
2199 return self.editor.InverseDiag(NodeID1, NodeID2)
2201 ## Replace two neighbour triangles sharing Node1-Node2 link
2202 # with a quadrangle built on the same 4 nodes.
2203 # @param NodeID1 first node id
2204 # @param NodeID2 second node id
2205 # @return false if proper faces not found
2206 def DeleteDiag(self, NodeID1, NodeID2):
2207 return self.editor.DeleteDiag(NodeID1, NodeID2)
2209 ## Reorient elements by ids
2210 # @param IDsOfElements if undefined reorient all mesh elements
2211 def Reorient(self, IDsOfElements=None):
2212 if IDsOfElements == None:
2213 IDsOfElements = self.GetElementsId()
2214 return self.editor.Reorient(IDsOfElements)
2216 ## Reorient all elements of the object
2217 # @param theObject is mesh, submesh or group
2218 def ReorientObject(self, theObject):
2219 return self.editor.ReorientObject(theObject)
2221 ## Fuse neighbour triangles into quadrangles.
2222 # @param IDsOfElements The triangles to be fused,
2223 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2224 # @param MaxAngle is a max angle between element normals at which fusion
2225 # is still performed; theMaxAngle is mesured in radians.
2226 # @return TRUE in case of success, FALSE otherwise.
2227 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2228 if IDsOfElements == []:
2229 IDsOfElements = self.GetElementsId()
2230 return self.editor.TriToQuad(IDsOfElements, GetFunctor(theCriterion), MaxAngle)
2232 ## Fuse neighbour triangles of the object into quadrangles
2233 # @param theObject is mesh, submesh or group
2234 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2235 # @param MaxAngle is a max angle between element normals at which fusion
2236 # is still performed; theMaxAngle is mesured in radians.
2237 # @return TRUE in case of success, FALSE otherwise.
2238 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2239 return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle)
2241 ## Split quadrangles into triangles.
2242 # @param IDsOfElements the faces to be splitted.
2243 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2244 # @param @return TRUE in case of success, FALSE otherwise.
2245 def QuadToTri (self, IDsOfElements, theCriterion):
2246 if IDsOfElements == []:
2247 IDsOfElements = self.GetElementsId()
2248 return self.editor.QuadToTri(IDsOfElements, GetFunctor(theCriterion))
2250 ## Split quadrangles into triangles.
2251 # @param theObject object to taking list of elements from, is mesh, submesh or group
2252 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2253 def QuadToTriObject (self, theObject, theCriterion):
2254 return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion))
2256 ## Split quadrangles into triangles.
2257 # @param theElems The faces to be splitted
2258 # @param the13Diag is used to choose a diagonal for splitting.
2259 # @return TRUE in case of success, FALSE otherwise.
2260 def SplitQuad (self, IDsOfElements, Diag13):
2261 if IDsOfElements == []:
2262 IDsOfElements = self.GetElementsId()
2263 return self.editor.SplitQuad(IDsOfElements, Diag13)
2265 ## Split quadrangles into triangles.
2266 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2267 def SplitQuadObject (self, theObject, Diag13):
2268 return self.editor.SplitQuadObject(theObject, Diag13)
2270 ## Find better splitting of the given quadrangle.
2271 # @param IDOfQuad ID of the quadrangle to be splitted.
2272 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2273 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2274 # diagonal is better, 0 if error occurs.
2275 def BestSplit (self, IDOfQuad, theCriterion):
2276 return self.editor.BestSplit(IDOfQuad, GetFunctor(theCriterion))
2278 ## Split quafrangle faces near triangular facets of volumes
2280 def SplitQuadsNearTriangularFacets(self):
2281 faces_array = self.GetElementsByType(SMESH.FACE)
2282 for face_id in faces_array:
2283 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2284 quad_nodes = self.mesh.GetElemNodes(face_id)
2285 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2286 isVolumeFound = False
2287 for node1_elem in node1_elems:
2288 if not isVolumeFound:
2289 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2290 nb_nodes = self.GetElemNbNodes(node1_elem)
2291 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2292 volume_elem = node1_elem
2293 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2294 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2295 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2296 isVolumeFound = True
2297 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2298 self.SplitQuad([face_id], False) # diagonal 2-4
2299 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2300 isVolumeFound = True
2301 self.SplitQuad([face_id], True) # diagonal 1-3
2302 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2303 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2304 isVolumeFound = True
2305 self.SplitQuad([face_id], True) # diagonal 1-3
2307 ## @brief Split hexahedrons into tetrahedrons.
2309 # Use pattern mapping functionality for splitting.
2310 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2311 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2312 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2313 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2314 # key-point will be mapped into <theNode001>-th node of each volume.
2315 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2316 # @return TRUE in case of success, FALSE otherwise.
2317 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2318 # Pattern: 5.---------.6
2323 # (0,0,1) 4.---------.7 * |
2330 # (0,0,0) 0.---------.3
2331 pattern_tetra = "!!! Nb of points: \n 8 \n\
2341 !!! Indices of points of 6 tetras: \n\
2349 pattern = GetPattern()
2350 isDone = pattern.LoadFromFile(pattern_tetra)
2352 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2355 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2356 isDone = pattern.MakeMesh(self.mesh, False, False)
2357 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2359 # split quafrangle faces near triangular facets of volumes
2360 self.SplitQuadsNearTriangularFacets()
2364 ## @brief Split hexahedrons into prisms.
2366 # Use pattern mapping functionality for splitting.
2367 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2368 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2369 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2370 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2371 # key-point will be mapped into <theNode001>-th node of each volume.
2372 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2373 # @param @return TRUE in case of success, FALSE otherwise.
2374 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2375 # Pattern: 5.---------.6
2380 # (0,0,1) 4.---------.7 |
2387 # (0,0,0) 0.---------.3
2388 pattern_prism = "!!! Nb of points: \n 8 \n\
2398 !!! Indices of points of 2 prisms: \n\
2402 pattern = GetPattern()
2403 isDone = pattern.LoadFromFile(pattern_prism)
2405 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2408 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2409 isDone = pattern.MakeMesh(self.mesh, False, False)
2410 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2412 # split quafrangle faces near triangular facets of volumes
2413 self.SplitQuadsNearTriangularFacets()
2418 # @param IDsOfElements list if ids of elements to smooth
2419 # @param IDsOfFixedNodes list of ids of fixed nodes.
2420 # Note that nodes built on edges and boundary nodes are always fixed.
2421 # @param MaxNbOfIterations maximum number of iterations
2422 # @param MaxAspectRatio varies in range [1.0, inf]
2423 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2424 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2425 MaxNbOfIterations, MaxAspectRatio, Method):
2426 if IDsOfElements == []:
2427 IDsOfElements = self.GetElementsId()
2428 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2429 MaxNbOfIterations, MaxAspectRatio, Method)
2431 ## Smooth elements belong to given object
2432 # @param theObject object to smooth
2433 # @param IDsOfFixedNodes list of ids of fixed nodes.
2434 # Note that nodes built on edges and boundary nodes are always fixed.
2435 # @param MaxNbOfIterations maximum number of iterations
2436 # @param MaxAspectRatio varies in range [1.0, inf]
2437 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2438 def SmoothObject(self, theObject, IDsOfFixedNodes,
2439 MaxNbOfIterations, MaxxAspectRatio, Method):
2440 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2441 MaxNbOfIterations, MaxxAspectRatio, Method)
2443 ## Parametric smooth the given elements
2444 # @param IDsOfElements list if ids of elements to smooth
2445 # @param IDsOfFixedNodes list of ids of fixed nodes.
2446 # Note that nodes built on edges and boundary nodes are always fixed.
2447 # @param MaxNbOfIterations maximum number of iterations
2448 # @param MaxAspectRatio varies in range [1.0, inf]
2449 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2450 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2451 MaxNbOfIterations, MaxAspectRatio, Method):
2452 if IDsOfElements == []:
2453 IDsOfElements = self.GetElementsId()
2454 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2455 MaxNbOfIterations, MaxAspectRatio, Method)
2457 ## Parametric smooth elements belong to given object
2458 # @param theObject object to smooth
2459 # @param IDsOfFixedNodes list of ids of fixed nodes.
2460 # Note that nodes built on edges and boundary nodes are always fixed.
2461 # @param MaxNbOfIterations maximum number of iterations
2462 # @param MaxAspectRatio varies in range [1.0, inf]
2463 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2464 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2465 MaxNbOfIterations, MaxAspectRatio, Method):
2466 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2467 MaxNbOfIterations, MaxAspectRatio, Method)
2469 ## Converts all mesh to quadratic one, deletes old elements, replacing
2470 # them with quadratic ones with the same id.
2471 def ConvertToQuadratic(self, theForce3d):
2472 self.editor.ConvertToQuadratic(theForce3d)
2474 ## Converts all mesh from quadratic to ordinary ones,
2475 # deletes old quadratic elements, \n replacing
2476 # them with ordinary mesh elements with the same id.
2477 def ConvertFromQuadratic(self):
2478 return self.editor.ConvertFromQuadratic()
2480 ## Renumber mesh nodes
2481 def RenumberNodes(self):
2482 self.editor.RenumberNodes()
2484 ## Renumber mesh elements
2485 def RenumberElements(self):
2486 self.editor.RenumberElements()
2488 ## Generate new elements by rotation of the elements around the axis
2489 # @param IDsOfElements list of ids of elements to sweep
2490 # @param Axix axis of rotation, AxisStruct or line(geom object)
2491 # @param AngleInRadians angle of Rotation
2492 # @param NbOfSteps number of steps
2493 # @param Tolerance tolerance
2494 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance):
2495 if IDsOfElements == []:
2496 IDsOfElements = self.GetElementsId()
2497 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2498 Axix = GetAxisStruct(Axix)
2499 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2501 ## Generate new elements by rotation of the elements of object around the axis
2502 # @param theObject object wich elements should be sweeped
2503 # @param Axix axis of rotation, AxisStruct or line(geom object)
2504 # @param AngleInRadians angle of Rotation
2505 # @param NbOfSteps number of steps
2506 # @param Tolerance tolerance
2507 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance):
2508 if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)):
2509 Axix = GetAxisStruct(Axix)
2510 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2512 ## Generate new elements by extrusion of the elements with given ids
2513 # @param IDsOfElements list of elements ids for extrusion
2514 # @param StepVector vector, defining the direction and value of extrusion
2515 # @param NbOfSteps the number of steps
2516 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps):
2517 if IDsOfElements == []:
2518 IDsOfElements = self.GetElementsId()
2519 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2520 StepVector = GetDirStruct(StepVector)
2521 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2523 ## Generate new elements by extrusion of the elements with given ids
2524 # @param IDsOfElements is ids of elements
2525 # @param StepVector vector, defining the direction and value of extrusion
2526 # @param NbOfSteps the number of steps
2527 # @param ExtrFlags set flags for performing extrusion
2528 # @param SewTolerance uses for comparing locations of nodes if flag
2529 # EXTRUSION_FLAG_SEW is set
2530 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance):
2531 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2532 StepVector = GetDirStruct(StepVector)
2533 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance)
2535 ## Generate new elements by extrusion of the elements belong to object
2536 # @param theObject object wich elements should be processed
2537 # @param StepVector vector, defining the direction and value of extrusion
2538 # @param NbOfSteps the number of steps
2539 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps):
2540 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2541 StepVector = GetDirStruct(StepVector)
2542 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2544 ## Generate new elements by extrusion of the elements belong to object
2545 # @param theObject object wich elements should be processed
2546 # @param StepVector vector, defining the direction and value of extrusion
2547 # @param NbOfSteps the number of steps
2548 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps):
2549 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2550 StepVector = GetDirStruct(StepVector)
2551 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2553 ## Generate new elements by extrusion of the elements belong to object
2554 # @param theObject object wich elements should be processed
2555 # @param StepVector vector, defining the direction and value of extrusion
2556 # @param NbOfSteps the number of steps
2557 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps):
2558 if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)):
2559 StepVector = GetDirStruct(StepVector)
2560 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2562 ## Generate new elements by extrusion of the given elements
2563 # A path of extrusion must be a meshed edge.
2564 # @param IDsOfElements is ids of elements
2565 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2566 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2567 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2568 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2569 # @param Angles list of angles
2570 # @param HasRefPoint allows to use base point
2571 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2572 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2573 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2574 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2575 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2576 if IDsOfElements == []:
2577 IDsOfElements = self.GetElementsId()
2578 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2579 RefPoint = GetPointStruct(RefPoint)
2581 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape, NodeStart,
2582 HasAngles, Angles, HasRefPoint, RefPoint)
2584 ## Generate new elements by extrusion of the elements belong to object
2585 # A path of extrusion must be a meshed edge.
2586 # @param IDsOfElements is ids of elements
2587 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2588 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2589 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2590 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2591 # @param Angles list of angles
2592 # @param HasRefPoint allows to use base point
2593 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2594 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2595 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2596 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2597 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation=False):
2598 if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)):
2599 RefPoint = GetPointStruct(RefPoint)
2600 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape, NodeStart,
2601 HasAngles, Angles, HasRefPoint, RefPoint, LinearVariation)
2603 ## Symmetrical copy of mesh elements
2604 # @param IDsOfElements list of elements ids
2605 # @param Mirror is AxisStruct or geom object(point, line, plane)
2606 # @param theMirrorType is POINT, AXIS or PLANE
2607 # If the Mirror is geom object this parameter is unnecessary
2608 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2609 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0):
2610 if IDsOfElements == []:
2611 IDsOfElements = self.GetElementsId()
2612 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2613 Mirror = GetAxisStruct(Mirror)
2614 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2616 ## Symmetrical copy of object
2617 # @param theObject mesh, submesh or group
2618 # @param Mirror is AxisStruct or geom object(point, line, plane)
2619 # @param theMirrorType is POINT, AXIS or PLANE
2620 # If the Mirror is geom object this parameter is unnecessary
2621 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2622 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0):
2623 if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)):
2624 Mirror = GetAxisStruct(Mirror)
2625 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2627 ## Translates the elements
2628 # @param IDsOfElements list of elements ids
2629 # @param Vector direction of translation(DirStruct or vector)
2630 # @param Copy allows to copy the translated elements
2631 def Translate(self, IDsOfElements, Vector, Copy):
2632 if IDsOfElements == []:
2633 IDsOfElements = self.GetElementsId()
2634 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2635 Vector = GetDirStruct(Vector)
2636 self.editor.Translate(IDsOfElements, Vector, Copy)
2638 ## Translates the object
2639 # @param theObject object to translate(mesh, submesh, or group)
2640 # @param Vector direction of translation(DirStruct or geom vector)
2641 # @param Copy allows to copy the translated elements
2642 def TranslateObject(self, theObject, Vector, Copy):
2643 if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)):
2644 Vector = GetDirStruct(Vector)
2645 self.editor.TranslateObject(theObject, Vector, Copy)
2647 ## Rotates the elements
2648 # @param IDsOfElements list of elements ids
2649 # @param Axis axis of rotation(AxisStruct or geom line)
2650 # @param AngleInRadians angle of rotation(in radians)
2651 # @param Copy allows to copy the rotated elements
2652 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy):
2653 if IDsOfElements == []:
2654 IDsOfElements = self.GetElementsId()
2655 if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)):
2656 Axis = GetAxisStruct(Axis)
2657 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2659 ## Rotates the object
2660 # @param theObject object to rotate(mesh, submesh, or group)
2661 # @param Axis axis of rotation(AxisStruct or geom line)
2662 # @param AngleInRadians angle of rotation(in radians)
2663 # @param Copy allows to copy the rotated elements
2664 def RotateObject (self, theObject, Axis, AngleInRadians, Copy):
2665 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2667 ## Find group of nodes close to each other within Tolerance.
2668 # @param Tolerance tolerance value
2669 # @param list of group of nodes
2670 def FindCoincidentNodes (self, Tolerance):
2671 return self.editor.FindCoincidentNodes(Tolerance)
2673 ## Find group of nodes close to each other within Tolerance.
2674 # @param Tolerance tolerance value
2675 # @param SubMeshOrGroup SubMesh or Group
2676 # @param list of group of nodes
2677 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2678 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2681 # @param list of group of nodes
2682 def MergeNodes (self, GroupsOfNodes):
2683 self.editor.MergeNodes(GroupsOfNodes)
2685 ## Find elements built on the same nodes.
2686 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2687 # @return a list of groups of equal elements
2688 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2689 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2691 ## Merge elements in each given group.
2692 # @param GroupsOfElementsID groups of elements for merging
2693 def MergeElements(self, GroupsOfElementsID):
2694 self.editor.MergeElements(GroupsOfElementsID)
2696 ## Remove all but one of elements built on the same nodes.
2697 def MergeEqualElements(self):
2698 self.editor.MergeEqualElements()
2701 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2702 FirstNodeID2, SecondNodeID2, LastNodeID2,
2703 CreatePolygons, CreatePolyedrs):
2704 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2705 FirstNodeID2, SecondNodeID2, LastNodeID2,
2706 CreatePolygons, CreatePolyedrs)
2708 ## Sew conform free borders
2709 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2710 FirstNodeID2, SecondNodeID2):
2711 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2712 FirstNodeID2, SecondNodeID2)
2714 ## Sew border to side
2715 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2716 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2717 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2718 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2720 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2721 # merged with nodes of elements of Side2.
2722 # Number of elements in theSide1 and in theSide2 must be
2723 # equal and they should have similar node connectivity.
2724 # The nodes to merge should belong to sides borders and
2725 # the first node should be linked to the second.
2726 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2727 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2728 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2729 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2730 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2731 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2733 ## Set new nodes for given element.
2734 # @param ide the element id
2735 # @param newIDs nodes ids
2736 # @return If number of nodes is not corresponded to type of element - returns false
2737 def ChangeElemNodes(self, ide, newIDs):
2738 return self.editor.ChangeElemNodes(ide, newIDs)
2740 ## If during last operation of MeshEditor some nodes were
2741 # created this method returns list of it's IDs, \n
2742 # if new nodes not created - returns empty list
2743 def GetLastCreatedNodes(self):
2744 return self.editor.GetLastCreatedNodes()
2746 ## If during last operation of MeshEditor some elements were
2747 # created this method returns list of it's IDs, \n
2748 # if new elements not creared - returns empty list
2749 def GetLastCreatedElems(self):
2750 return self.editor.GetLastCreatedElems()