1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Francis KLOSS, OCC
32 import SMESH # necessary for back compatibility
39 # import NETGENPlugin module if possible
58 NETGEN_1D2D3D = FULL_NETGEN
59 NETGEN_FULL = FULL_NETGEN
64 # MirrorType enumeration
65 POINT = SMESH_MeshEditor.POINT
66 AXIS = SMESH_MeshEditor.AXIS
67 PLANE = SMESH_MeshEditor.PLANE
69 # Smooth_Method enumeration
70 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
71 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
73 # Fineness enumeration(for NETGEN)
86 ior = salome.orb.object_to_string(obj)
87 sobj = salome.myStudy.FindObjectIOR(ior)
91 attr = sobj.FindAttribute("AttributeName")[1]
94 ## Sets name to object
95 def SetName(obj, name):
96 ior = salome.orb.object_to_string(obj)
97 sobj = salome.myStudy.FindObjectIOR(ior)
99 attr = sobj.FindAttribute("AttributeName")[1]
102 ## Print error message if a hypothesis was not assigned.
103 def TreatHypoStatus(status, hypName, geomName, isAlgo):
105 hypType = "algorithm"
107 hypType = "hypothesis"
109 if status == HYP_UNKNOWN_FATAL :
110 reason = "for unknown reason"
111 elif status == HYP_INCOMPATIBLE :
112 reason = "this hypothesis mismatches algorithm"
113 elif status == HYP_NOTCONFORM :
114 reason = "not conform mesh would be built"
115 elif status == HYP_ALREADY_EXIST :
116 reason = hypType + " of the same dimension already assigned to this shape"
117 elif status == HYP_BAD_DIM :
118 reason = hypType + " mismatches shape"
119 elif status == HYP_CONCURENT :
120 reason = "there are concurrent hypotheses on sub-shapes"
121 elif status == HYP_BAD_SUBSHAPE :
122 reason = "shape is neither the main one, nor its subshape, nor a valid group"
123 elif status == HYP_BAD_GEOMETRY:
124 reason = "geometry mismatches algorithm's expectation"
125 elif status == HYP_HIDDEN_ALGO:
126 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
127 elif status == HYP_HIDING_ALGO:
128 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
131 hypName = '"' + hypName + '"'
132 geomName= '"' + geomName+ '"'
133 if status < HYP_UNKNOWN_FATAL:
134 print hypName, "was assigned to", geomName,"but", reason
136 print hypName, "was not assigned to",geomName,":", reason
139 class smeshDC(SMESH._objref_SMESH_Gen):
141 def init_smesh(self,theStudy,geompyD):
143 self.SetGeomEngine(geompyD)
144 self.SetCurrentStudy(theStudy)
146 def Mesh(self, obj=0, name=0):
147 return Mesh(self,self.geompyD,obj,name)
149 ## Returns long value from enumeration
150 # Uses for SMESH.FunctorType enumeration
151 def EnumToLong(self,theItem):
154 ## Get PointStruct from vertex
155 # @param theVertex is GEOM object(vertex)
156 # @return SMESH.PointStruct
157 def GetPointStruct(self,theVertex):
158 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
159 return PointStruct(x,y,z)
161 ## Get DirStruct from vector
162 # @param theVector is GEOM object(vector)
163 # @return SMESH.DirStruct
164 def GetDirStruct(self,theVector):
165 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
166 if(len(vertices) != 2):
167 print "Error: vector object is incorrect."
169 p1 = self.geompyD.PointCoordinates(vertices[0])
170 p2 = self.geompyD.PointCoordinates(vertices[1])
171 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
172 dirst = DirStruct(pnt)
175 ## Make DirStruct from a triplet
176 # @param x,y,z are vector components
177 # @return SMESH.DirStruct
178 def MakeDirStruct(self,x,y,z):
179 pnt = PointStruct(x,y,z)
180 return DirStruct(pnt)
182 ## Get AxisStruct from object
183 # @param theObj is GEOM object(line or plane)
184 # @return SMESH.AxisStruct
185 def GetAxisStruct(self,theObj):
186 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
188 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
189 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
190 vertex1 = self.geompyD.PointCoordinates(vertex1)
191 vertex2 = self.geompyD.PointCoordinates(vertex2)
192 vertex3 = self.geompyD.PointCoordinates(vertex3)
193 vertex4 = self.geompyD.PointCoordinates(vertex4)
194 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
195 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
196 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] ]
197 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
199 elif len(edges) == 1:
200 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
201 p1 = self.geompyD.PointCoordinates( vertex1 )
202 p2 = self.geompyD.PointCoordinates( vertex2 )
203 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
207 # From SMESH_Gen interface:
208 # ------------------------
210 ## Set the current mode
211 def SetEmbeddedMode( self,theMode ):
212 #self.SetEmbeddedMode(theMode)
213 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
215 ## Get the current mode
216 def IsEmbeddedMode(self):
217 #return self.IsEmbeddedMode()
218 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
220 ## Set the current study
221 def SetCurrentStudy( self, theStudy ):
222 #self.SetCurrentStudy(theStudy)
223 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
225 ## Get the current study
226 def GetCurrentStudy(self):
227 #return self.GetCurrentStudy()
228 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
230 ## Create Mesh object importing data from given UNV file
231 # @return an instance of Mesh class
232 def CreateMeshesFromUNV( self,theFileName ):
233 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
234 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
237 ## Create Mesh object(s) importing data from given MED file
238 # @return a list of Mesh class instances
239 def CreateMeshesFromMED( self,theFileName ):
240 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
242 for iMesh in range(len(aSmeshMeshes)) :
243 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
244 aMeshes.append(aMesh)
245 return aMeshes, aStatus
247 ## Create Mesh object importing data from given STL file
248 # @return an instance of Mesh class
249 def CreateMeshesFromSTL( self, theFileName ):
250 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
251 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
254 ## From SMESH_Gen interface
255 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
256 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
258 ## From SMESH_Gen interface. Creates pattern
259 def GetPattern(self):
260 return SMESH._objref_SMESH_Gen.GetPattern(self)
264 # Filtering. Auxiliary functions:
265 # ------------------------------
267 ## Creates an empty criterion
268 # @return SMESH.Filter.Criterion
269 def GetEmptyCriterion(self):
270 Type = self.EnumToLong(FT_Undefined)
271 Compare = self.EnumToLong(FT_Undefined)
275 UnaryOp = self.EnumToLong(FT_Undefined)
276 BinaryOp = self.EnumToLong(FT_Undefined)
279 Precision = -1 ##@1e-07
280 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
281 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
283 ## Creates a criterion by given parameters
284 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
285 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
286 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
287 # @param Treshold is threshold value (range of ids as string, shape, numeric)
288 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
289 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
290 # FT_Undefined(must be for the last criterion in criteria)
291 # @return SMESH.Filter.Criterion
292 def GetCriterion(self,elementType,
294 Compare = FT_EqualTo,
296 UnaryOp=FT_Undefined,
297 BinaryOp=FT_Undefined):
298 aCriterion = self.GetEmptyCriterion()
299 aCriterion.TypeOfElement = elementType
300 aCriterion.Type = self.EnumToLong(CritType)
304 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
305 aCriterion.Compare = self.EnumToLong(Compare)
306 elif Compare == "=" or Compare == "==":
307 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
309 aCriterion.Compare = self.EnumToLong(FT_LessThan)
311 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
313 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
316 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
317 FT_BelongToCylinder, FT_LyingOnGeom]:
319 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
320 aCriterion.ThresholdStr = GetName(aTreshold)
321 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
323 print "Error: Treshold should be a shape."
325 elif CritType == FT_RangeOfIds:
327 if isinstance(aTreshold, str):
328 aCriterion.ThresholdStr = aTreshold
330 print "Error: Treshold should be a string."
332 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
333 # Here we do not need treshold
334 if aTreshold == FT_LogicalNOT:
335 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
336 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
337 aCriterion.BinaryOp = aTreshold
341 aTreshold = float(aTreshold)
342 aCriterion.Threshold = aTreshold
344 print "Error: Treshold should be a number."
347 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
348 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
350 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
351 aCriterion.BinaryOp = self.EnumToLong(Treshold)
353 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
354 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
356 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
357 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
361 ## Creates filter by given parameters of criterion
362 # @param elementType is the type of elements in the group
363 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
364 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
365 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
366 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
367 # @return SMESH_Filter
368 def GetFilter(self,elementType,
369 CritType=FT_Undefined,
372 UnaryOp=FT_Undefined):
373 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
374 aFilterMgr = self.CreateFilterManager()
375 aFilter = aFilterMgr.CreateFilter()
377 aCriteria.append(aCriterion)
378 aFilter.SetCriteria(aCriteria)
381 ## Creates numerical functor by its type
382 # @param theCrierion is FT_...; functor type
383 # @return SMESH_NumericalFunctor
384 def GetFunctor(self,theCriterion):
385 aFilterMgr = self.CreateFilterManager()
386 if theCriterion == FT_AspectRatio:
387 return aFilterMgr.CreateAspectRatio()
388 elif theCriterion == FT_AspectRatio3D:
389 return aFilterMgr.CreateAspectRatio3D()
390 elif theCriterion == FT_Warping:
391 return aFilterMgr.CreateWarping()
392 elif theCriterion == FT_MinimumAngle:
393 return aFilterMgr.CreateMinimumAngle()
394 elif theCriterion == FT_Taper:
395 return aFilterMgr.CreateTaper()
396 elif theCriterion == FT_Skew:
397 return aFilterMgr.CreateSkew()
398 elif theCriterion == FT_Area:
399 return aFilterMgr.CreateArea()
400 elif theCriterion == FT_Volume3D:
401 return aFilterMgr.CreateVolume3D()
402 elif theCriterion == FT_MultiConnection:
403 return aFilterMgr.CreateMultiConnection()
404 elif theCriterion == FT_MultiConnection2D:
405 return aFilterMgr.CreateMultiConnection2D()
406 elif theCriterion == FT_Length:
407 return aFilterMgr.CreateLength()
408 elif theCriterion == FT_Length2D:
409 return aFilterMgr.CreateLength2D()
411 print "Error: given parameter is not numerucal functor type."
414 #Register the new proxy for SMESH_Gen
415 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
418 ## Mother class to define algorithm, recommended to do not use directly.
421 class Mesh_Algorithm:
422 # @class Mesh_Algorithm
423 # @brief Class Mesh_Algorithm
427 #def __init__(self,smesh):
435 #17908#def FindHypothesis(self,hypname, args):
436 #17908# key = "%s %s %s" % (self.__class__.__name__, hypname, args)
437 #17908# if Mesh_Algorithm.hypos.has_key( key ):
438 #17908# return Mesh_Algorithm.hypos[ key ]
441 ## If the algorithm is global, return 0; \n
442 # else return the submesh associated to this algorithm.
443 def GetSubMesh(self):
446 ## Return the wrapped mesher.
447 def GetAlgorithm(self):
450 ## Get list of hypothesis that can be used with this algorithm
451 def GetCompatibleHypothesis(self):
454 mylist = self.algo.GetCompatibleHypothesis()
462 def SetName(self, name):
463 SetName(self.algo, name)
467 return self.algo.GetId()
470 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
472 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
473 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
474 self.Assign(algo, mesh, geom)
478 def Assign(self, algo, mesh, geom):
480 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
489 name = mesh.geompyD.SubShapeName(geom, piece)
490 mesh.geompyD.addToStudyInFather(piece, geom, name)
491 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
494 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
495 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
498 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so", UseExisting=0):
500 #17908#if UseExisting:
501 #17908# hypo = self.FindHypothesis(hyp, args)
502 #17908# if hypo: CreateNew = 0
505 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
506 key = "%s %s %s" % (self.__class__.__name__, hyp, args)
507 #17908#Mesh_Algorithm.hypos[key] = hypo
513 a = a + s + str(args[i])
516 name = GetName(self.geom)
517 #SetName(hypo, name + "/" + hyp + a) - NPAL16198
518 SetName(hypo, hyp + a)
520 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
521 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
525 # Public class: Mesh_Segment
526 # --------------------------
528 ## Class to define a segment 1D algorithm for discretization
531 class Mesh_Segment(Mesh_Algorithm):
533 #17908#algo = 0 # algorithm object common for all Mesh_Segments
535 ## Private constructor.
536 def __init__(self, mesh, geom=0):
537 Mesh_Algorithm.__init__(self)
539 #17908#if not Mesh_Segment.algo:
540 #17908# Mesh_Segment.algo = self.Create(mesh, geom, "Regular_1D")
542 #17908# self.Assign( Mesh_Segment.algo, mesh, geom)
544 self.Create(mesh, geom, "Regular_1D")
546 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
547 # @param l for the length of segments that cut an edge
548 # @param UseExisting if ==true - search existing hypothesis created with
549 # same parameters, else (default) - create new
550 def LocalLength(self, l, UseExisting=0):
551 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting)
555 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
556 # @param n for the number of segments that cut an edge
557 # @param s for the scale factor (optional)
558 # @param UseExisting if ==true - search existing hypothesis created with
559 # same parameters, else (default) - create new
560 def NumberOfSegments(self, n, s=[], UseExisting=0):
562 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting)
564 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting)
565 hyp.SetDistrType( 1 )
566 hyp.SetScaleFactor(s)
567 hyp.SetNumberOfSegments(n)
570 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
571 # @param start for the length of the first segment
572 # @param end for the length of the last segment
573 # @param UseExisting if ==true - search existing hypothesis created with
574 # same parameters, else (default) - create new
575 def Arithmetic1D(self, start, end, UseExisting=0):
576 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting)
577 hyp.SetLength(start, 1)
578 hyp.SetLength(end , 0)
581 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
582 # @param start for the length of the first segment
583 # @param end for the length of the last segment
584 # @param UseExisting if ==true - search existing hypothesis created with
585 # same parameters, else (default) - create new
586 def StartEndLength(self, start, end, UseExisting=0):
587 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting)
588 hyp.SetLength(start, 1)
589 hyp.SetLength(end , 0)
592 ## Define "Deflection1D" hypothesis
593 # @param d for the deflection
594 # @param UseExisting if ==true - search existing hypothesis created with
595 # same parameters, else (default) - create new
596 def Deflection1D(self, d, UseExisting=0):
597 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting)
601 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
602 # the opposite side in the case of quadrangular faces
603 def Propagation(self):
604 return self.Hypothesis("Propagation", UseExisting=1)
606 ## Define "AutomaticLength" hypothesis
607 # @param fineness for the fineness [0-1]
608 # @param UseExisting if ==true - search existing hypothesis created with
609 # same parameters, else (default) - create new
610 def AutomaticLength(self, fineness=0, UseExisting=0):
611 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting)
612 hyp.SetFineness( fineness )
615 ## Define "SegmentLengthAroundVertex" hypothesis
616 # @param length for the segment length
617 # @param vertex for the length localization: vertex index [0,1] | verext object
618 # @param UseExisting if ==true - search existing hypothesis created with
619 # same parameters, else (default) - create new
620 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
622 store_geom = self.geom
624 if type(vertex) is types.IntType:
625 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
629 hyp = self.Hypothesis("SegmentAroundVertex_0D",[length],UseExisting=UseExisting)
630 hyp = self.Hypothesis("SegmentLengthAroundVertex",[length],UseExisting=UseExisting)
631 self.geom = store_geom
632 hyp.SetLength( length )
635 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
636 # If the 2D mesher sees that all boundary edges are quadratic ones,
637 # it generates quadratic faces, else it generates linear faces using
638 # medium nodes as if they were vertex ones.
639 # The 3D mesher generates quadratic volumes only if all boundary faces
640 # are quadratic ones, else it fails.
641 def QuadraticMesh(self):
642 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1)
645 # Public class: Mesh_CompositeSegment
646 # --------------------------
648 ## Class to define a segment 1D algorithm for discretization
651 class Mesh_CompositeSegment(Mesh_Segment):
653 #17908#algo = 0 # algorithm object common for all Mesh_CompositeSegments
655 ## Private constructor.
656 def __init__(self, mesh, geom=0):
657 #17908#if not Mesh_CompositeSegment.algo:
658 #17908# Mesh_CompositeSegment.algo = self.Create(mesh, geom, "CompositeSegment_1D")
660 #17908# self.Assign( Mesh_CompositeSegment.algo, mesh, geom)
662 self.Create(mesh, geom, "CompositeSegment_1D")
665 # Public class: Mesh_Segment_Python
666 # ---------------------------------
668 ## Class to define a segment 1D algorithm for discretization with python function
671 class Mesh_Segment_Python(Mesh_Segment):
673 #17908#algo = 0 # algorithm object common for all Mesh_Segment_Pythons
675 ## Private constructor.
676 def __init__(self, mesh, geom=0):
677 import Python1dPlugin
678 #17908#if not Mesh_Segment_Python.algo:
679 #17908# Mesh_Segment_Python.algo = self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
681 #17908# self.Assign( Mesh_Segment_Python.algo, mesh, geom)
683 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
685 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
686 # @param n for the number of segments that cut an edge
687 # @param func for the python function that calculate the length of all segments
688 # @param UseExisting if ==true - search existing hypothesis created with
689 # same parameters, else (default) - create new
690 def PythonSplit1D(self, n, func, UseExisting=0):
691 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so", UseExisting=UseExisting)
692 hyp.SetNumberOfSegments(n)
693 hyp.SetPythonLog10RatioFunction(func)
696 # Public class: Mesh_Triangle
697 # ---------------------------
699 ## Class to define a triangle 2D algorithm
702 class Mesh_Triangle(Mesh_Algorithm):
711 # algorithm objects common for all instances of Mesh_Triangle
714 #17908#algoNET_2D = 0
716 ## Private constructor.
717 def __init__(self, mesh, algoType, geom=0):
718 Mesh_Algorithm.__init__(self)
720 self.algoType = algoType
721 if algoType == MEFISTO:
722 #17908#if not Mesh_Triangle.algoMEF:
723 #17908# Mesh_Triangle.algoMEF = self.Create(mesh, geom, "MEFISTO_2D")
725 #17908# self.Assign( Mesh_Triangle.algoMEF, mesh, geom)
727 self.Create(mesh, geom, "MEFISTO_2D")
729 elif algoType == BLSURF:
731 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
732 self.SetPhysicalMesh()
733 elif algoType == NETGEN:
735 print "Warning: NETGENPlugin module unavailable"
737 #17908#if not Mesh_Triangle.algoNET:
738 #17908# Mesh_Triangle.algoNET = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
740 #17908# self.Assign( Mesh_Triangle.algoNET, mesh, geom)
742 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
744 elif algoType == NETGEN_2D:
746 print "Warning: NETGENPlugin module unavailable"
748 #17908#if not Mesh_Triangle.algoNET_2D:
749 #17908# Mesh_Triangle.algoNET_2D = self.Create(mesh, geom,
750 #17908# "NETGEN_2D_ONLY", "libNETGENEngine.so")
752 #17908# self.Assign( Mesh_Triangle.algoNET_2D, mesh, geom)
754 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
757 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
758 # @param area for the maximum area of each triangles
759 # @param UseExisting if ==true - search existing hypothesis created with
760 # same parameters, else (default) - create new
762 # Only for algoType == MEFISTO || NETGEN_2D
763 def MaxElementArea(self, area, UseExisting=0):
764 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
765 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting)
766 hyp.SetMaxElementArea(area)
768 elif self.algoType == NETGEN:
769 print "Netgen 1D-2D algo doesn't support this hypothesis"
772 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
774 # Only for algoType == MEFISTO || NETGEN_2D
775 def LengthFromEdges(self):
776 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
777 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1)
779 elif self.algoType == NETGEN:
780 print "Netgen 1D-2D algo doesn't support this hypothesis"
784 # @param thePhysicalMesh is:
785 # DefaultSize or Custom
786 def SetPhysicalMesh(self, thePhysicalMesh=1):
789 self.params.SetPhysicalMesh(thePhysicalMesh)
792 def SetPhySize(self, theVal):
795 self.params.SetPhySize(theVal)
798 # @param theGeometricMesh is:
799 # DefaultGeom or Custom
800 def SetGeometricMesh(self, theGeometricMesh=0):
803 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
804 self.params.SetGeometricMesh(theGeometricMesh)
806 ## Set AngleMeshS flag
807 def SetAngleMeshS(self, theVal=_angleMeshS):
810 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
811 self.params.SetAngleMeshS(theVal)
813 ## Set Gradation flag
814 def SetGradation(self, theVal=_gradation):
817 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
818 self.params.SetGradation(theVal)
820 ## Set QuadAllowed flag
822 # Only for algoType == NETGEN || NETGEN_2D
823 def SetQuadAllowed(self, toAllow=True):
824 if self.algoType == NETGEN_2D:
825 if toAllow: # add QuadranglePreference
826 self.Hypothesis("QuadranglePreference", UseExisting=1)
827 else: # remove QuadranglePreference
828 for hyp in self.mesh.GetHypothesisList( self.geom ):
829 if hyp.GetName() == "QuadranglePreference":
830 self.mesh.RemoveHypothesis( self.geom, hyp )
835 if self.params == 0 and self.Parameters():
836 self.params.SetQuadAllowed(toAllow)
839 ## Define "Netgen 2D Parameters" hypothesis
841 # Only for algoType == NETGEN
842 def Parameters(self):
843 if self.algoType == NETGEN:
844 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
845 "libNETGENEngine.so", UseExisting=0)
847 elif self.algoType == MEFISTO:
848 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
850 elif self.algoType == NETGEN_2D:
851 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
852 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
854 elif self.algoType == BLSURF:
855 self.params = self.Hypothesis("BLSURF_Parameters", [], "libBLSURFEngine.so")
861 # Only for algoType == NETGEN
862 def SetMaxSize(self, theSize):
865 if self.params is not None:
866 self.params.SetMaxSize(theSize)
868 ## Set SecondOrder flag
870 # Only for algoType == NETGEN
871 def SetSecondOrder(self, theVal):
874 if self.params is not None:
875 self.params.SetSecondOrder(theVal)
879 # Only for algoType == NETGEN
880 def SetOptimize(self, theVal):
883 if self.params is not None:
884 self.params.SetOptimize(theVal)
887 # @param theFineness is:
888 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
890 # Only for algoType == NETGEN
891 def SetFineness(self, theFineness):
894 if self.params is not None:
895 self.params.SetFineness(theFineness)
899 # Only for algoType == NETGEN
900 def SetGrowthRate(self, theRate):
903 if self.params is not None:
904 self.params.SetGrowthRate(theRate)
908 # Only for algoType == NETGEN
909 def SetNbSegPerEdge(self, theVal):
912 if self.params is not None:
913 self.params.SetNbSegPerEdge(theVal)
915 ## Set NbSegPerRadius
917 # Only for algoType == NETGEN
918 def SetNbSegPerRadius(self, theVal):
921 if self.params is not None:
922 self.params.SetNbSegPerRadius(theVal)
925 def SetDecimesh(self, toAllow=False):
928 self.params.SetDecimesh(toAllow)
933 # Public class: Mesh_Quadrangle
934 # -----------------------------
936 ## Class to define a quadrangle 2D algorithm
939 class Mesh_Quadrangle(Mesh_Algorithm):
941 #17908#algo = 0 # algorithm object common for all Mesh_Quadrangles
943 ## Private constructor.
944 def __init__(self, mesh, geom=0):
945 Mesh_Algorithm.__init__(self)
947 #17908#if not Mesh_Quadrangle.algo:
948 #17908# Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
950 #17908# self.Assign( Mesh_Quadrangle.algo, mesh, geom)
952 self.Create(mesh, geom, "Quadrangle_2D")
954 ## Define "QuadranglePreference" hypothesis, forcing construction
955 # of quadrangles if the number of nodes on opposite edges is not the same
956 # in the case where the global number of nodes on edges is even
957 def QuadranglePreference(self):
958 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
961 # Public class: Mesh_Tetrahedron
962 # ------------------------------
964 ## Class to define a tetrahedron 3D algorithm
967 class Mesh_Tetrahedron(Mesh_Algorithm):
972 #17908#algoNET = 0 # algorithm object common for all Mesh_Tetrahedrons
973 #17908#algoGHS = 0 # algorithm object common for all Mesh_Tetrahedrons
974 #17908#algoFNET = 0 # algorithm object common for all Mesh_Tetrahedrons
976 ## Private constructor.
977 def __init__(self, mesh, algoType, geom=0):
978 Mesh_Algorithm.__init__(self)
980 if algoType == NETGEN:
981 #17908#if not Mesh_Tetrahedron.algoNET:
982 #17908# Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
984 #17908# self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
986 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
989 elif algoType == GHS3D:
990 #17908#if not Mesh_Tetrahedron.algoGHS:
991 #17908# import GHS3DPlugin
992 #17908# Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
994 #17908# self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
997 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
1000 elif algoType == FULL_NETGEN:
1002 print "Warning: NETGENPlugin module has not been imported."
1003 #17908#if not Mesh_Tetrahedron.algoFNET:
1004 #17908# Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1006 #17908# self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
1008 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1011 self.algoType = algoType
1013 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
1014 # @param vol for the maximum volume of each tetrahedral
1015 # @param UseExisting if ==true - search existing hypothesis created with
1016 # same parameters, else (default) - create new
1017 def MaxElementVolume(self, vol, UseExisting=0):
1018 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
1019 hyp.SetMaxElementVolume(vol)
1022 ## Define "Netgen 3D Parameters" hypothesis
1023 def Parameters(self):
1024 if (self.algoType == FULL_NETGEN):
1025 self.params = self.Hypothesis("NETGEN_Parameters", [],
1026 "libNETGENEngine.so", UseExisting=0)
1029 print "Algo doesn't support this hypothesis"
1033 def SetMaxSize(self, theSize):
1034 if self.params == 0:
1036 self.params.SetMaxSize(theSize)
1038 ## Set SecondOrder flag
1039 def SetSecondOrder(self, theVal):
1040 if self.params == 0:
1042 self.params.SetSecondOrder(theVal)
1044 ## Set Optimize flag
1045 def SetOptimize(self, theVal):
1046 if self.params == 0:
1048 self.params.SetOptimize(theVal)
1051 # @param theFineness is:
1052 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
1053 def SetFineness(self, theFineness):
1054 if self.params == 0:
1056 self.params.SetFineness(theFineness)
1059 def SetGrowthRate(self, theRate):
1060 if self.params == 0:
1062 self.params.SetGrowthRate(theRate)
1065 def SetNbSegPerEdge(self, theVal):
1066 if self.params == 0:
1068 self.params.SetNbSegPerEdge(theVal)
1070 ## Set NbSegPerRadius
1071 def SetNbSegPerRadius(self, theVal):
1072 if self.params == 0:
1074 self.params.SetNbSegPerRadius(theVal)
1076 # Public class: Mesh_Hexahedron
1077 # ------------------------------
1079 ## Class to define a hexahedron 3D algorithm
1082 class Mesh_Hexahedron(Mesh_Algorithm):
1084 # #17908#algo = 0 # algorithm object common for all Mesh_Hexahedrons
1086 # ## Private constructor.
1087 # def __init__(self, mesh, geom=0):
1088 # Mesh_Algorithm.__init__(self)
1090 # #17908#if not Mesh_Hexahedron.algo:
1091 # #17908# Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
1093 # #17908# self.Assign( Mesh_Hexahedron.algo, mesh, geom)
1095 # self.Create(mesh, geom, "Hexa_3D")
1100 #17908#algoHEXA = 0 # algorithm object common for all Mesh_Hexahedron's
1101 #17908#algoHEXO = 0 # algorithm object common for all Mesh_Hexahedron's
1103 ## Private constructor.
1104 def __init__(self, mesh, algoType=Hexa, geom=0):
1105 Mesh_Algorithm.__init__(self)
1107 if algoType == Hexa:
1108 #17908#if not Mesh_Hexahedron.algoHEXA:
1109 #17908# Mesh_Hexahedron.algoHEXA = self.Create(mesh, geom, "Hexa_3D")
1111 #17908# self.Assign(Mesh_Hexahedron.algoHEXA, mesh, geom)
1113 self.Create(mesh, geom, "Hexa_3D")
1116 elif algoType == Hexotic:
1117 #17908#if not Mesh_Hexahedron.algoHEXO:
1118 #17908# import HexoticPlugin
1119 #17908# Mesh_Hexahedron.algoHEXO = self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
1121 #17908# self.Assign(Mesh_Hexahedron.algoHEXO, mesh, geom)
1123 import HexoticPlugin
1124 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
1127 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
1128 def MinMaxQuad(self, min=3, max=8, quad=True):
1129 #17908#self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so")
1130 #17908#self.params.SetHexesMinLevel(min)
1131 #17908#self.params.SetHexesMaxLevel(max)
1132 #17908#self.params.SetHexoticQuadrangles(quad)
1133 #17908#return self.params
1134 params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so")
1135 params.SetHexesMinLevel(min)
1136 params.SetHexesMaxLevel(max)
1137 params.SetHexoticQuadrangles(quad)
1140 # Deprecated, only for compatibility!
1141 # Public class: Mesh_Netgen
1142 # ------------------------------
1144 ## Class to define a NETGEN-based 2D or 3D algorithm
1145 # that need no discrete boundary (i.e. independent)
1147 # This class is deprecated, only for compatibility!
1150 class Mesh_Netgen(Mesh_Algorithm):
1154 #17908#algoNET23 = 0 # algorithm object common for all Mesh_Netgens
1155 #17908#algoNET2 = 0 # algorithm object common for all Mesh_Netgens
1157 ## Private constructor.
1158 def __init__(self, mesh, is3D, geom=0):
1159 Mesh_Algorithm.__init__(self)
1162 print "Warning: NETGENPlugin module has not been imported."
1166 #17908#if not Mesh_Netgen.algoNET23:
1167 #17908# Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1169 #17908# self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1171 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1175 #17908#if not Mesh_Netgen.algoNET2:
1176 #17908# Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1178 #17908# self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1180 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1183 ## Define hypothesis containing parameters of the algorithm
1184 def Parameters(self):
1186 hyp = self.Hypothesis("NETGEN_Parameters", [],
1187 "libNETGENEngine.so", UseExisting=0)
1189 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1190 "libNETGENEngine.so", UseExisting=0)
1193 # Public class: Mesh_Projection1D
1194 # ------------------------------
1196 ## Class to define a projection 1D algorithm
1199 class Mesh_Projection1D(Mesh_Algorithm):
1201 #17908#algo = 0 # algorithm object common for all Mesh_Projection1Ds
1203 ## Private constructor.
1204 def __init__(self, mesh, geom=0):
1205 Mesh_Algorithm.__init__(self)
1207 #17908#if not Mesh_Projection1D.algo:
1208 #17908# Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1210 #17908# self.Assign( Mesh_Projection1D.algo, mesh, geom)
1212 self.Create(mesh, geom, "Projection_1D")
1214 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1215 # take a mesh pattern from, and optionally association of vertices
1216 # between the source edge and a target one (where a hipothesis is assigned to)
1217 # @param edge to take nodes distribution from
1218 # @param mesh to take nodes distribution from (optional)
1219 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1220 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1221 # to associate with \a srcV (optional)
1222 # @param UseExisting if ==true - search existing hypothesis created with
1223 # same parameters, else (default) - create new
1224 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1225 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1226 hyp.SetSourceEdge( edge )
1227 if not mesh is None and isinstance(mesh, Mesh):
1228 mesh = mesh.GetMesh()
1229 hyp.SetSourceMesh( mesh )
1230 hyp.SetVertexAssociation( srcV, tgtV )
1234 # Public class: Mesh_Projection2D
1235 # ------------------------------
1237 ## Class to define a projection 2D algorithm
1240 class Mesh_Projection2D(Mesh_Algorithm):
1242 #17908#algo = 0 # algorithm object common for all Mesh_Projection2Ds
1244 ## Private constructor.
1245 def __init__(self, mesh, geom=0):
1246 Mesh_Algorithm.__init__(self)
1248 #17908#if not Mesh_Projection2D.algo:
1249 #17908# Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1251 #17908# self.Assign( Mesh_Projection2D.algo, mesh, geom)
1253 self.Create(mesh, geom, "Projection_2D")
1255 ## Define "Source Face" hypothesis, specifying a meshed face to
1256 # take a mesh pattern from, and optionally association of vertices
1257 # between the source face and a target one (where a hipothesis is assigned to)
1258 # @param face to take mesh pattern from
1259 # @param mesh to take mesh pattern from (optional)
1260 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1261 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1262 # to associate with \a srcV1 (optional)
1263 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1264 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1265 # to associate with \a srcV2 (optional)
1266 # @param UseExisting if ==true - search existing hypothesis created with
1267 # same parameters, else (default) - create new
1269 # Note: association vertices must belong to one edge of a face
1270 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1271 srcV2=None, tgtV2=None, UseExisting=0):
1272 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1273 UseExisting=UseExisting)
1274 hyp.SetSourceFace( face )
1275 if not mesh is None and isinstance(mesh, Mesh):
1276 mesh = mesh.GetMesh()
1277 hyp.SetSourceMesh( mesh )
1278 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1281 # Public class: Mesh_Projection3D
1282 # ------------------------------
1284 ## Class to define a projection 3D algorithm
1287 class Mesh_Projection3D(Mesh_Algorithm):
1289 #17908#algo = 0 # algorithm object common for all Mesh_Projection3Ds
1291 ## Private constructor.
1292 def __init__(self, mesh, geom=0):
1293 Mesh_Algorithm.__init__(self)
1295 #17908#if not Mesh_Projection3D.algo:
1296 #17908# Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1298 #17908# self.Assign( Mesh_Projection3D.algo, mesh, geom)
1300 self.Create(mesh, geom, "Projection_3D")
1302 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1303 # take a mesh pattern from, and optionally association of vertices
1304 # between the source solid and a target one (where a hipothesis is assigned to)
1305 # @param solid to take mesh pattern from
1306 # @param mesh to take mesh pattern from (optional)
1307 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1308 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1309 # to associate with \a srcV1 (optional)
1310 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1311 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1312 # to associate with \a srcV2 (optional)
1313 # @param UseExisting - if ==true - search existing hypothesis created with
1314 # same parameters, else (default) - create new
1316 # Note: association vertices must belong to one edge of a solid
1317 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1318 srcV2=0, tgtV2=0, UseExisting=0):
1319 hyp = self.Hypothesis("ProjectionSource3D",
1320 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1321 UseExisting=UseExisting)
1322 hyp.SetSource3DShape( solid )
1323 if not mesh is None and isinstance(mesh, Mesh):
1324 mesh = mesh.GetMesh()
1325 hyp.SetSourceMesh( mesh )
1326 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1330 # Public class: Mesh_Prism
1331 # ------------------------
1333 ## Class to define a 3D extrusion algorithm
1336 class Mesh_Prism3D(Mesh_Algorithm):
1338 #17908#algo = 0 # algorithm object common for all Mesh_Prism3Ds
1340 ## Private constructor.
1341 def __init__(self, mesh, geom=0):
1342 Mesh_Algorithm.__init__(self)
1344 #17908#if not Mesh_Prism3D.algo:
1345 #17908# Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1347 #17908# self.Assign( Mesh_Prism3D.algo, mesh, geom)
1349 self.Create(mesh, geom, "Prism_3D")
1351 # Public class: Mesh_RadialPrism
1352 # -------------------------------
1354 ## Class to define a Radial Prism 3D algorithm
1357 class Mesh_RadialPrism3D(Mesh_Algorithm):
1359 #17908#algo = 0 # algorithm object common for all Mesh_RadialPrism3Ds
1361 ## Private constructor.
1362 def __init__(self, mesh, geom=0):
1363 Mesh_Algorithm.__init__(self)
1365 #17908#if not Mesh_RadialPrism3D.algo:
1366 #17908# Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1368 #17908# self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1370 self.Create(mesh, geom, "RadialPrism_3D")
1372 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1373 self.nbLayers = None
1375 ## Return 3D hypothesis holding the 1D one
1376 def Get3DHypothesis(self):
1377 return self.distribHyp
1379 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1380 # hypothes. Returns the created hypothes
1381 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1382 print "OwnHypothesis",hypType
1383 if not self.nbLayers is None:
1384 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1385 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1386 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
1387 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1388 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
1389 self.distribHyp.SetLayerDistribution( hyp )
1392 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1393 # prisms to build between the inner and outer shells
1394 # @param UseExisting if ==true - search existing hypothesis created with
1395 # same parameters, else (default) - create new
1396 def NumberOfLayers(self, n, UseExisting=0):
1397 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1398 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1399 self.nbLayers.SetNumberOfLayers( n )
1400 return self.nbLayers
1402 ## Define "LocalLength" hypothesis, specifying segment length
1403 # to build between the inner and outer shells
1404 # @param l for the length of segments
1405 def LocalLength(self, l):
1406 hyp = self.OwnHypothesis("LocalLength", [l] )
1410 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1411 # prisms to build between the inner and outer shells
1412 # @param n for the number of segments
1413 # @param s for the scale factor (optional)
1414 def NumberOfSegments(self, n, s=[]):
1416 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1418 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1419 hyp.SetDistrType( 1 )
1420 hyp.SetScaleFactor(s)
1421 hyp.SetNumberOfSegments(n)
1424 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1425 # to build between the inner and outer shells as arithmetic length increasing
1426 # @param start for the length of the first segment
1427 # @param end for the length of the last segment
1428 def Arithmetic1D(self, start, end ):
1429 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1430 hyp.SetLength(start, 1)
1431 hyp.SetLength(end , 0)
1434 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1435 # to build between the inner and outer shells as geometric length increasing
1436 # @param start for the length of the first segment
1437 # @param end for the length of the last segment
1438 def StartEndLength(self, start, end):
1439 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1440 hyp.SetLength(start, 1)
1441 hyp.SetLength(end , 0)
1444 ## Define "AutomaticLength" hypothesis, specifying number of segments
1445 # to build between the inner and outer shells
1446 # @param fineness for the fineness [0-1]
1447 def AutomaticLength(self, fineness=0):
1448 hyp = self.OwnHypothesis("AutomaticLength")
1449 hyp.SetFineness( fineness )
1452 # Private class: Mesh_UseExisting
1453 # -------------------------------
1454 class Mesh_UseExisting(Mesh_Algorithm):
1456 #17908#algo1D = 0 # StdMeshers_UseExisting_1D object common for all Mesh_UseExisting
1457 #17908#algo2D = 0 # StdMeshers_UseExisting_2D object common for all Mesh_UseExisting
1459 def __init__(self, dim, mesh, geom=0):
1461 #17908#if not Mesh_UseExisting.algo1D:
1462 #17908# Mesh_UseExisting.algo1D= self.Create(mesh, geom, "UseExisting_1D")
1464 #17908# self.Assign( Mesh_UseExisting.algo1D, mesh, geom)
1466 self.Create(mesh, geom, "UseExisting_1D")
1468 #17908#if not Mesh_UseExisting.algo2D:
1469 #17908# Mesh_UseExisting.algo2D= self.Create(mesh, geom, "UseExisting_2D")
1471 #17908# self.Assign( Mesh_UseExisting.algo2D, mesh, geom)
1473 self.Create(mesh, geom, "UseExisting_2D")
1475 # Public class: Mesh
1476 # ==================
1478 ## Class to define a mesh
1480 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1490 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1491 # sets GUI name of this mesh to \a name.
1492 # @param obj Shape to be meshed or SMESH_Mesh object
1493 # @param name Study name of the mesh
1494 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1495 self.smeshpyD=smeshpyD
1496 self.geompyD=geompyD
1500 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1502 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1503 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1506 self.mesh = self.smeshpyD.CreateEmptyMesh()
1508 SetName(self.mesh, name)
1510 SetName(self.mesh, GetName(obj))
1512 self.editor = self.mesh.GetMeshEditor()
1514 ## Method that inits the Mesh object from SMESH_Mesh interface
1515 # @param theMesh is SMESH_Mesh object
1516 def SetMesh(self, theMesh):
1518 self.geom = self.mesh.GetShapeToMesh()
1520 ## Method that returns the mesh
1521 # @return SMESH_Mesh object
1527 name = GetName(self.GetMesh())
1531 def SetName(self, name):
1532 SetName(self.GetMesh(), name)
1534 ## Get the subMesh object associated to a subShape. The subMesh object
1535 # gives access to nodes and elements IDs.
1536 # \n SubMesh will be used instead of SubShape in a next idl version to
1537 # adress a specific subMesh...
1538 def GetSubMesh(self, theSubObject, name):
1539 submesh = self.mesh.GetSubMesh(theSubObject, name)
1542 ## Method that returns the shape associated to the mesh
1543 # @return GEOM_Object
1547 ## Method that associates given shape to the mesh(entails the mesh recreation)
1548 # @param geom shape to be meshed(GEOM_Object)
1549 def SetShape(self, geom):
1550 self.mesh = self.smeshpyD.CreateMesh(geom)
1552 ## Return true if hypotheses are defined well
1553 # @param theMesh is an instance of Mesh class
1554 # @param theSubObject subshape of a mesh shape
1555 def IsReadyToCompute(self, theSubObject):
1556 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1558 ## Return errors of hypotheses definintion
1559 # error list is empty if everything is OK
1560 # @param theMesh is an instance of Mesh class
1561 # @param theSubObject subshape of a mesh shape
1562 # @return a list of errors
1563 def GetAlgoState(self, theSubObject):
1564 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1566 ## Return geometrical object the given element is built on.
1567 # The returned geometrical object, if not nil, is either found in the
1568 # study or is published by this method with the given name
1569 # @param theMesh is an instance of Mesh class
1570 # @param theElementID an id of the mesh element
1571 # @param theGeomName user defined name of geometrical object
1572 # @return GEOM::GEOM_Object instance
1573 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1574 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1576 ## Returns mesh dimension depending on shape one
1577 def MeshDimension(self):
1578 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1579 if len( shells ) > 0 :
1581 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1583 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1589 ## Creates a segment discretization 1D algorithm.
1590 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1591 # If the optional \a geom parameter is not sets, this algorithm is global.
1592 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1593 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1594 # @param geom If defined, subshape to be meshed
1595 def Segment(self, algo=REGULAR, geom=0):
1596 ## if Segment(geom) is called by mistake
1597 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1598 algo, geom = geom, algo
1599 if not algo: algo = REGULAR
1602 return Mesh_Segment(self, geom)
1603 elif algo == PYTHON:
1604 return Mesh_Segment_Python(self, geom)
1605 elif algo == COMPOSITE:
1606 return Mesh_CompositeSegment(self, geom)
1608 return Mesh_Segment(self, geom)
1610 ## Enable creation of nodes and segments usable by 2D algoritms.
1611 # Added nodes and segments must be bound to edges and vertices by
1612 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
1613 # If the optional \a geom parameter is not sets, this algorithm is global.
1614 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1615 # @param geom subshape to be manually meshed
1616 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
1617 def UseExistingSegments(self, geom=0):
1618 algo = Mesh_UseExisting(1,self,geom)
1619 return algo.GetAlgorithm()
1621 ## Enable creation of nodes and faces usable by 3D algoritms.
1622 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
1623 # and SetMeshElementOnShape()
1624 # If the optional \a geom parameter is not sets, this algorithm is global.
1625 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1626 # @param geom subshape to be manually meshed
1627 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
1628 def UseExistingFaces(self, geom=0):
1629 algo = Mesh_UseExisting(2,self,geom)
1630 return algo.GetAlgorithm()
1632 ## Creates a triangle 2D algorithm for faces.
1633 # If the optional \a geom parameter is not sets, this algorithm is global.
1634 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1635 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1636 # @param geom If defined, subshape to be meshed
1637 def Triangle(self, algo=MEFISTO, geom=0):
1638 ## if Triangle(geom) is called by mistake
1639 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1643 return Mesh_Triangle(self, algo, geom)
1645 ## Creates a quadrangle 2D algorithm for faces.
1646 # If the optional \a geom parameter is not sets, this algorithm is global.
1647 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1648 # @param geom If defined, subshape to be meshed
1649 def Quadrangle(self, geom=0):
1650 return Mesh_Quadrangle(self, geom)
1652 ## Creates a tetrahedron 3D algorithm for solids.
1653 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1654 # If the optional \a geom parameter is not sets, this algorithm is global.
1655 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1656 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1657 # @param geom If defined, subshape to be meshed
1658 def Tetrahedron(self, algo=NETGEN, geom=0):
1659 ## if Tetrahedron(geom) is called by mistake
1660 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1661 algo, geom = geom, algo
1662 if not algo: algo = NETGEN
1664 return Mesh_Tetrahedron(self, algo, geom)
1666 ## Creates a hexahedron 3D algorithm for solids.
1667 # If the optional \a geom parameter is not sets, this algorithm is global.
1668 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1669 # @param geom If defined, subshape to be meshed
1670 ## def Hexahedron(self, geom=0):
1671 ## return Mesh_Hexahedron(self, geom)
1672 def Hexahedron(self, algo=Hexa, geom=0):
1673 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1674 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
1675 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
1676 elif geom == 0: algo, geom = Hexa, algo
1677 return Mesh_Hexahedron(self, algo, geom)
1679 ## Deprecated, only for compatibility!
1680 def Netgen(self, is3D, geom=0):
1681 return Mesh_Netgen(self, is3D, geom)
1683 ## Creates a projection 1D algorithm for edges.
1684 # If the optional \a geom parameter is not sets, this algorithm is global.
1685 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1686 # @param geom If defined, subshape to be meshed
1687 def Projection1D(self, geom=0):
1688 return Mesh_Projection1D(self, geom)
1690 ## Creates a projection 2D algorithm for faces.
1691 # If the optional \a geom parameter is not sets, this algorithm is global.
1692 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1693 # @param geom If defined, subshape to be meshed
1694 def Projection2D(self, geom=0):
1695 return Mesh_Projection2D(self, geom)
1697 ## Creates a projection 3D algorithm for solids.
1698 # If the optional \a geom parameter is not sets, this algorithm is global.
1699 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1700 # @param geom If defined, subshape to be meshed
1701 def Projection3D(self, geom=0):
1702 return Mesh_Projection3D(self, geom)
1704 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1705 # If the optional \a geom parameter is not sets, this algorithm is global.
1706 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1707 # @param geom If defined, subshape to be meshed
1708 def Prism(self, geom=0):
1712 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
1713 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
1714 if nbSolids == 0 or nbSolids == nbShells:
1715 return Mesh_Prism3D(self, geom)
1716 return Mesh_RadialPrism3D(self, geom)
1718 ## Compute the mesh and return the status of the computation
1719 def Compute(self, geom=0):
1720 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1722 print "Compute impossible: mesh is not constructed on geom shape."
1728 ok = self.smeshpyD.Compute(self.mesh, geom)
1729 except SALOME.SALOME_Exception, ex:
1730 print "Mesh computation failed, exception caught:"
1731 print " ", ex.details.text
1734 print "Mesh computation failed, exception caught:"
1735 traceback.print_exc()
1737 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1740 if err.isGlobalAlgo:
1748 reason = '%s %sD algorithm is missing' % (glob, dim)
1749 elif err.state == HYP_MISSING:
1750 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1751 % (glob, dim, name, dim))
1752 elif err.state == HYP_NOTCONFORM:
1753 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1754 elif err.state == HYP_BAD_PARAMETER:
1755 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1756 % ( glob, dim, name ))
1757 elif err.state == HYP_BAD_GEOMETRY:
1758 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1759 'its expectation' % ( glob, dim, name ))
1761 reason = "For unknown reason."+\
1762 " Revise Mesh.Compute() implementation in smeshDC.py!"
1764 if allReasons != "":
1767 allReasons += reason
1769 if allReasons != "":
1770 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1773 print '"' + GetName(self.mesh) + '"',"has not been computed."
1776 if salome.sg.hasDesktop():
1777 smeshgui = salome.ImportComponentGUI("SMESH")
1778 smeshgui.Init(salome.myStudyId)
1779 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1780 salome.sg.updateObjBrowser(1)
1784 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1785 # The parameter \a fineness [0,-1] defines mesh fineness
1786 def AutomaticTetrahedralization(self, fineness=0):
1787 dim = self.MeshDimension()
1789 self.RemoveGlobalHypotheses()
1790 self.Segment().AutomaticLength(fineness)
1792 self.Triangle().LengthFromEdges()
1795 self.Tetrahedron(NETGEN)
1797 return self.Compute()
1799 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1800 # The parameter \a fineness [0,-1] defines mesh fineness
1801 def AutomaticHexahedralization(self, fineness=0):
1802 dim = self.MeshDimension()
1804 self.RemoveGlobalHypotheses()
1805 self.Segment().AutomaticLength(fineness)
1812 return self.Compute()
1814 ## Assign hypothesis
1815 # @param hyp is a hypothesis to assign
1816 # @param geom is subhape of mesh geometry
1817 def AddHypothesis(self, hyp, geom=0 ):
1818 if isinstance( hyp, Mesh_Algorithm ):
1819 hyp = hyp.GetAlgorithm()
1824 status = self.mesh.AddHypothesis(geom, hyp)
1825 isAlgo = hyp._narrow( SMESH_Algo )
1826 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1829 ## Unassign hypothesis
1830 # @param hyp is a hypothesis to unassign
1831 # @param geom is subhape of mesh geometry
1832 def RemoveHypothesis(self, hyp, geom=0 ):
1833 if isinstance( hyp, Mesh_Algorithm ):
1834 hyp = hyp.GetAlgorithm()
1839 status = self.mesh.RemoveHypothesis(geom, hyp)
1842 ## Get the list of hypothesis added on a geom
1843 # @param geom is subhape of mesh geometry
1844 def GetHypothesisList(self, geom):
1845 return self.mesh.GetHypothesisList( geom )
1847 ## Removes all global hypotheses
1848 def RemoveGlobalHypotheses(self):
1849 current_hyps = self.mesh.GetHypothesisList( self.geom )
1850 for hyp in current_hyps:
1851 self.mesh.RemoveHypothesis( self.geom, hyp )
1855 ## Create a mesh group based on geometric object \a grp
1856 # and give a \a name, \n if this parameter is not defined
1857 # the name is the same as the geometric group name \n
1858 # Note: Works like GroupOnGeom().
1859 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1860 # @param name is the name of the mesh group
1861 # @return SMESH_GroupOnGeom
1862 def Group(self, grp, name=""):
1863 return self.GroupOnGeom(grp, name)
1865 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1866 # Export the mesh in a file with the MED format and choice the \a version of MED format
1867 # @param f is the file name
1868 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1869 def ExportToMED(self, f, version, opt=0):
1870 self.mesh.ExportToMED(f, opt, version)
1872 ## Export the mesh in a file with the MED format
1873 # @param f is the file name
1874 # @param auto_groups boolean parameter for creating/not creating
1875 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1876 # the typical use is auto_groups=false.
1877 # @param version MED format version(MED_V2_1 or MED_V2_2)
1878 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1879 self.mesh.ExportToMED(f, auto_groups, version)
1881 ## Export the mesh in a file with the DAT format
1882 # @param f is the file name
1883 def ExportDAT(self, f):
1884 self.mesh.ExportDAT(f)
1886 ## Export the mesh in a file with the UNV format
1887 # @param f is the file name
1888 def ExportUNV(self, f):
1889 self.mesh.ExportUNV(f)
1891 ## Export the mesh in a file with the STL format
1892 # @param f is the file name
1893 # @param ascii defined the kind of file contents
1894 def ExportSTL(self, f, ascii=1):
1895 self.mesh.ExportSTL(f, ascii)
1898 # Operations with groups:
1899 # ----------------------
1901 ## Creates an empty mesh group
1902 # @param elementType is the type of elements in the group
1903 # @param name is the name of the mesh group
1904 # @return SMESH_Group
1905 def CreateEmptyGroup(self, elementType, name):
1906 return self.mesh.CreateGroup(elementType, name)
1908 ## Creates a mesh group based on geometric object \a grp
1909 # and give a \a name, \n if this parameter is not defined
1910 # the name is the same as the geometric group name
1911 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1912 # @param name is the name of the mesh group
1913 # @return SMESH_GroupOnGeom
1914 def GroupOnGeom(self, grp, name="", typ=None):
1916 name = grp.GetName()
1919 tgeo = str(grp.GetShapeType())
1920 if tgeo == "VERTEX":
1922 elif tgeo == "EDGE":
1924 elif tgeo == "FACE":
1926 elif tgeo == "SOLID":
1928 elif tgeo == "SHELL":
1930 elif tgeo == "COMPOUND":
1931 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1932 print "Mesh.Group: empty geometric group", GetName( grp )
1934 tgeo = self.geompyD.GetType(grp)
1935 if tgeo == geompyDC.ShapeType["VERTEX"]:
1937 elif tgeo == geompyDC.ShapeType["EDGE"]:
1939 elif tgeo == geompyDC.ShapeType["FACE"]:
1941 elif tgeo == geompyDC.ShapeType["SOLID"]:
1945 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1948 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1950 ## Create a mesh group by the given ids of elements
1951 # @param groupName is the name of the mesh group
1952 # @param elementType is the type of elements in the group
1953 # @param elemIDs is the list of ids
1954 # @return SMESH_Group
1955 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1956 group = self.mesh.CreateGroup(elementType, groupName)
1960 ## Create a mesh group by the given conditions
1961 # @param groupName is the name of the mesh group
1962 # @param elementType is the type of elements in the group
1963 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1964 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1965 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1966 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1967 # @return SMESH_Group
1971 CritType=FT_Undefined,
1974 UnaryOp=FT_Undefined):
1975 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1976 group = self.MakeGroupByCriterion(groupName, aCriterion)
1979 ## Create a mesh group by the given criterion
1980 # @param groupName is the name of the mesh group
1981 # @param Criterion is the instance of Criterion class
1982 # @return SMESH_Group
1983 def MakeGroupByCriterion(self, groupName, Criterion):
1984 aFilterMgr = self.smeshpyD.CreateFilterManager()
1985 aFilter = aFilterMgr.CreateFilter()
1987 aCriteria.append(Criterion)
1988 aFilter.SetCriteria(aCriteria)
1989 group = self.MakeGroupByFilter(groupName, aFilter)
1992 ## Create a mesh group by the given criteria(list of criterions)
1993 # @param groupName is the name of the mesh group
1994 # @param Criteria is the list of criterions
1995 # @return SMESH_Group
1996 def MakeGroupByCriteria(self, groupName, theCriteria):
1997 aFilterMgr = self.smeshpyD.CreateFilterManager()
1998 aFilter = aFilterMgr.CreateFilter()
1999 aFilter.SetCriteria(theCriteria)
2000 group = self.MakeGroupByFilter(groupName, aFilter)
2003 ## Create a mesh group by the given filter
2004 # @param groupName is the name of the mesh group
2005 # @param Criterion is the instance of Filter class
2006 # @return SMESH_Group
2007 def MakeGroupByFilter(self, groupName, theFilter):
2008 anIds = theFilter.GetElementsId(self.mesh)
2009 anElemType = theFilter.GetElementType()
2010 group = self.MakeGroupByIds(groupName, anElemType, anIds)
2013 ## Pass mesh elements through the given filter and return ids
2014 # @param theFilter is SMESH_Filter
2015 # @return list of ids
2016 def GetIdsFromFilter(self, theFilter):
2017 return theFilter.GetElementsId(self.mesh)
2019 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
2020 # Returns list of special structures(borders).
2021 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
2022 def GetFreeBorders(self):
2023 aFilterMgr = self.smeshpyD.CreateFilterManager()
2024 aPredicate = aFilterMgr.CreateFreeEdges()
2025 aPredicate.SetMesh(self.mesh)
2026 aBorders = aPredicate.GetBorders()
2030 def RemoveGroup(self, group):
2031 self.mesh.RemoveGroup(group)
2033 ## Remove group with its contents
2034 def RemoveGroupWithContents(self, group):
2035 self.mesh.RemoveGroupWithContents(group)
2037 ## Get the list of groups existing in the mesh
2038 def GetGroups(self):
2039 return self.mesh.GetGroups()
2041 ## Get number of groups existing in the mesh
2043 return self.mesh.NbGroups()
2045 ## Get the list of names of groups existing in the mesh
2046 def GetGroupNames(self):
2047 groups = self.GetGroups()
2049 for group in groups:
2050 names.append(group.GetName())
2053 ## Union of two groups
2054 # New group is created. All mesh elements that are
2055 # present in initial groups are added to the new one
2056 def UnionGroups(self, group1, group2, name):
2057 return self.mesh.UnionGroups(group1, group2, name)
2059 ## Intersection of two groups
2060 # New group is created. All mesh elements that are
2061 # present in both initial groups are added to the new one.
2062 def IntersectGroups(self, group1, group2, name):
2063 return self.mesh.IntersectGroups(group1, group2, name)
2065 ## Cut of two groups
2066 # New group is created. All mesh elements that are present in
2067 # main group but do not present in tool group are added to the new one
2068 def CutGroups(self, mainGroup, toolGroup, name):
2069 return self.mesh.CutGroups(mainGroup, toolGroup, name)
2072 # Get some info about mesh:
2073 # ------------------------
2075 ## Get the log of nodes and elements added or removed since previous
2077 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
2078 # @return list of log_block structures:
2083 def GetLog(self, clearAfterGet):
2084 return self.mesh.GetLog(clearAfterGet)
2086 ## Clear the log of nodes and elements added or removed since previous
2087 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2089 self.mesh.ClearLog()
2091 def SetAutoColor(self, color):
2092 self.mesh.SetAutoColor(color)
2094 def GetAutoColor(self):
2095 return self.mesh.GetAutoColor()
2097 ## Get the internal Id
2099 return self.mesh.GetId()
2102 def GetStudyId(self):
2103 return self.mesh.GetStudyId()
2105 ## Check group names for duplications.
2106 # Consider maximum group name length stored in MED file.
2107 def HasDuplicatedGroupNamesMED(self):
2108 return self.mesh.HasDuplicatedGroupNamesMED()
2110 ## Obtain instance of SMESH_MeshEditor
2111 def GetMeshEditor(self):
2112 return self.mesh.GetMeshEditor()
2115 def GetMEDMesh(self):
2116 return self.mesh.GetMEDMesh()
2119 # Get informations about mesh contents:
2120 # ------------------------------------
2122 ## Returns number of nodes in mesh
2124 return self.mesh.NbNodes()
2126 ## Returns number of elements in mesh
2127 def NbElements(self):
2128 return self.mesh.NbElements()
2130 ## Returns number of edges in mesh
2132 return self.mesh.NbEdges()
2134 ## Returns number of edges with given order in mesh
2135 # @param elementOrder is order of elements:
2136 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2137 def NbEdgesOfOrder(self, elementOrder):
2138 return self.mesh.NbEdgesOfOrder(elementOrder)
2140 ## Returns number of faces in mesh
2142 return self.mesh.NbFaces()
2144 ## Returns number of faces with given order in mesh
2145 # @param elementOrder is order of elements:
2146 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2147 def NbFacesOfOrder(self, elementOrder):
2148 return self.mesh.NbFacesOfOrder(elementOrder)
2150 ## Returns number of triangles in mesh
2151 def NbTriangles(self):
2152 return self.mesh.NbTriangles()
2154 ## Returns number of triangles with given order in mesh
2155 # @param elementOrder is order of elements:
2156 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2157 def NbTrianglesOfOrder(self, elementOrder):
2158 return self.mesh.NbTrianglesOfOrder(elementOrder)
2160 ## Returns number of quadrangles in mesh
2161 def NbQuadrangles(self):
2162 return self.mesh.NbQuadrangles()
2164 ## Returns number of quadrangles with given order in mesh
2165 # @param elementOrder is order of elements:
2166 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2167 def NbQuadranglesOfOrder(self, elementOrder):
2168 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2170 ## Returns number of polygons in mesh
2171 def NbPolygons(self):
2172 return self.mesh.NbPolygons()
2174 ## Returns number of volumes in mesh
2175 def NbVolumes(self):
2176 return self.mesh.NbVolumes()
2178 ## Returns number of volumes with given order in mesh
2179 # @param elementOrder is order of elements:
2180 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2181 def NbVolumesOfOrder(self, elementOrder):
2182 return self.mesh.NbVolumesOfOrder(elementOrder)
2184 ## Returns number of tetrahedrons in mesh
2186 return self.mesh.NbTetras()
2188 ## Returns number of tetrahedrons with given order in mesh
2189 # @param elementOrder is order of elements:
2190 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2191 def NbTetrasOfOrder(self, elementOrder):
2192 return self.mesh.NbTetrasOfOrder(elementOrder)
2194 ## Returns number of hexahedrons in mesh
2196 return self.mesh.NbHexas()
2198 ## Returns number of hexahedrons with given order in mesh
2199 # @param elementOrder is order of elements:
2200 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2201 def NbHexasOfOrder(self, elementOrder):
2202 return self.mesh.NbHexasOfOrder(elementOrder)
2204 ## Returns number of pyramids in mesh
2205 def NbPyramids(self):
2206 return self.mesh.NbPyramids()
2208 ## Returns number of pyramids with given order in mesh
2209 # @param elementOrder is order of elements:
2210 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2211 def NbPyramidsOfOrder(self, elementOrder):
2212 return self.mesh.NbPyramidsOfOrder(elementOrder)
2214 ## Returns number of prisms in mesh
2216 return self.mesh.NbPrisms()
2218 ## Returns number of prisms with given order in mesh
2219 # @param elementOrder is order of elements:
2220 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2221 def NbPrismsOfOrder(self, elementOrder):
2222 return self.mesh.NbPrismsOfOrder(elementOrder)
2224 ## Returns number of polyhedrons in mesh
2225 def NbPolyhedrons(self):
2226 return self.mesh.NbPolyhedrons()
2228 ## Returns number of submeshes in mesh
2229 def NbSubMesh(self):
2230 return self.mesh.NbSubMesh()
2232 ## Returns list of mesh elements ids
2233 def GetElementsId(self):
2234 return self.mesh.GetElementsId()
2236 ## Returns list of ids of mesh elements with given type
2237 # @param elementType is required type of elements
2238 def GetElementsByType(self, elementType):
2239 return self.mesh.GetElementsByType(elementType)
2241 ## Returns list of mesh nodes ids
2242 def GetNodesId(self):
2243 return self.mesh.GetNodesId()
2245 # Get informations about mesh elements:
2246 # ------------------------------------
2248 ## Returns type of mesh element
2249 def GetElementType(self, id, iselem):
2250 return self.mesh.GetElementType(id, iselem)
2252 ## Returns list of submesh elements ids
2253 # @param Shape is geom object(subshape) IOR
2254 # Shape must be subshape of a ShapeToMesh()
2255 def GetSubMeshElementsId(self, Shape):
2256 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2257 ShapeID = Shape.GetSubShapeIndices()[0]
2260 return self.mesh.GetSubMeshElementsId(ShapeID)
2262 ## Returns list of submesh nodes ids
2263 # @param Shape is geom object(subshape) IOR
2264 # Shape must be subshape of a ShapeToMesh()
2265 def GetSubMeshNodesId(self, Shape, all):
2266 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2267 ShapeID = Shape.GetSubShapeIndices()[0]
2270 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2272 ## Returns list of ids of submesh elements with given type
2273 # @param Shape is geom object(subshape) IOR
2274 # Shape must be subshape of a ShapeToMesh()
2275 def GetSubMeshElementType(self, Shape):
2276 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2277 ShapeID = Shape.GetSubShapeIndices()[0]
2280 return self.mesh.GetSubMeshElementType(ShapeID)
2282 ## Get mesh description
2284 return self.mesh.Dump()
2287 # Get information about nodes and elements of mesh by its ids:
2288 # -----------------------------------------------------------
2290 ## Get XYZ coordinates of node as list of double
2291 # \n If there is not node for given ID - returns empty list
2292 def GetNodeXYZ(self, id):
2293 return self.mesh.GetNodeXYZ(id)
2295 ## For given node returns list of IDs of inverse elements
2296 # \n If there is not node for given ID - returns empty list
2297 def GetNodeInverseElements(self, id):
2298 return self.mesh.GetNodeInverseElements(id)
2300 ## @brief Return position of a node on shape
2301 # @return SMESH::NodePosition
2302 def GetNodePosition(self,NodeID):
2303 return self.mesh.GetNodePosition(NodeID)
2305 ## If given element is node returns IDs of shape from position
2306 # \n If there is not node for given ID - returns -1
2307 def GetShapeID(self, id):
2308 return self.mesh.GetShapeID(id)
2310 ## For given element returns ID of result shape after
2311 # FindShape() from SMESH_MeshEditor
2312 # \n If there is not element for given ID - returns -1
2313 def GetShapeIDForElem(self,id):
2314 return self.mesh.GetShapeIDForElem(id)
2316 ## Returns number of nodes for given element
2317 # \n If there is not element for given ID - returns -1
2318 def GetElemNbNodes(self, id):
2319 return self.mesh.GetElemNbNodes(id)
2321 ## Returns ID of node by given index for given element
2322 # \n If there is not element for given ID - returns -1
2323 # \n If there is not node for given index - returns -2
2324 def GetElemNode(self, id, index):
2325 return self.mesh.GetElemNode(id, index)
2327 ## Returns IDs of nodes of given element
2328 def GetElemNodes(self, id):
2329 return self.mesh.GetElemNodes(id)
2331 ## Returns true if given node is medium node
2332 # in given quadratic element
2333 def IsMediumNode(self, elementID, nodeID):
2334 return self.mesh.IsMediumNode(elementID, nodeID)
2336 ## Returns true if given node is medium node
2337 # in one of quadratic elements
2338 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2339 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2341 ## Returns number of edges for given element
2342 def ElemNbEdges(self, id):
2343 return self.mesh.ElemNbEdges(id)
2345 ## Returns number of faces for given element
2346 def ElemNbFaces(self, id):
2347 return self.mesh.ElemNbFaces(id)
2349 ## Returns true if given element is polygon
2350 def IsPoly(self, id):
2351 return self.mesh.IsPoly(id)
2353 ## Returns true if given element is quadratic
2354 def IsQuadratic(self, id):
2355 return self.mesh.IsQuadratic(id)
2357 ## Returns XYZ coordinates of bary center for given element
2359 # \n If there is not element for given ID - returns empty list
2360 def BaryCenter(self, id):
2361 return self.mesh.BaryCenter(id)
2364 # Mesh edition (SMESH_MeshEditor functionality):
2365 # ---------------------------------------------
2367 ## Removes elements from mesh by ids
2368 # @param IDsOfElements is list of ids of elements to remove
2369 def RemoveElements(self, IDsOfElements):
2370 return self.editor.RemoveElements(IDsOfElements)
2372 ## Removes nodes from mesh by ids
2373 # @param IDsOfNodes is list of ids of nodes to remove
2374 def RemoveNodes(self, IDsOfNodes):
2375 return self.editor.RemoveNodes(IDsOfNodes)
2377 ## Add node to mesh by coordinates
2378 def AddNode(self, x, y, z):
2379 return self.editor.AddNode( x, y, z)
2382 ## Create edge both similar and quadratic (this is determed
2383 # by number of given nodes).
2384 # @param IdsOfNodes List of node IDs for creation of element.
2385 # Needed order of nodes in this list corresponds to description
2386 # of MED. \n This description is located by the following link:
2387 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2388 def AddEdge(self, IDsOfNodes):
2389 return self.editor.AddEdge(IDsOfNodes)
2391 ## Create face both similar and quadratic (this is determed
2392 # by number of given nodes).
2393 # @param IdsOfNodes List of node IDs for creation of element.
2394 # Needed order of nodes in this list corresponds to description
2395 # of MED. \n This description is located by the following link:
2396 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2397 def AddFace(self, IDsOfNodes):
2398 return self.editor.AddFace(IDsOfNodes)
2400 ## Add polygonal face to mesh by list of nodes ids
2401 def AddPolygonalFace(self, IdsOfNodes):
2402 return self.editor.AddPolygonalFace(IdsOfNodes)
2404 ## Create volume both similar and quadratic (this is determed
2405 # by number of given nodes).
2406 # @param IdsOfNodes List of node IDs for creation of element.
2407 # Needed order of nodes in this list corresponds to description
2408 # of MED. \n This description is located by the following link:
2409 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2410 def AddVolume(self, IDsOfNodes):
2411 return self.editor.AddVolume(IDsOfNodes)
2413 ## Create volume of many faces, giving nodes for each face.
2414 # @param IdsOfNodes List of node IDs for volume creation face by face.
2415 # @param Quantities List of integer values, Quantities[i]
2416 # gives quantity of nodes in face number i.
2417 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2418 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2420 ## Create volume of many faces, giving IDs of existing faces.
2421 # @param IdsOfFaces List of face IDs for volume creation.
2423 # Note: The created volume will refer only to nodes
2424 # of the given faces, not to the faces itself.
2425 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2426 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2429 ## @brief Bind a node to a vertex
2430 # @param NodeID - node ID
2431 # @param Vertex - vertex or vertex ID
2432 # @return True if succeed else raise an exception
2433 def SetNodeOnVertex(self, NodeID, Vertex):
2434 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2435 VertexID = Vertex.GetSubShapeIndices()[0]
2439 self.editor.SetNodeOnVertex(NodeID, VertexID)
2440 except SALOME.SALOME_Exception, inst:
2441 raise ValueError, inst.details.text
2445 ## @brief Store node position on an edge
2446 # @param NodeID - node ID
2447 # @param Edge - edge or edge ID
2448 # @param paramOnEdge - parameter on edge where the node is located
2449 # @return True if succeed else raise an exception
2450 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2451 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2452 EdgeID = Edge.GetSubShapeIndices()[0]
2456 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2457 except SALOME.SALOME_Exception, inst:
2458 raise ValueError, inst.details.text
2461 ## @brief Store node position on a face
2462 # @param NodeID - node ID
2463 # @param Face - face or face ID
2464 # @param u - U parameter on face where the node is located
2465 # @param v - V parameter on face where the node is located
2466 # @return True if succeed else raise an exception
2467 def SetNodeOnFace(self, NodeID, Face, u, v):
2468 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2469 FaceID = Face.GetSubShapeIndices()[0]
2473 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2474 except SALOME.SALOME_Exception, inst:
2475 raise ValueError, inst.details.text
2478 ## @brief Bind a node to a solid
2479 # @param NodeID - node ID
2480 # @param Solid - solid or solid ID
2481 # @return True if succeed else raise an exception
2482 def SetNodeInVolume(self, NodeID, Solid):
2483 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2484 SolidID = Solid.GetSubShapeIndices()[0]
2488 self.editor.SetNodeInVolume(NodeID, SolidID)
2489 except SALOME.SALOME_Exception, inst:
2490 raise ValueError, inst.details.text
2493 ## @brief Bind an element to a shape
2494 # @param ElementID - element ID
2495 # @param Shape - shape or shape ID
2496 # @return True if succeed else raise an exception
2497 def SetMeshElementOnShape(self, ElementID, Shape):
2498 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2499 ShapeID = Shape.GetSubShapeIndices()[0]
2503 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2504 except SALOME.SALOME_Exception, inst:
2505 raise ValueError, inst.details.text
2509 ## Move node with given id
2510 # @param NodeID id of the node
2511 # @param x new X coordinate
2512 # @param y new Y coordinate
2513 # @param z new Z coordinate
2514 def MoveNode(self, NodeID, x, y, z):
2515 return self.editor.MoveNode(NodeID, x, y, z)
2517 ## Find a node closest to a point
2518 # @param x X coordinate of a point
2519 # @param y Y coordinate of a point
2520 # @param z Z coordinate of a point
2521 # @return id of a node
2522 def FindNodeClosestTo(self, x, y, z):
2523 preview = self.mesh.GetMeshEditPreviewer()
2524 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2526 ## Find a node closest to a point and move it to a point location
2527 # @param x X coordinate of a point
2528 # @param y Y coordinate of a point
2529 # @param z Z coordinate of a point
2530 # @return id of a moved node
2531 def MeshToPassThroughAPoint(self, x, y, z):
2532 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2534 ## Replace two neighbour triangles sharing Node1-Node2 link
2535 # with ones built on the same 4 nodes but having other common link.
2536 # @param NodeID1 first node id
2537 # @param NodeID2 second node id
2538 # @return false if proper faces not found
2539 def InverseDiag(self, NodeID1, NodeID2):
2540 return self.editor.InverseDiag(NodeID1, NodeID2)
2542 ## Replace two neighbour triangles sharing Node1-Node2 link
2543 # with a quadrangle built on the same 4 nodes.
2544 # @param NodeID1 first node id
2545 # @param NodeID2 second node id
2546 # @return false if proper faces not found
2547 def DeleteDiag(self, NodeID1, NodeID2):
2548 return self.editor.DeleteDiag(NodeID1, NodeID2)
2550 ## Reorient elements by ids
2551 # @param IDsOfElements if undefined reorient all mesh elements
2552 def Reorient(self, IDsOfElements=None):
2553 if IDsOfElements == None:
2554 IDsOfElements = self.GetElementsId()
2555 return self.editor.Reorient(IDsOfElements)
2557 ## Reorient all elements of the object
2558 # @param theObject is mesh, submesh or group
2559 def ReorientObject(self, theObject):
2560 if ( isinstance( theObject, Mesh )):
2561 theObject = theObject.GetMesh()
2562 return self.editor.ReorientObject(theObject)
2564 ## Fuse neighbour triangles into quadrangles.
2565 # @param IDsOfElements The triangles to be fused,
2566 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2567 # @param MaxAngle is a max angle between element normals at which fusion
2568 # is still performed; theMaxAngle is mesured in radians.
2569 # @return TRUE in case of success, FALSE otherwise.
2570 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2571 if IDsOfElements == []:
2572 IDsOfElements = self.GetElementsId()
2573 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2575 ## Fuse neighbour triangles of the object into quadrangles
2576 # @param theObject is mesh, submesh or group
2577 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2578 # @param MaxAngle is a max angle between element normals at which fusion
2579 # is still performed; theMaxAngle is mesured in radians.
2580 # @return TRUE in case of success, FALSE otherwise.
2581 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2582 if ( isinstance( theObject, Mesh )):
2583 theObject = theObject.GetMesh()
2584 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2586 ## Split quadrangles into triangles.
2587 # @param IDsOfElements the faces to be splitted.
2588 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2589 # @return TRUE in case of success, FALSE otherwise.
2590 def QuadToTri (self, IDsOfElements, theCriterion):
2591 if IDsOfElements == []:
2592 IDsOfElements = self.GetElementsId()
2593 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2595 ## Split quadrangles into triangles.
2596 # @param theObject object to taking list of elements from, is mesh, submesh or group
2597 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2598 def QuadToTriObject (self, theObject, theCriterion):
2599 if ( isinstance( theObject, Mesh )):
2600 theObject = theObject.GetMesh()
2601 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2603 ## Split quadrangles into triangles.
2604 # @param theElems The faces to be splitted
2605 # @param the13Diag is used to choose a diagonal for splitting.
2606 # @return TRUE in case of success, FALSE otherwise.
2607 def SplitQuad (self, IDsOfElements, Diag13):
2608 if IDsOfElements == []:
2609 IDsOfElements = self.GetElementsId()
2610 return self.editor.SplitQuad(IDsOfElements, Diag13)
2612 ## Split quadrangles into triangles.
2613 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2614 def SplitQuadObject (self, theObject, Diag13):
2615 if ( isinstance( theObject, Mesh )):
2616 theObject = theObject.GetMesh()
2617 return self.editor.SplitQuadObject(theObject, Diag13)
2619 ## Find better splitting of the given quadrangle.
2620 # @param IDOfQuad ID of the quadrangle to be splitted.
2621 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2622 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2623 # diagonal is better, 0 if error occurs.
2624 def BestSplit (self, IDOfQuad, theCriterion):
2625 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2627 ## Split quafrangle faces near triangular facets of volumes
2629 def SplitQuadsNearTriangularFacets(self):
2630 faces_array = self.GetElementsByType(SMESH.FACE)
2631 for face_id in faces_array:
2632 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2633 quad_nodes = self.mesh.GetElemNodes(face_id)
2634 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2635 isVolumeFound = False
2636 for node1_elem in node1_elems:
2637 if not isVolumeFound:
2638 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2639 nb_nodes = self.GetElemNbNodes(node1_elem)
2640 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2641 volume_elem = node1_elem
2642 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2643 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2644 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2645 isVolumeFound = True
2646 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2647 self.SplitQuad([face_id], False) # diagonal 2-4
2648 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2649 isVolumeFound = True
2650 self.SplitQuad([face_id], True) # diagonal 1-3
2651 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2652 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2653 isVolumeFound = True
2654 self.SplitQuad([face_id], True) # diagonal 1-3
2656 ## @brief Split hexahedrons into tetrahedrons.
2658 # Use pattern mapping functionality for splitting.
2659 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2660 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2661 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2662 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2663 # key-point will be mapped into <theNode001>-th node of each volume.
2664 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2665 # @return TRUE in case of success, FALSE otherwise.
2666 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2667 # Pattern: 5.---------.6
2672 # (0,0,1) 4.---------.7 * |
2679 # (0,0,0) 0.---------.3
2680 pattern_tetra = "!!! Nb of points: \n 8 \n\
2690 !!! Indices of points of 6 tetras: \n\
2698 pattern = self.smeshpyD.GetPattern()
2699 isDone = pattern.LoadFromFile(pattern_tetra)
2701 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2704 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2705 isDone = pattern.MakeMesh(self.mesh, False, False)
2706 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2708 # split quafrangle faces near triangular facets of volumes
2709 self.SplitQuadsNearTriangularFacets()
2713 ## @brief Split hexahedrons into prisms.
2715 # Use pattern mapping functionality for splitting.
2716 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2717 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2718 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2719 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2720 # key-point will be mapped into <theNode001>-th node of each volume.
2721 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2722 # @return TRUE in case of success, FALSE otherwise.
2723 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2724 # Pattern: 5.---------.6
2729 # (0,0,1) 4.---------.7 |
2736 # (0,0,0) 0.---------.3
2737 pattern_prism = "!!! Nb of points: \n 8 \n\
2747 !!! Indices of points of 2 prisms: \n\
2751 pattern = self.smeshpyD.GetPattern()
2752 isDone = pattern.LoadFromFile(pattern_prism)
2754 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2757 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2758 isDone = pattern.MakeMesh(self.mesh, False, False)
2759 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2761 # split quafrangle faces near triangular facets of volumes
2762 self.SplitQuadsNearTriangularFacets()
2767 # @param IDsOfElements list if ids of elements to smooth
2768 # @param IDsOfFixedNodes list of ids of fixed nodes.
2769 # Note that nodes built on edges and boundary nodes are always fixed.
2770 # @param MaxNbOfIterations maximum number of iterations
2771 # @param MaxAspectRatio varies in range [1.0, inf]
2772 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2773 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2774 MaxNbOfIterations, MaxAspectRatio, Method):
2775 if IDsOfElements == []:
2776 IDsOfElements = self.GetElementsId()
2777 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2778 MaxNbOfIterations, MaxAspectRatio, Method)
2780 ## Smooth elements belong to given object
2781 # @param theObject object to smooth
2782 # @param IDsOfFixedNodes list of ids of fixed nodes.
2783 # Note that nodes built on edges and boundary nodes are always fixed.
2784 # @param MaxNbOfIterations maximum number of iterations
2785 # @param MaxAspectRatio varies in range [1.0, inf]
2786 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2787 def SmoothObject(self, theObject, IDsOfFixedNodes,
2788 MaxNbOfIterations, MaxxAspectRatio, Method):
2789 if ( isinstance( theObject, Mesh )):
2790 theObject = theObject.GetMesh()
2791 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2792 MaxNbOfIterations, MaxxAspectRatio, Method)
2794 ## Parametric smooth the given elements
2795 # @param IDsOfElements list if ids of elements to smooth
2796 # @param IDsOfFixedNodes list of ids of fixed nodes.
2797 # Note that nodes built on edges and boundary nodes are always fixed.
2798 # @param MaxNbOfIterations maximum number of iterations
2799 # @param MaxAspectRatio varies in range [1.0, inf]
2800 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2801 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2802 MaxNbOfIterations, MaxAspectRatio, Method):
2803 if IDsOfElements == []:
2804 IDsOfElements = self.GetElementsId()
2805 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2806 MaxNbOfIterations, MaxAspectRatio, Method)
2808 ## Parametric smooth elements belong to given object
2809 # @param theObject object to smooth
2810 # @param IDsOfFixedNodes list of ids of fixed nodes.
2811 # Note that nodes built on edges and boundary nodes are always fixed.
2812 # @param MaxNbOfIterations maximum number of iterations
2813 # @param MaxAspectRatio varies in range [1.0, inf]
2814 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2815 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2816 MaxNbOfIterations, MaxAspectRatio, Method):
2817 if ( isinstance( theObject, Mesh )):
2818 theObject = theObject.GetMesh()
2819 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2820 MaxNbOfIterations, MaxAspectRatio, Method)
2822 ## Converts all mesh to quadratic one, deletes old elements, replacing
2823 # them with quadratic ones with the same id.
2824 def ConvertToQuadratic(self, theForce3d):
2825 self.editor.ConvertToQuadratic(theForce3d)
2827 ## Converts all mesh from quadratic to ordinary ones,
2828 # deletes old quadratic elements, \n replacing
2829 # them with ordinary mesh elements with the same id.
2830 def ConvertFromQuadratic(self):
2831 return self.editor.ConvertFromQuadratic()
2833 ## Renumber mesh nodes
2834 def RenumberNodes(self):
2835 self.editor.RenumberNodes()
2837 ## Renumber mesh elements
2838 def RenumberElements(self):
2839 self.editor.RenumberElements()
2841 ## Generate new elements by rotation of the elements around the axis
2842 # @param IDsOfElements list of ids of elements to sweep
2843 # @param Axix axis of rotation, AxisStruct or line(geom object)
2844 # @param AngleInRadians angle of Rotation
2845 # @param NbOfSteps number of steps
2846 # @param Tolerance tolerance
2847 # @param MakeGroups to generate new groups from existing ones
2848 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2849 if IDsOfElements == []:
2850 IDsOfElements = self.GetElementsId()
2851 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2852 Axix = self.smeshpyD.GetAxisStruct(Axix)
2854 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2855 AngleInRadians, NbOfSteps, Tolerance)
2856 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2859 ## Generate new elements by rotation of the elements of object around the axis
2860 # @param theObject object wich elements should be sweeped
2861 # @param Axix axis of rotation, AxisStruct or line(geom object)
2862 # @param AngleInRadians angle of Rotation
2863 # @param NbOfSteps number of steps
2864 # @param Tolerance tolerance
2865 # @param MakeGroups to generate new groups from existing ones
2866 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2867 if ( isinstance( theObject, Mesh )):
2868 theObject = theObject.GetMesh()
2869 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2870 Axix = self.smeshpyD.GetAxisStruct(Axix)
2872 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2873 NbOfSteps, Tolerance)
2874 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2877 ## Generate new elements by extrusion of the elements with given ids
2878 # @param IDsOfElements list of elements ids for extrusion
2879 # @param StepVector vector, defining the direction and value of extrusion
2880 # @param NbOfSteps the number of steps
2881 # @param MakeGroups to generate new groups from existing ones
2882 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2883 if IDsOfElements == []:
2884 IDsOfElements = self.GetElementsId()
2885 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2886 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2888 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2889 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2892 ## Generate new elements by extrusion of the elements with given ids
2893 # @param IDsOfElements is ids of elements
2894 # @param StepVector vector, defining the direction and value of extrusion
2895 # @param NbOfSteps the number of steps
2896 # @param ExtrFlags set flags for performing extrusion
2897 # @param SewTolerance uses for comparing locations of nodes if flag
2898 # EXTRUSION_FLAG_SEW is set
2899 # @param MakeGroups to generate new groups from existing ones
2900 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2901 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2902 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2904 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2905 ExtrFlags, SewTolerance)
2906 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2907 ExtrFlags, SewTolerance)
2910 ## Generate new elements by extrusion of the elements belong to object
2911 # @param theObject object wich elements should be processed
2912 # @param StepVector vector, defining the direction and value of extrusion
2913 # @param NbOfSteps the number of steps
2914 # @param MakeGroups to generate new groups from existing ones
2915 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2916 if ( isinstance( theObject, Mesh )):
2917 theObject = theObject.GetMesh()
2918 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2919 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2921 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2922 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2925 ## Generate new elements by extrusion of the elements belong to object
2926 # @param theObject object wich elements should be processed
2927 # @param StepVector vector, defining the direction and value of extrusion
2928 # @param NbOfSteps the number of steps
2929 # @param MakeGroups to generate new groups from existing ones
2930 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2931 if ( isinstance( theObject, Mesh )):
2932 theObject = theObject.GetMesh()
2933 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2934 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2936 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2937 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2940 ## Generate new elements by extrusion of the elements belong to object
2941 # @param theObject object wich elements should be processed
2942 # @param StepVector vector, defining the direction and value of extrusion
2943 # @param NbOfSteps the number of steps
2944 # @param MakeGroups to generate new groups from existing ones
2945 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2946 if ( isinstance( theObject, Mesh )):
2947 theObject = theObject.GetMesh()
2948 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2949 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2951 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2952 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2955 ## Generate new elements by extrusion of the given elements
2956 # A path of extrusion must be a meshed edge.
2957 # @param IDsOfElements is ids of elements
2958 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2959 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2960 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2961 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2962 # @param Angles list of angles
2963 # @param HasRefPoint allows to use base point
2964 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2965 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2966 # @param MakeGroups to generate new groups from existing ones
2967 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2968 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2969 HasAngles, Angles, HasRefPoint, RefPoint,
2970 MakeGroups=False, LinearVariation=False):
2971 if IDsOfElements == []:
2972 IDsOfElements = self.GetElementsId()
2973 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2974 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2977 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
2978 PathShape, NodeStart, HasAngles,
2979 Angles, HasRefPoint, RefPoint)
2980 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
2981 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2983 ## Generate new elements by extrusion of the elements belong to object
2984 # A path of extrusion must be a meshed edge.
2985 # @param IDsOfElements is ids of elements
2986 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2987 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2988 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2989 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2990 # @param Angles list of angles
2991 # @param HasRefPoint allows to use base point
2992 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2993 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2994 # @param MakeGroups to generate new groups from existing ones
2995 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2996 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2997 HasAngles, Angles, HasRefPoint, RefPoint,
2998 MakeGroups=False, LinearVariation=False):
2999 if ( isinstance( theObject, Mesh )):
3000 theObject = theObject.GetMesh()
3001 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3002 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3004 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
3005 PathShape, NodeStart, HasAngles,
3006 Angles, HasRefPoint, RefPoint)
3007 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
3008 NodeStart, HasAngles, Angles, HasRefPoint,
3011 ## Symmetrical copy of mesh elements
3012 # @param IDsOfElements list of elements ids
3013 # @param Mirror is AxisStruct or geom object(point, line, plane)
3014 # @param theMirrorType is POINT, AXIS or PLANE
3015 # If the Mirror is geom object this parameter is unnecessary
3016 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3017 # @param MakeGroups to generate new groups from existing ones (if Copy)
3018 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3019 if IDsOfElements == []:
3020 IDsOfElements = self.GetElementsId()
3021 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3022 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3023 if Copy and MakeGroups:
3024 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3025 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3028 ## Create a new mesh by symmetrical copy of mesh elements
3029 # @param IDsOfElements list of elements ids
3030 # @param Mirror is AxisStruct or geom object(point, line, plane)
3031 # @param theMirrorType is POINT, AXIS or PLANE
3032 # If the Mirror is geom object this parameter is unnecessary
3033 # @param MakeGroups to generate new groups from existing ones
3034 # @param NewMeshName is a name of new mesh to create
3035 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3036 if IDsOfElements == []:
3037 IDsOfElements = self.GetElementsId()
3038 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3039 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3040 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3041 MakeGroups, NewMeshName)
3042 return Mesh(self.smeshpyD,self.geompyD,mesh)
3044 ## Symmetrical copy of object
3045 # @param theObject mesh, submesh or group
3046 # @param Mirror is AxisStruct or geom object(point, line, plane)
3047 # @param theMirrorType is POINT, AXIS or PLANE
3048 # If the Mirror is geom object this parameter is unnecessary
3049 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3050 # @param MakeGroups to generate new groups from existing ones (if Copy)
3051 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3052 if ( isinstance( theObject, Mesh )):
3053 theObject = theObject.GetMesh()
3054 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3055 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3056 if Copy and MakeGroups:
3057 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3058 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3061 ## Create a new mesh by symmetrical copy of object
3062 # @param theObject mesh, submesh or group
3063 # @param Mirror is AxisStruct or geom object(point, line, plane)
3064 # @param theMirrorType is POINT, AXIS or PLANE
3065 # If the Mirror is geom object this parameter is unnecessary
3066 # @param MakeGroups to generate new groups from existing ones
3067 # @param NewMeshName is a name of new mesh to create
3068 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3069 if ( isinstance( theObject, Mesh )):
3070 theObject = theObject.GetMesh()
3071 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3072 Mirror = GetAxisStruct(Mirror)
3073 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3074 MakeGroups, NewMeshName)
3075 return Mesh( self.smeshpyD,self.geompyD,mesh )
3077 ## Translates the elements
3078 # @param IDsOfElements list of elements ids
3079 # @param Vector direction of translation(DirStruct or vector)
3080 # @param Copy allows to copy the translated elements
3081 # @param MakeGroups to generate new groups from existing ones (if Copy)
3082 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3083 if IDsOfElements == []:
3084 IDsOfElements = self.GetElementsId()
3085 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3086 Vector = self.smeshpyD.GetDirStruct(Vector)
3087 if Copy and MakeGroups:
3088 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3089 self.editor.Translate(IDsOfElements, Vector, Copy)
3092 ## Create a new mesh of translated elements
3093 # @param IDsOfElements list of elements ids
3094 # @param Vector direction of translation(DirStruct or vector)
3095 # @param MakeGroups to generate new groups from existing ones
3096 # @param NewMeshName is a name of new mesh to create
3097 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3098 if IDsOfElements == []:
3099 IDsOfElements = self.GetElementsId()
3100 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3101 Vector = self.smeshpyD.GetDirStruct(Vector)
3102 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3103 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3105 ## Translates the object
3106 # @param theObject object to translate(mesh, submesh, or group)
3107 # @param Vector direction of translation(DirStruct or geom vector)
3108 # @param Copy allows to copy the translated elements
3109 # @param MakeGroups to generate new groups from existing ones (if Copy)
3110 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3111 if ( isinstance( theObject, Mesh )):
3112 theObject = theObject.GetMesh()
3113 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3114 Vector = self.smeshpyD.GetDirStruct(Vector)
3115 if Copy and MakeGroups:
3116 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3117 self.editor.TranslateObject(theObject, Vector, Copy)
3120 ## Create a new mesh from translated object
3121 # @param theObject object to translate(mesh, submesh, or group)
3122 # @param Vector direction of translation(DirStruct or geom vector)
3123 # @param MakeGroups to generate new groups from existing ones
3124 # @param NewMeshName is a name of new mesh to create
3125 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3126 if ( isinstance( theObject, Mesh )):
3127 theObject = theObject.GetMesh()
3128 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3129 Vector = self.smeshpyD.GetDirStruct(Vector)
3130 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3131 return Mesh( self.smeshpyD, self.geompyD, mesh )
3133 ## Rotates the elements
3134 # @param IDsOfElements list of elements ids
3135 # @param Axis axis of rotation(AxisStruct or geom line)
3136 # @param AngleInRadians angle of rotation(in radians)
3137 # @param Copy allows to copy the rotated elements
3138 # @param MakeGroups to generate new groups from existing ones (if Copy)
3139 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3140 if IDsOfElements == []:
3141 IDsOfElements = self.GetElementsId()
3142 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3143 Axis = self.smeshpyD.GetAxisStruct(Axis)
3144 if Copy and MakeGroups:
3145 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3146 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3149 ## Create a new mesh of rotated elements
3150 # @param IDsOfElements list of element ids
3151 # @param Axis axis of rotation(AxisStruct or geom line)
3152 # @param AngleInRadians angle of rotation(in radians)
3153 # @param MakeGroups to generate new groups from existing ones
3154 # @param NewMeshName is a name of new mesh to create
3155 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3156 if IDsOfElements == []:
3157 IDsOfElements = self.GetElementsId()
3158 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3159 Axis = self.smeshpyD.GetAxisStruct(Axis)
3160 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3161 MakeGroups, NewMeshName)
3162 return Mesh( self.smeshpyD, self.geompyD, mesh )
3164 ## Rotates the object
3165 # @param theObject object to rotate(mesh, submesh, or group)
3166 # @param Axis axis of rotation(AxisStruct or geom line)
3167 # @param AngleInRadians angle of rotation(in radians)
3168 # @param Copy allows to copy the rotated elements
3169 # @param MakeGroups to generate new groups from existing ones (if Copy)
3170 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3171 if ( isinstance( theObject, Mesh )):
3172 theObject = theObject.GetMesh()
3173 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3174 Axis = self.smeshpyD.GetAxisStruct(Axis)
3175 if Copy and MakeGroups:
3176 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3177 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3180 ## Create a new mesh from a rotated object
3181 # @param theObject object to rotate (mesh, submesh, or group)
3182 # @param Axis axis of rotation(AxisStruct or geom line)
3183 # @param AngleInRadians angle of rotation(in radians)
3184 # @param MakeGroups to generate new groups from existing ones
3185 # @param NewMeshName is a name of new mesh to create
3186 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3187 if ( isinstance( theObject, Mesh )):
3188 theObject = theObject.GetMesh()
3189 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3190 Axis = self.smeshpyD.GetAxisStruct(Axis)
3191 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3192 MakeGroups, NewMeshName)
3193 return Mesh( self.smeshpyD, self.geompyD, mesh )
3195 ## Find group of nodes close to each other within Tolerance.
3196 # @param Tolerance tolerance value
3197 # @param list of group of nodes
3198 def FindCoincidentNodes (self, Tolerance):
3199 return self.editor.FindCoincidentNodes(Tolerance)
3201 ## Find group of nodes close to each other within Tolerance.
3202 # @param Tolerance tolerance value
3203 # @param SubMeshOrGroup SubMesh or Group
3204 # @param list of group of nodes
3205 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
3206 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
3209 # @param list of group of nodes
3210 def MergeNodes (self, GroupsOfNodes):
3211 self.editor.MergeNodes(GroupsOfNodes)
3213 ## Find elements built on the same nodes.
3214 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3215 # @return a list of groups of equal elements
3216 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3217 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3219 ## Merge elements in each given group.
3220 # @param GroupsOfElementsID groups of elements for merging
3221 def MergeElements(self, GroupsOfElementsID):
3222 self.editor.MergeElements(GroupsOfElementsID)
3224 ## Remove all but one of elements built on the same nodes.
3225 def MergeEqualElements(self):
3226 self.editor.MergeEqualElements()
3229 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3230 FirstNodeID2, SecondNodeID2, LastNodeID2,
3231 CreatePolygons, CreatePolyedrs):
3232 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3233 FirstNodeID2, SecondNodeID2, LastNodeID2,
3234 CreatePolygons, CreatePolyedrs)
3236 ## Sew conform free borders
3237 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3238 FirstNodeID2, SecondNodeID2):
3239 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3240 FirstNodeID2, SecondNodeID2)
3242 ## Sew border to side
3243 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3244 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3245 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3246 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3248 ## Sew two sides of a mesh. Nodes belonging to Side1 are
3249 # merged with nodes of elements of Side2.
3250 # Number of elements in theSide1 and in theSide2 must be
3251 # equal and they should have similar node connectivity.
3252 # The nodes to merge should belong to sides borders and
3253 # the first node should be linked to the second.
3254 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3255 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3256 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3257 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3258 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3259 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3261 ## Set new nodes for given element.
3262 # @param ide the element id
3263 # @param newIDs nodes ids
3264 # @return If number of nodes is not corresponded to type of element - returns false
3265 def ChangeElemNodes(self, ide, newIDs):
3266 return self.editor.ChangeElemNodes(ide, newIDs)
3268 ## If during last operation of MeshEditor some nodes were
3269 # created this method returns list of its IDs, \n
3270 # if new nodes not created - returns empty list
3271 def GetLastCreatedNodes(self):
3272 return self.editor.GetLastCreatedNodes()
3274 ## If during last operation of MeshEditor some elements were
3275 # created this method returns list of its IDs, \n
3276 # if new elements not creared - returns empty list
3277 def GetLastCreatedElems(self):
3278 return self.editor.GetLastCreatedElems()