1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Francis KLOSS, OCC
32 import SMESH # necessary for back compatibility
39 # import NETGENPlugin module if possible
58 NETGEN_1D2D3D = FULL_NETGEN
59 NETGEN_FULL = FULL_NETGEN
61 # MirrorType enumeration
62 POINT = SMESH_MeshEditor.POINT
63 AXIS = SMESH_MeshEditor.AXIS
64 PLANE = SMESH_MeshEditor.PLANE
66 # Smooth_Method enumeration
67 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
68 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
70 # Fineness enumeration(for NETGEN)
83 ior = salome.orb.object_to_string(obj)
84 sobj = salome.myStudy.FindObjectIOR(ior)
88 attr = sobj.FindAttribute("AttributeName")[1]
91 ## Sets name to object
92 def SetName(obj, name):
93 ior = salome.orb.object_to_string(obj)
94 sobj = salome.myStudy.FindObjectIOR(ior)
96 attr = sobj.FindAttribute("AttributeName")[1]
99 ## Print error message if a hypothesis was not assigned.
100 def TreatHypoStatus(status, hypName, geomName, isAlgo):
102 hypType = "algorithm"
104 hypType = "hypothesis"
106 if status == HYP_UNKNOWN_FATAL :
107 reason = "for unknown reason"
108 elif status == HYP_INCOMPATIBLE :
109 reason = "this hypothesis mismatches algorithm"
110 elif status == HYP_NOTCONFORM :
111 reason = "not conform mesh would be built"
112 elif status == HYP_ALREADY_EXIST :
113 reason = hypType + " of the same dimension already assigned to this shape"
114 elif status == HYP_BAD_DIM :
115 reason = hypType + " mismatches shape"
116 elif status == HYP_CONCURENT :
117 reason = "there are concurrent hypotheses on sub-shapes"
118 elif status == HYP_BAD_SUBSHAPE :
119 reason = "shape is neither the main one, nor its subshape, nor a valid group"
120 elif status == HYP_BAD_GEOMETRY:
121 reason = "geometry mismatches algorithm's expectation"
122 elif status == HYP_HIDDEN_ALGO:
123 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
124 elif status == HYP_HIDING_ALGO:
125 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
128 hypName = '"' + hypName + '"'
129 geomName= '"' + geomName+ '"'
130 if status < HYP_UNKNOWN_FATAL:
131 print hypName, "was assigned to", geomName,"but", reason
133 print hypName, "was not assigned to",geomName,":", reason
136 class smeshDC(SMESH._objref_SMESH_Gen):
138 def init_smesh(self,theStudy,geompyD):
139 self.SetCurrentStudy(theStudy)
141 self.SetGeomEngine(geompyD)
143 def Mesh(self, obj=0, name=0):
144 return Mesh(self,self.geompyD,obj,name)
146 ## Returns long value from enumeration
147 # Uses for SMESH.FunctorType enumeration
148 def EnumToLong(self,theItem):
151 ## Get PointStruct from vertex
152 # @param theVertex is GEOM object(vertex)
153 # @return SMESH.PointStruct
154 def GetPointStruct(self,theVertex):
155 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
156 return PointStruct(x,y,z)
158 ## Get DirStruct from vector
159 # @param theVector is GEOM object(vector)
160 # @return SMESH.DirStruct
161 def GetDirStruct(self,theVector):
162 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
163 if(len(vertices) != 2):
164 print "Error: vector object is incorrect."
166 p1 = self.geompyD.PointCoordinates(vertices[0])
167 p2 = self.geompyD.PointCoordinates(vertices[1])
168 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
169 dirst = DirStruct(pnt)
172 ## Make DirStruct from a triplet
173 # @param x,y,z are vector components
174 # @return SMESH.DirStruct
175 def MakeDirStruct(x,y,z):
176 pnt = PointStruct(x,y,z)
177 return DirStruct(pnt)
179 ## Get AxisStruct from object
180 # @param theObj is GEOM object(line or plane)
181 # @return SMESH.AxisStruct
182 def GetAxisStruct(self,theObj):
183 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
185 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
186 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
187 vertex1 = self.geompyD.PointCoordinates(vertex1)
188 vertex2 = self.geompyD.PointCoordinates(vertex2)
189 vertex3 = self.geompyD.PointCoordinates(vertex3)
190 vertex4 = self.geompyD.PointCoordinates(vertex4)
191 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
192 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
193 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] ]
194 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
196 elif len(edges) == 1:
197 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
198 p1 = self.geompyD.PointCoordinates( vertex1 )
199 p2 = self.geompyD.PointCoordinates( vertex2 )
200 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
204 # From SMESH_Gen interface:
205 # ------------------------
207 ## Set the current mode
208 def SetEmbeddedMode( self,theMode ):
209 #self.SetEmbeddedMode(theMode)
210 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
212 ## Get the current mode
213 def IsEmbeddedMode(self):
214 #return self.IsEmbeddedMode()
215 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
217 ## Set the current study
218 def SetCurrentStudy( self, theStudy ):
219 #self.SetCurrentStudy(theStudy)
220 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
222 ## Get the current study
223 def GetCurrentStudy(self):
224 #return self.GetCurrentStudy()
225 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
227 ## Create Mesh object importing data from given UNV file
228 # @return an instance of Mesh class
229 def CreateMeshesFromUNV( self,theFileName ):
230 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
231 aMesh = Mesh(self,self.geompyD,aSmeshMesh)
234 ## Create Mesh object(s) importing data from given MED file
235 # @return a list of Mesh class instances
236 def CreateMeshesFromMED( self,theFileName ):
237 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
239 for iMesh in range(len(aSmeshMeshes)) :
240 aMesh = Mesh(self,self.geompyD,aSmeshMeshes[iMesh])
241 aMeshes.append(aMesh)
242 return aMeshes, aStatus
244 ## Create Mesh object importing data from given STL file
245 # @return an instance of Mesh class
246 def CreateMeshesFromSTL( self, theFileName ):
247 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
248 aMesh = Mesh(self,self.geompyD,aSmeshMesh)
251 ## From SMESH_Gen interface
252 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
253 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
255 ## From SMESH_Gen interface. Creates pattern
256 def GetPattern(self):
257 return SMESH._objref_SMESH_Gen.GetPattern(self)
261 # Filtering. Auxiliary functions:
262 # ------------------------------
264 ## Creates an empty criterion
265 # @return SMESH.Filter.Criterion
266 def GetEmptyCriterion(self):
267 Type = self.EnumToLong(FT_Undefined)
268 Compare = self.EnumToLong(FT_Undefined)
272 UnaryOp = self.EnumToLong(FT_Undefined)
273 BinaryOp = self.EnumToLong(FT_Undefined)
276 Precision = -1 ##@1e-07
277 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
278 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
280 ## Creates a criterion by given parameters
281 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
282 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
283 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
284 # @param Treshold is threshold value (range of ids as string, shape, numeric)
285 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
286 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
287 # FT_Undefined(must be for the last criterion in criteria)
288 # @return SMESH.Filter.Criterion
289 def GetCriterion(self,elementType,
291 Compare = FT_EqualTo,
293 UnaryOp=FT_Undefined,
294 BinaryOp=FT_Undefined):
295 aCriterion = self.GetEmptyCriterion()
296 aCriterion.TypeOfElement = elementType
297 aCriterion.Type = self.EnumToLong(CritType)
301 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
302 aCriterion.Compare = self.EnumToLong(Compare)
303 elif Compare == "=" or Compare == "==":
304 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
306 aCriterion.Compare = self.EnumToLong(FT_LessThan)
308 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
310 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
313 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
314 FT_BelongToCylinder, FT_LyingOnGeom]:
316 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
317 aCriterion.ThresholdStr = GetName(aTreshold)
318 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
320 print "Error: Treshold should be a shape."
322 elif CritType == FT_RangeOfIds:
324 if isinstance(aTreshold, str):
325 aCriterion.ThresholdStr = aTreshold
327 print "Error: Treshold should be a string."
329 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
330 # Here we don't need treshold
331 if aTreshold == FT_LogicalNOT:
332 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
333 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
334 aCriterion.BinaryOp = aTreshold
338 aTreshold = float(aTreshold)
339 aCriterion.Threshold = aTreshold
341 print "Error: Treshold should be a number."
344 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
345 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
347 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
348 aCriterion.BinaryOp = self.EnumToLong(Treshold)
350 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
351 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
353 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
354 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
358 ## Creates filter by given parameters of criterion
359 # @param elementType is the type of elements in the group
360 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
361 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
362 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
363 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
364 # @return SMESH_Filter
365 def GetFilter(self,elementType,
366 CritType=FT_Undefined,
369 UnaryOp=FT_Undefined):
370 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
371 aFilterMgr = self.CreateFilterManager()
372 aFilter = aFilterMgr.CreateFilter()
374 aCriteria.append(aCriterion)
375 aFilter.SetCriteria(aCriteria)
378 ## Creates numerical functor by its type
379 # @param theCrierion is FT_...; functor type
380 # @return SMESH_NumericalFunctor
381 def GetFunctor(self,theCriterion):
382 aFilterMgr = self.CreateFilterManager()
383 if theCriterion == FT_AspectRatio:
384 return aFilterMgr.CreateAspectRatio()
385 elif theCriterion == FT_AspectRatio3D:
386 return aFilterMgr.CreateAspectRatio3D()
387 elif theCriterion == FT_Warping:
388 return aFilterMgr.CreateWarping()
389 elif theCriterion == FT_MinimumAngle:
390 return aFilterMgr.CreateMinimumAngle()
391 elif theCriterion == FT_Taper:
392 return aFilterMgr.CreateTaper()
393 elif theCriterion == FT_Skew:
394 return aFilterMgr.CreateSkew()
395 elif theCriterion == FT_Area:
396 return aFilterMgr.CreateArea()
397 elif theCriterion == FT_Volume3D:
398 return aFilterMgr.CreateVolume3D()
399 elif theCriterion == FT_MultiConnection:
400 return aFilterMgr.CreateMultiConnection()
401 elif theCriterion == FT_MultiConnection2D:
402 return aFilterMgr.CreateMultiConnection2D()
403 elif theCriterion == FT_Length:
404 return aFilterMgr.CreateLength()
405 elif theCriterion == FT_Length2D:
406 return aFilterMgr.CreateLength2D()
408 print "Error: given parameter is not numerucal functor type."
411 #Register the new proxy for SMESH_Gen
412 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
415 ## Mother class to define algorithm, recommended to don't use directly.
418 class Mesh_Algorithm:
419 # @class Mesh_Algorithm
420 # @brief Class Mesh_Algorithm
424 #def __init__(self,smesh):
432 def FindHypothesis(self,hypname, args):
433 key = "%s %s %s" % (self.__class__.__name__, hypname, args)
434 if Mesh_Algorithm.hypos.has_key( key ):
435 return Mesh_Algorithm.hypos[ key ]
438 ## If the algorithm is global, return 0; \n
439 # else return the submesh associated to this algorithm.
440 def GetSubMesh(self):
443 ## Return the wrapped mesher.
444 def GetAlgorithm(self):
447 ## Get list of hypothesis that can be used with this algorithm
448 def GetCompatibleHypothesis(self):
451 mylist = self.algo.GetCompatibleHypothesis()
459 def SetName(self, name):
460 SetName(self.algo, name)
464 return self.algo.GetId()
467 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
469 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
470 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
471 self.Assign(algo, mesh, geom)
475 def Assign(self, algo, mesh, geom):
477 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
486 name = mesh.geompyD.SubShapeName(geom, piece)
487 mesh.geompyD.addToStudyInFather(piece, geom, name)
488 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
491 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
492 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
495 def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so", UseExisting=0):
498 hypo = self.FindHypothesis(hyp, args)
499 if hypo!=None: CreateNew = 0
502 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
503 key = "%s %s %s" % (self.__class__.__name__, hyp, args)
504 Mesh_Algorithm.hypos[key] = hypo
510 a = a + s + str(args[i])
513 name = GetName(self.geom)
514 #SetName(hypo, name + "/" + hyp + a) - NPAL16198
515 SetName(hypo, hyp + a)
517 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
518 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
522 # Public class: Mesh_Segment
523 # --------------------------
525 ## Class to define a segment 1D algorithm for discretization
528 class Mesh_Segment(Mesh_Algorithm):
530 algo = 0 # algorithm object common for all Mesh_Segment's
532 ## Private constructor.
533 def __init__(self, mesh, geom=0):
534 Mesh_Algorithm.__init__(self)
536 if not Mesh_Segment.algo:
537 Mesh_Segment.algo = self.Create(mesh, geom, "Regular_1D")
539 self.Assign( Mesh_Segment.algo, mesh, geom)
542 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
543 # @param l for the length of segments that cut an edge
544 # @param UseExisting if ==true - search existing hypothesis created with
545 # same parameters, else (default) - create new
546 def LocalLength(self, l, UseExisting=0):
547 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting)
551 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
552 # @param n for the number of segments that cut an edge
553 # @param s for the scale factor (optional)
554 # @param UseExisting if ==true - search existing hypothesis created with
555 # same parameters, else (default) - create new
556 def NumberOfSegments(self, n, s=[], UseExisting=0):
558 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting)
560 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting)
561 hyp.SetDistrType( 1 )
562 hyp.SetScaleFactor(s)
563 hyp.SetNumberOfSegments(n)
566 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
567 # @param start for the length of the first segment
568 # @param end for the length of the last segment
569 # @param UseExisting if ==true - search existing hypothesis created with
570 # same parameters, else (default) - create new
571 def Arithmetic1D(self, start, end, UseExisting=0):
572 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting)
573 hyp.SetLength(start, 1)
574 hyp.SetLength(end , 0)
577 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
578 # @param start for the length of the first segment
579 # @param end for the length of the last segment
580 # @param UseExisting if ==true - search existing hypothesis created with
581 # same parameters, else (default) - create new
582 def StartEndLength(self, start, end, UseExisting=0):
583 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting)
584 hyp.SetLength(start, 1)
585 hyp.SetLength(end , 0)
588 ## Define "Deflection1D" hypothesis
589 # @param d for the deflection
590 # @param UseExisting if ==true - search existing hypothesis created with
591 # same parameters, else (default) - create new
592 def Deflection1D(self, d, UseExisting=0):
593 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting)
597 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
598 # the opposite side in the case of quadrangular faces
599 def Propagation(self):
600 return self.Hypothesis("Propagation", UseExisting=1)
602 ## Define "AutomaticLength" hypothesis
603 # @param fineness for the fineness [0-1]
604 # @param UseExisting if ==true - search existing hypothesis created with
605 # same parameters, else (default) - create new
606 def AutomaticLength(self, fineness=0, UseExisting=0):
607 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting)
608 hyp.SetFineness( fineness )
611 ## Define "SegmentLengthAroundVertex" hypothesis
612 # @param length for the segment length
613 # @param vertex for the length localization: vertex index [0,1] | verext object
614 # @param UseExisting if ==true - search existing hypothesis created with
615 # same parameters, else (default) - create new
616 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
618 store_geom = self.geom
620 if type(vertex) is types.IntType:
621 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
625 hyp = self.Hypothesis("SegmentAroundVertex_0D",[length],UseExisting=UseExisting)
626 hyp = self.Hypothesis("SegmentLengthAroundVertex",[length],UseExisting=UseExisting)
627 self.geom = store_geom
628 hyp.SetLength( length )
631 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
632 # If the 2D mesher sees that all boundary edges are quadratic ones,
633 # it generates quadratic faces, else it generates linear faces using
634 # medium nodes as if they were vertex ones.
635 # The 3D mesher generates quadratic volumes only if all boundary faces
636 # are quadratic ones, else it fails.
637 def QuadraticMesh(self):
638 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1)
641 # Public class: Mesh_CompositeSegment
642 # --------------------------
644 ## Class to define a segment 1D algorithm for discretization
647 class Mesh_CompositeSegment(Mesh_Segment):
649 algo = 0 # algorithm object common for all Mesh_CompositeSegment's
651 ## Private constructor.
652 def __init__(self, mesh, geom=0):
653 if not Mesh_CompositeSegment.algo:
654 Mesh_CompositeSegment.algo = self.Create(mesh, geom, "CompositeSegment_1D")
656 self.Assign( Mesh_CompositeSegment.algo, mesh, geom)
660 # Public class: Mesh_Segment_Python
661 # ---------------------------------
663 ## Class to define a segment 1D algorithm for discretization with python function
666 class Mesh_Segment_Python(Mesh_Segment):
668 algo = 0 # algorithm object common for all Mesh_Segment_Python's
670 ## Private constructor.
671 def __init__(self, mesh, geom=0):
672 import Python1dPlugin
673 if not Mesh_Segment_Python.algo:
674 Mesh_Segment_Python.algo = self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
676 self.Assign( Mesh_Segment_Python.algo, mesh, geom)
679 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
680 # @param n for the number of segments that cut an edge
681 # @param func for the python function that calculate the length of all segments
682 # @param UseExisting if ==true - search existing hypothesis created with
683 # same parameters, else (default) - create new
684 def PythonSplit1D(self, n, func, UseExisting=0):
685 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so", UseExisting=UseExisting)
686 hyp.SetNumberOfSegments(n)
687 hyp.SetPythonLog10RatioFunction(func)
690 # Public class: Mesh_Triangle
691 # ---------------------------
693 ## Class to define a triangle 2D algorithm
696 class Mesh_Triangle(Mesh_Algorithm):
702 # algorithm objects common for all instances of Mesh_Triangle
707 ## Private constructor.
708 def __init__(self, mesh, algoType, geom=0):
709 Mesh_Algorithm.__init__(self)
711 if algoType == MEFISTO:
712 if not Mesh_Triangle.algoMEF:
713 Mesh_Triangle.algoMEF = self.Create(mesh, geom, "MEFISTO_2D")
715 self.Assign( Mesh_Triangle.algoMEF, mesh, geom)
718 elif algoType == NETGEN:
720 print "Warning: NETGENPlugin module unavailable"
722 if not Mesh_Triangle.algoNET:
723 Mesh_Triangle.algoNET = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
725 self.Assign( Mesh_Triangle.algoNET, mesh, geom)
728 elif algoType == NETGEN_2D:
730 print "Warning: NETGENPlugin module unavailable"
732 if not Mesh_Triangle.algoNET_2D:
733 Mesh_Triangle.algoNET_2D = self.Create(mesh, geom,
734 "NETGEN_2D_ONLY", "libNETGENEngine.so")
736 self.Assign( Mesh_Triangle.algoNET_2D, mesh, geom)
740 self.algoType = algoType
742 ## Define "MaxElementArea" hypothesis to give the maximun area of each triangles
743 # @param area for the maximum area of each triangles
744 # @param UseExisting if ==true - search existing hypothesis created with
745 # same parameters, else (default) - create new
747 # Only for algoType == MEFISTO || NETGEN_2D
748 def MaxElementArea(self, area, UseExisting=0):
749 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
750 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting)
751 hyp.SetMaxElementArea(area)
753 elif self.algoType == NETGEN:
754 print "Netgen 1D-2D algo doesn't support this hypothesis"
757 ## Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
759 # Only for algoType == MEFISTO || NETGEN_2D
760 def LengthFromEdges(self):
761 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
762 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1)
764 elif self.algoType == NETGEN:
765 print "Netgen 1D-2D algo doesn't support this hypothesis"
768 ## Set QuadAllowed flag
770 # Only for algoType == NETGEN || NETGEN_2D
771 def SetQuadAllowed(self, toAllow=True):
772 if self.algoType == NETGEN_2D:
773 if toAllow: # add QuadranglePreference
774 self.Hypothesis("QuadranglePreference", UseExisting=1)
775 else: # remove QuadranglePreference
776 for hyp in self.mesh.GetHypothesisList( self.geom ):
777 if hyp.GetName() == "QuadranglePreference":
778 self.mesh.RemoveHypothesis( self.geom, hyp )
783 if self.params == 0 and self.Parameters():
784 self.params.SetQuadAllowed(toAllow)
787 ## Define "Netgen 2D Parameters" hypothesis
789 # Only for algoType == NETGEN
790 def Parameters(self):
791 if self.algoType == NETGEN:
792 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
793 "libNETGENEngine.so", UseExisting=0)
795 elif self.algoType == MEFISTO:
796 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
798 elif self.algoType == NETGEN_2D:
799 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
800 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
806 # Only for algoType == NETGEN
807 def SetMaxSize(self, theSize):
808 if self.params == 0 and self.Parameters():
809 self.params.SetMaxSize(theSize)
811 ## Set SecondOrder flag
813 # Only for algoType == NETGEN
814 def SetSecondOrder(self, theVal):
815 if self.params == 0 and self.Parameters():
816 self.params.SetSecondOrder(theVal)
821 # Only for algoType == NETGEN
822 def SetOptimize(self, theVal):
823 if self.params == 0 and self.Parameters():
824 self.params.SetOptimize(theVal)
827 # @param theFineness is:
828 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
830 # Only for algoType == NETGEN
831 def SetFineness(self, theFineness):
832 if self.params == 0 and self.Parameters():
833 self.params.SetFineness(theFineness)
837 # Only for algoType == NETGEN
838 def SetGrowthRate(self, theRate):
839 if self.params == 0 and self.Parameters():
840 self.params.SetGrowthRate(theRate)
844 # Only for algoType == NETGEN
845 def SetNbSegPerEdge(self, theVal):
846 if self.params == 0 and self.Parameters():
847 self.params.SetNbSegPerEdge(theVal)
849 ## Set NbSegPerRadius
851 # Only for algoType == NETGEN
852 def SetNbSegPerRadius(self, theVal):
853 if self.params == 0 and self.Parameters():
854 self.params.SetNbSegPerRadius(theVal)
859 # Public class: Mesh_Quadrangle
860 # -----------------------------
862 ## Class to define a quadrangle 2D algorithm
865 class Mesh_Quadrangle(Mesh_Algorithm):
867 algo = 0 # algorithm object common for all Mesh_Quadrangle's
869 ## Private constructor.
870 def __init__(self, mesh, geom=0):
871 Mesh_Algorithm.__init__(self)
873 if not Mesh_Quadrangle.algo:
874 Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
876 self.Assign( Mesh_Quadrangle.algo, mesh, geom)
879 ## Define "QuadranglePreference" hypothesis, forcing construction
880 # of quadrangles if the number of nodes on opposite edges is not the same
881 # in the case where the global number of nodes on edges is even
882 def QuadranglePreference(self):
883 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
886 # Public class: Mesh_Tetrahedron
887 # ------------------------------
889 ## Class to define a tetrahedron 3D algorithm
892 class Mesh_Tetrahedron(Mesh_Algorithm):
897 algoNET = 0 # algorithm object common for all Mesh_Tetrahedron's
898 algoGHS = 0 # algorithm object common for all Mesh_Tetrahedron's
899 algoFNET = 0 # algorithm object common for all Mesh_Tetrahedron's
901 ## Private constructor.
902 def __init__(self, mesh, algoType, geom=0):
903 Mesh_Algorithm.__init__(self)
905 if algoType == NETGEN:
906 if not Mesh_Tetrahedron.algoNET:
907 Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
909 self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
913 elif algoType == GHS3D:
914 if not Mesh_Tetrahedron.algoGHS:
916 Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
918 self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
922 elif algoType == FULL_NETGEN:
924 print "Warning: NETGENPlugin module has not been imported."
925 if not Mesh_Tetrahedron.algoFNET:
926 Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
928 self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
932 self.algoType = algoType
934 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
935 # @param vol for the maximum volume of each tetrahedral
936 # @param UseExisting if ==true - search existing hypothesis created with
937 # same parameters, else (default) - create new
938 def MaxElementVolume(self, vol, UseExisting=0):
939 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
940 hyp.SetMaxElementVolume(vol)
943 ## Define "Netgen 3D Parameters" hypothesis
944 def Parameters(self):
945 if (self.algoType == FULL_NETGEN):
946 self.params = self.Hypothesis("NETGEN_Parameters", [],
947 "libNETGENEngine.so", UseExisting=0)
950 print "Algo doesn't support this hypothesis"
954 def SetMaxSize(self, theSize):
957 self.params.SetMaxSize(theSize)
959 ## Set SecondOrder flag
960 def SetSecondOrder(self, theVal):
963 self.params.SetSecondOrder(theVal)
966 def SetOptimize(self, theVal):
969 self.params.SetOptimize(theVal)
972 # @param theFineness is:
973 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
974 def SetFineness(self, theFineness):
977 self.params.SetFineness(theFineness)
980 def SetGrowthRate(self, theRate):
983 self.params.SetGrowthRate(theRate)
986 def SetNbSegPerEdge(self, theVal):
989 self.params.SetNbSegPerEdge(theVal)
991 ## Set NbSegPerRadius
992 def SetNbSegPerRadius(self, theVal):
995 self.params.SetNbSegPerRadius(theVal)
997 # Public class: Mesh_Hexahedron
998 # ------------------------------
1000 ## Class to define a hexahedron 3D algorithm
1003 class Mesh_Hexahedron(Mesh_Algorithm):
1005 algo = 0 # algorithm object common for all Mesh_Hexahedron's
1007 ## Private constructor.
1008 def __init__(self, mesh, geom=0):
1009 Mesh_Algorithm.__init__(self)
1011 if not Mesh_Hexahedron.algo:
1012 Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
1014 self.Assign( Mesh_Hexahedron.algo, mesh, geom)
1017 # Deprecated, only for compatibility!
1018 # Public class: Mesh_Netgen
1019 # ------------------------------
1021 ## Class to define a NETGEN-based 2D or 3D algorithm
1022 # that need no discrete boundary (i.e. independent)
1024 # This class is deprecated, only for compatibility!
1027 class Mesh_Netgen(Mesh_Algorithm):
1031 algoNET23 = 0 # algorithm object common for all Mesh_Netgen's
1032 algoNET2 = 0 # algorithm object common for all Mesh_Netgen's
1034 ## Private constructor.
1035 def __init__(self, mesh, is3D, geom=0):
1036 Mesh_Algorithm.__init__(self)
1039 print "Warning: NETGENPlugin module has not been imported."
1043 if not Mesh_Netgen.algoNET23:
1044 Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1046 self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1051 if not Mesh_Netgen.algoNET2:
1052 Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1054 self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1058 ## Define hypothesis containing parameters of the algorithm
1059 def Parameters(self):
1061 hyp = self.Hypothesis("NETGEN_Parameters", [],
1062 "libNETGENEngine.so", UseExisting=0)
1064 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1065 "libNETGENEngine.so", UseExisting=0)
1068 # Public class: Mesh_Projection1D
1069 # ------------------------------
1071 ## Class to define a projection 1D algorithm
1074 class Mesh_Projection1D(Mesh_Algorithm):
1076 algo = 0 # algorithm object common for all Mesh_Projection1D's
1078 ## Private constructor.
1079 def __init__(self, mesh, geom=0):
1080 Mesh_Algorithm.__init__(self)
1082 if not Mesh_Projection1D.algo:
1083 Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1085 self.Assign( Mesh_Projection1D.algo, mesh, geom)
1088 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1089 # take a mesh pattern from, and optionally association of vertices
1090 # between the source edge and a target one (where a hipothesis is assigned to)
1091 # @param edge to take nodes distribution from
1092 # @param mesh to take nodes distribution from (optional)
1093 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1094 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1095 # to associate with \a srcV (optional)
1096 # @param UseExisting if ==true - search existing hypothesis created with
1097 # same parameters, else (default) - create new
1098 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1099 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1100 hyp.SetSourceEdge( edge )
1101 if not mesh is None and isinstance(mesh, Mesh):
1102 mesh = mesh.GetMesh()
1103 hyp.SetSourceMesh( mesh )
1104 hyp.SetVertexAssociation( srcV, tgtV )
1108 # Public class: Mesh_Projection2D
1109 # ------------------------------
1111 ## Class to define a projection 2D algorithm
1114 class Mesh_Projection2D(Mesh_Algorithm):
1116 algo = 0 # algorithm object common for all Mesh_Projection2D's
1118 ## Private constructor.
1119 def __init__(self, mesh, geom=0):
1120 Mesh_Algorithm.__init__(self)
1122 if not Mesh_Projection2D.algo:
1123 Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1125 self.Assign( Mesh_Projection2D.algo, mesh, geom)
1128 ## Define "Source Face" hypothesis, specifying a meshed face to
1129 # take a mesh pattern from, and optionally association of vertices
1130 # between the source face and a target one (where a hipothesis is assigned to)
1131 # @param face to take mesh pattern from
1132 # @param mesh to take mesh pattern from (optional)
1133 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1134 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1135 # to associate with \a srcV1 (optional)
1136 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1137 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1138 # to associate with \a srcV2 (optional)
1139 # @param UseExisting if ==true - search existing hypothesis created with
1140 # same parameters, else (default) - create new
1142 # Note: association vertices must belong to one edge of a face
1143 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1144 srcV2=None, tgtV2=None, UseExisting=0):
1145 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1146 UseExisting=UseExisting)
1147 hyp.SetSourceFace( face )
1148 if not mesh is None and isinstance(mesh, Mesh):
1149 mesh = mesh.GetMesh()
1150 hyp.SetSourceMesh( mesh )
1151 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1154 # Public class: Mesh_Projection3D
1155 # ------------------------------
1157 ## Class to define a projection 3D algorithm
1160 class Mesh_Projection3D(Mesh_Algorithm):
1162 algo = 0 # algorithm object common for all Mesh_Projection3D's
1164 ## Private constructor.
1165 def __init__(self, mesh, geom=0):
1166 Mesh_Algorithm.__init__(self)
1168 if not Mesh_Projection3D.algo:
1169 Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1171 self.Assign( Mesh_Projection3D.algo, mesh, geom)
1174 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1175 # take a mesh pattern from, and optionally association of vertices
1176 # between the source solid and a target one (where a hipothesis is assigned to)
1177 # @param solid to take mesh pattern from
1178 # @param mesh to take mesh pattern from (optional)
1179 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1180 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1181 # to associate with \a srcV1 (optional)
1182 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1183 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1184 # to associate with \a srcV2 (optional)
1185 # @param UseExisting - if ==true - search existing hypothesis created with
1186 # same parameters, else (default) - create new
1188 # Note: association vertices must belong to one edge of a solid
1189 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1190 srcV2=0, tgtV2=0, UseExisting=0):
1191 hyp = self.Hypothesis("ProjectionSource3D",
1192 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1193 UseExisting=UseExisting)
1194 hyp.SetSource3DShape( solid )
1195 if not mesh is None and isinstance(mesh, Mesh):
1196 mesh = mesh.GetMesh()
1197 hyp.SetSourceMesh( mesh )
1198 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1202 # Public class: Mesh_Prism
1203 # ------------------------
1205 ## Class to define a 3D extrusion algorithm
1208 class Mesh_Prism3D(Mesh_Algorithm):
1210 algo = 0 # algorithm object common for all Mesh_Prism3D's
1212 ## Private constructor.
1213 def __init__(self, mesh, geom=0):
1214 Mesh_Algorithm.__init__(self)
1216 if not Mesh_Prism3D.algo:
1217 Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1219 self.Assign( Mesh_Prism3D.algo, mesh, geom)
1222 # Public class: Mesh_RadialPrism
1223 # -------------------------------
1225 ## Class to define a Radial Prism 3D algorithm
1228 class Mesh_RadialPrism3D(Mesh_Algorithm):
1230 algo = 0 # algorithm object common for all Mesh_RadialPrism3D's
1232 ## Private constructor.
1233 def __init__(self, mesh, geom=0):
1234 Mesh_Algorithm.__init__(self)
1236 if not Mesh_RadialPrism3D.algo:
1237 Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1239 self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1241 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1242 self.nbLayers = None
1244 ## Return 3D hypothesis holding the 1D one
1245 def Get3DHypothesis(self):
1246 return self.distribHyp
1248 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1249 # hypothes. Returns the created hypothes
1250 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1251 print "OwnHypothesis",hypType
1252 if not self.nbLayers is None:
1253 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1254 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1255 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
1256 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1257 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
1258 self.distribHyp.SetLayerDistribution( hyp )
1261 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1262 # prisms to build between the inner and outer shells
1263 # @param UseExisting if ==true - search existing hypothesis created with
1264 # same parameters, else (default) - create new
1265 def NumberOfLayers(self, n, UseExisting=0):
1266 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1267 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1268 self.nbLayers.SetNumberOfLayers( n )
1269 return self.nbLayers
1271 ## Define "LocalLength" hypothesis, specifying segment length
1272 # to build between the inner and outer shells
1273 # @param l for the length of segments
1274 def LocalLength(self, l):
1275 hyp = self.OwnHypothesis("LocalLength", [l] )
1279 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1280 # prisms to build between the inner and outer shells
1281 # @param n for the number of segments
1282 # @param s for the scale factor (optional)
1283 def NumberOfSegments(self, n, s=[]):
1285 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1287 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1288 hyp.SetDistrType( 1 )
1289 hyp.SetScaleFactor(s)
1290 hyp.SetNumberOfSegments(n)
1293 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1294 # to build between the inner and outer shells as arithmetic length increasing
1295 # @param start for the length of the first segment
1296 # @param end for the length of the last segment
1297 def Arithmetic1D(self, start, end ):
1298 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1299 hyp.SetLength(start, 1)
1300 hyp.SetLength(end , 0)
1303 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1304 # to build between the inner and outer shells as geometric length increasing
1305 # @param start for the length of the first segment
1306 # @param end for the length of the last segment
1307 def StartEndLength(self, start, end):
1308 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1309 hyp.SetLength(start, 1)
1310 hyp.SetLength(end , 0)
1313 ## Define "AutomaticLength" hypothesis, specifying number of segments
1314 # to build between the inner and outer shells
1315 # @param fineness for the fineness [0-1]
1316 def AutomaticLength(self, fineness=0):
1317 hyp = self.OwnHypothesis("AutomaticLength")
1318 hyp.SetFineness( fineness )
1322 # Public class: Mesh
1323 # ==================
1325 ## Class to define a mesh
1327 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1337 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1338 # sets GUI name of this mesh to \a name.
1339 # @param obj Shape to be meshed or SMESH_Mesh object
1340 # @param name Study name of the mesh
1341 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1342 self.smeshpyD=smeshpyD
1343 self.geompyD=geompyD
1347 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1349 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1350 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1353 self.mesh = self.smeshpyD.CreateEmptyMesh()
1355 SetName(self.mesh, name)
1357 SetName(self.mesh, GetName(obj))
1359 self.editor = self.mesh.GetMeshEditor()
1361 ## Method that inits the Mesh object from SMESH_Mesh interface
1362 # @param theMesh is SMESH_Mesh object
1363 def SetMesh(self, theMesh):
1365 self.geom = self.mesh.GetShapeToMesh()
1367 ## Method that returns the mesh
1368 # @return SMESH_Mesh object
1374 name = GetName(self.GetMesh())
1378 def SetName(self, name):
1379 SetName(self.GetMesh(), name)
1381 ## Get the subMesh object associated to a subShape. The subMesh object
1382 # gives access to nodes and elements IDs.
1383 # \n SubMesh will be used instead of SubShape in a next idl version to
1384 # adress a specific subMesh...
1385 def GetSubMesh(self, theSubObject, name):
1386 submesh = self.mesh.GetSubMesh(theSubObject, name)
1389 ## Method that returns the shape associated to the mesh
1390 # @return GEOM_Object
1394 ## Method that associates given shape to the mesh(entails the mesh recreation)
1395 # @param geom shape to be meshed(GEOM_Object)
1396 def SetShape(self, geom):
1397 self.mesh = self.smeshpyD.CreateMesh(geom)
1399 ## Return true if hypotheses are defined well
1400 # @param theMesh is an instance of Mesh class
1401 # @param theSubObject subshape of a mesh shape
1402 def IsReadyToCompute(self, theSubObject):
1403 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1405 ## Return errors of hypotheses definintion
1406 # error list is empty if everything is OK
1407 # @param theMesh is an instance of Mesh class
1408 # @param theSubObject subshape of a mesh shape
1409 # @return a list of errors
1410 def GetAlgoState(self, theSubObject):
1411 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1413 ## Return geometrical object the given element is built on.
1414 # The returned geometrical object, if not nil, is either found in the
1415 # study or is published by this method with the given name
1416 # @param theMesh is an instance of Mesh class
1417 # @param theElementID an id of the mesh element
1418 # @param theGeomName user defined name of geometrical object
1419 # @return GEOM::GEOM_Object instance
1420 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1421 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1423 ## Returns mesh dimension depending on shape one
1424 def MeshDimension(self):
1425 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1426 if len( shells ) > 0 :
1428 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1430 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1436 ## Creates a segment discretization 1D algorithm.
1437 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1438 # If the optional \a geom parameter is not sets, this algorithm is global.
1439 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1440 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1441 # @param geom If defined, subshape to be meshed
1442 def Segment(self, algo=REGULAR, geom=0):
1443 ## if Segment(geom) is called by mistake
1444 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1445 algo, geom = geom, algo
1446 if not algo: algo = REGULAR
1449 return Mesh_Segment(self, geom)
1450 elif algo == PYTHON:
1451 return Mesh_Segment_Python(self, geom)
1452 elif algo == COMPOSITE:
1453 return Mesh_CompositeSegment(self, geom)
1455 return Mesh_Segment(self, geom)
1457 ## Creates a triangle 2D algorithm for faces.
1458 # If the optional \a geom parameter is not sets, this algorithm is global.
1459 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1460 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1461 # @param geom If defined, subshape to be meshed
1462 def Triangle(self, algo=MEFISTO, geom=0):
1463 ## if Triangle(geom) is called by mistake
1464 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1468 return Mesh_Triangle(self, algo, geom)
1470 ## Creates a quadrangle 2D algorithm for faces.
1471 # If the optional \a geom parameter is not sets, this algorithm is global.
1472 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1473 # @param geom If defined, subshape to be meshed
1474 def Quadrangle(self, geom=0):
1475 return Mesh_Quadrangle(self, geom)
1477 ## Creates a tetrahedron 3D algorithm for solids.
1478 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1479 # If the optional \a geom parameter is not sets, this algorithm is global.
1480 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1481 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1482 # @param geom If defined, subshape to be meshed
1483 def Tetrahedron(self, algo=NETGEN, geom=0):
1484 ## if Tetrahedron(geom) is called by mistake
1485 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1486 algo, geom = geom, algo
1487 if not algo: algo = NETGEN
1489 return Mesh_Tetrahedron(self, algo, geom)
1491 ## Creates a hexahedron 3D algorithm for solids.
1492 # If the optional \a geom parameter is not sets, this algorithm is global.
1493 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1494 # @param geom If defined, subshape to be meshed
1495 def Hexahedron(self, geom=0):
1496 return Mesh_Hexahedron(self, geom)
1498 ## Deprecated, only for compatibility!
1499 def Netgen(self, is3D, geom=0):
1500 return Mesh_Netgen(self, is3D, geom)
1502 ## Creates a projection 1D algorithm for edges.
1503 # If the optional \a geom parameter is not sets, this algorithm is global.
1504 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1505 # @param geom If defined, subshape to be meshed
1506 def Projection1D(self, geom=0):
1507 return Mesh_Projection1D(self, geom)
1509 ## Creates a projection 2D algorithm for faces.
1510 # If the optional \a geom parameter is not sets, this algorithm is global.
1511 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1512 # @param geom If defined, subshape to be meshed
1513 def Projection2D(self, geom=0):
1514 return Mesh_Projection2D(self, geom)
1516 ## Creates a projection 3D algorithm for solids.
1517 # If the optional \a geom parameter is not sets, this algorithm is global.
1518 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1519 # @param geom If defined, subshape to be meshed
1520 def Projection3D(self, geom=0):
1521 return Mesh_Projection3D(self, geom)
1523 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1524 # If the optional \a geom parameter is not sets, this algorithm is global.
1525 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1526 # @param geom If defined, subshape to be meshed
1527 def Prism(self, geom=0):
1531 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
1532 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
1533 if nbSolids == 0 or nbSolids == nbShells:
1534 return Mesh_Prism3D(self, geom)
1535 return Mesh_RadialPrism3D(self, geom)
1537 ## Compute the mesh and return the status of the computation
1538 def Compute(self, geom=0):
1539 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1541 print "Compute impossible: mesh is not constructed on geom shape."
1547 ok = self.smeshpyD.Compute(self.mesh, geom)
1548 except SALOME.SALOME_Exception, ex:
1549 print "Mesh computation failed, exception caught:"
1550 print " ", ex.details.text
1553 print "Mesh computation failed, exception caught:"
1554 traceback.print_exc()
1556 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1559 if err.isGlobalAlgo:
1567 reason = '%s %sD algorithm is missing' % (glob, dim)
1568 elif err.state == HYP_MISSING:
1569 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1570 % (glob, dim, name, dim))
1571 elif err.state == HYP_NOTCONFORM:
1572 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1573 elif err.state == HYP_BAD_PARAMETER:
1574 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1575 % ( glob, dim, name ))
1576 elif err.state == HYP_BAD_GEOMETRY:
1577 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1578 'its expectation' % ( glob, dim, name ))
1580 reason = "For unknown reason."+\
1581 " Revise Mesh.Compute() implementation in smesh.py!"
1583 if allReasons != "":
1586 allReasons += reason
1588 if allReasons != "":
1589 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1592 print '"' + GetName(self.mesh) + '"',"has not been computed."
1595 if salome.sg.hasDesktop():
1596 smeshgui = salome.ImportComponentGUI("SMESH")
1597 smeshgui.Init(salome.myStudyId)
1598 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1599 salome.sg.updateObjBrowser(1)
1603 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1604 # The parameter \a fineness [0,-1] defines mesh fineness
1605 def AutomaticTetrahedralization(self, fineness=0):
1606 dim = self.MeshDimension()
1608 self.RemoveGlobalHypotheses()
1609 self.Segment().AutomaticLength(fineness)
1611 self.Triangle().LengthFromEdges()
1614 self.Tetrahedron(NETGEN)
1616 return self.Compute()
1618 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1619 # The parameter \a fineness [0,-1] defines mesh fineness
1620 def AutomaticHexahedralization(self, fineness=0):
1621 dim = self.MeshDimension()
1623 self.RemoveGlobalHypotheses()
1624 self.Segment().AutomaticLength(fineness)
1631 return self.Compute()
1633 ## Assign hypothesis
1634 # @param hyp is a hypothesis to assign
1635 # @param geom is subhape of mesh geometry
1636 def AddHypothesis(self, hyp, geom=0 ):
1637 if isinstance( hyp, Mesh_Algorithm ):
1638 hyp = hyp.GetAlgorithm()
1643 status = self.mesh.AddHypothesis(geom, hyp)
1644 isAlgo = hyp._narrow( SMESH_Algo )
1645 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1648 ## Unassign hypothesis
1649 # @param hyp is a hypothesis to unassign
1650 # @param geom is subhape of mesh geometry
1651 def RemoveHypothesis(self, hyp, geom=0 ):
1652 if isinstance( hyp, Mesh_Algorithm ):
1653 hyp = hyp.GetAlgorithm()
1658 status = self.mesh.RemoveHypothesis(geom, hyp)
1661 ## Get the list of hypothesis added on a geom
1662 # @param geom is subhape of mesh geometry
1663 def GetHypothesisList(self, geom):
1664 return self.mesh.GetHypothesisList( geom )
1666 ## Removes all global hypotheses
1667 def RemoveGlobalHypotheses(self):
1668 current_hyps = self.mesh.GetHypothesisList( self.geom )
1669 for hyp in current_hyps:
1670 self.mesh.RemoveHypothesis( self.geom, hyp )
1674 ## Create a mesh group based on geometric object \a grp
1675 # and give a \a name, \n if this parameter is not defined
1676 # the name is the same as the geometric group name \n
1677 # Note: Works like GroupOnGeom().
1678 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1679 # @param name is the name of the mesh group
1680 # @return SMESH_GroupOnGeom
1681 def Group(self, grp, name=""):
1682 return self.GroupOnGeom(grp, name)
1684 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1685 # Export the mesh in a file with the MED format and choice the \a version of MED format
1686 # @param f is the file name
1687 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1688 def ExportToMED(self, f, version, opt=0):
1689 self.mesh.ExportToMED(f, opt, version)
1691 ## Export the mesh in a file with the MED format
1692 # @param f is the file name
1693 # @param auto_groups boolean parameter for creating/not creating
1694 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1695 # the typical use is auto_groups=false.
1696 # @param version MED format version(MED_V2_1 or MED_V2_2)
1697 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1698 self.mesh.ExportToMED(f, auto_groups, version)
1700 ## Export the mesh in a file with the DAT format
1701 # @param f is the file name
1702 def ExportDAT(self, f):
1703 self.mesh.ExportDAT(f)
1705 ## Export the mesh in a file with the UNV format
1706 # @param f is the file name
1707 def ExportUNV(self, f):
1708 self.mesh.ExportUNV(f)
1710 ## Export the mesh in a file with the STL format
1711 # @param f is the file name
1712 # @param ascii defined the kind of file contents
1713 def ExportSTL(self, f, ascii=1):
1714 self.mesh.ExportSTL(f, ascii)
1717 # Operations with groups:
1718 # ----------------------
1720 ## Creates an empty mesh group
1721 # @param elementType is the type of elements in the group
1722 # @param name is the name of the mesh group
1723 # @return SMESH_Group
1724 def CreateEmptyGroup(self, elementType, name):
1725 return self.mesh.CreateGroup(elementType, name)
1727 ## Creates a mesh group based on geometric object \a grp
1728 # and give a \a name, \n if this parameter is not defined
1729 # the name is the same as the geometric group name
1730 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1731 # @param name is the name of the mesh group
1732 # @return SMESH_GroupOnGeom
1733 def GroupOnGeom(self, grp, name="", typ=None):
1735 name = grp.GetName()
1738 tgeo = str(grp.GetShapeType())
1739 if tgeo == "VERTEX":
1741 elif tgeo == "EDGE":
1743 elif tgeo == "FACE":
1745 elif tgeo == "SOLID":
1747 elif tgeo == "SHELL":
1749 elif tgeo == "COMPOUND":
1750 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1751 print "Mesh.Group: empty geometric group", GetName( grp )
1753 tgeo = self.geompyD.GetType(grp)
1754 if tgeo == geompyDC.ShapeType["VERTEX"]:
1756 elif tgeo == geompyDC.ShapeType["EDGE"]:
1758 elif tgeo == geompyDC.ShapeType["FACE"]:
1760 elif tgeo == geompyDC.ShapeType["SOLID"]:
1764 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1767 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1769 ## Create a mesh group by the given ids of elements
1770 # @param groupName is the name of the mesh group
1771 # @param elementType is the type of elements in the group
1772 # @param elemIDs is the list of ids
1773 # @return SMESH_Group
1774 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1775 group = self.mesh.CreateGroup(elementType, groupName)
1779 ## Create a mesh group by the given conditions
1780 # @param groupName is the name of the mesh group
1781 # @param elementType is the type of elements in the group
1782 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1783 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1784 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1785 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1786 # @return SMESH_Group
1790 CritType=FT_Undefined,
1793 UnaryOp=FT_Undefined):
1794 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1795 group = self.MakeGroupByCriterion(groupName, aCriterion)
1798 ## Create a mesh group by the given criterion
1799 # @param groupName is the name of the mesh group
1800 # @param Criterion is the instance of Criterion class
1801 # @return SMESH_Group
1802 def MakeGroupByCriterion(self, groupName, Criterion):
1803 aFilterMgr = self.smeshpyD.CreateFilterManager()
1804 aFilter = aFilterMgr.CreateFilter()
1806 aCriteria.append(Criterion)
1807 aFilter.SetCriteria(aCriteria)
1808 group = self.MakeGroupByFilter(groupName, aFilter)
1811 ## Create a mesh group by the given criteria(list of criterions)
1812 # @param groupName is the name of the mesh group
1813 # @param Criteria is the list of criterions
1814 # @return SMESH_Group
1815 def MakeGroupByCriteria(self, groupName, theCriteria):
1816 aFilterMgr = self.smeshpyD.CreateFilterManager()
1817 aFilter = aFilterMgr.CreateFilter()
1818 aFilter.SetCriteria(theCriteria)
1819 group = self.MakeGroupByFilter(groupName, aFilter)
1822 ## Create a mesh group by the given filter
1823 # @param groupName is the name of the mesh group
1824 # @param Criterion is the instance of Filter class
1825 # @return SMESH_Group
1826 def MakeGroupByFilter(self, groupName, theFilter):
1827 anIds = theFilter.GetElementsId(self.mesh)
1828 anElemType = theFilter.GetElementType()
1829 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1832 ## Pass mesh elements through the given filter and return ids
1833 # @param theFilter is SMESH_Filter
1834 # @return list of ids
1835 def GetIdsFromFilter(self, theFilter):
1836 return theFilter.GetElementsId(self.mesh)
1838 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1839 # Returns list of special structures(borders).
1840 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1841 def GetFreeBorders(self):
1842 aFilterMgr = self.smeshpyD.CreateFilterManager()
1843 aPredicate = aFilterMgr.CreateFreeEdges()
1844 aPredicate.SetMesh(self.mesh)
1845 aBorders = aPredicate.GetBorders()
1849 def RemoveGroup(self, group):
1850 self.mesh.RemoveGroup(group)
1852 ## Remove group with its contents
1853 def RemoveGroupWithContents(self, group):
1854 self.mesh.RemoveGroupWithContents(group)
1856 ## Get the list of groups existing in the mesh
1857 def GetGroups(self):
1858 return self.mesh.GetGroups()
1860 ## Get number of groups existing in the mesh
1862 return self.mesh.NbGroups()
1864 ## Get the list of names of groups existing in the mesh
1865 def GetGroupNames(self):
1866 groups = self.GetGroups()
1868 for group in groups:
1869 names.append(group.GetName())
1872 ## Union of two groups
1873 # New group is created. All mesh elements that are
1874 # present in initial groups are added to the new one
1875 def UnionGroups(self, group1, group2, name):
1876 return self.mesh.UnionGroups(group1, group2, name)
1878 ## Intersection of two groups
1879 # New group is created. All mesh elements that are
1880 # present in both initial groups are added to the new one.
1881 def IntersectGroups(self, group1, group2, name):
1882 return self.mesh.IntersectGroups(group1, group2, name)
1884 ## Cut of two groups
1885 # New group is created. All mesh elements that are present in
1886 # main group but do not present in tool group are added to the new one
1887 def CutGroups(self, mainGroup, toolGroup, name):
1888 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1891 # Get some info about mesh:
1892 # ------------------------
1894 ## Get the log of nodes and elements added or removed since previous
1896 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1897 # @return list of log_block structures:
1902 def GetLog(self, clearAfterGet):
1903 return self.mesh.GetLog(clearAfterGet)
1905 ## Clear the log of nodes and elements added or removed since previous
1906 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1908 self.mesh.ClearLog()
1910 def SetAutoColor(self, color):
1911 self.mesh.SetAutoColor(color)
1913 def GetAutoColor(self):
1914 return self.mesh.GetAutoColor()
1916 ## Get the internal Id
1918 return self.mesh.GetId()
1921 def GetStudyId(self):
1922 return self.mesh.GetStudyId()
1924 ## Check group names for duplications.
1925 # Consider maximum group name length stored in MED file.
1926 def HasDuplicatedGroupNamesMED(self):
1927 return self.mesh.HasDuplicatedGroupNamesMED()
1929 ## Obtain instance of SMESH_MeshEditor
1930 def GetMeshEditor(self):
1931 return self.mesh.GetMeshEditor()
1934 def GetMEDMesh(self):
1935 return self.mesh.GetMEDMesh()
1938 # Get informations about mesh contents:
1939 # ------------------------------------
1941 ## Returns number of nodes in mesh
1943 return self.mesh.NbNodes()
1945 ## Returns number of elements in mesh
1946 def NbElements(self):
1947 return self.mesh.NbElements()
1949 ## Returns number of edges in mesh
1951 return self.mesh.NbEdges()
1953 ## Returns number of edges with given order in mesh
1954 # @param elementOrder is order of elements:
1955 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1956 def NbEdgesOfOrder(self, elementOrder):
1957 return self.mesh.NbEdgesOfOrder(elementOrder)
1959 ## Returns number of faces in mesh
1961 return self.mesh.NbFaces()
1963 ## Returns number of faces with given order in mesh
1964 # @param elementOrder is order of elements:
1965 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1966 def NbFacesOfOrder(self, elementOrder):
1967 return self.mesh.NbFacesOfOrder(elementOrder)
1969 ## Returns number of triangles in mesh
1970 def NbTriangles(self):
1971 return self.mesh.NbTriangles()
1973 ## Returns number of triangles with given order in mesh
1974 # @param elementOrder is order of elements:
1975 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1976 def NbTrianglesOfOrder(self, elementOrder):
1977 return self.mesh.NbTrianglesOfOrder(elementOrder)
1979 ## Returns number of quadrangles in mesh
1980 def NbQuadrangles(self):
1981 return self.mesh.NbQuadrangles()
1983 ## Returns number of quadrangles with given order in mesh
1984 # @param elementOrder is order of elements:
1985 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1986 def NbQuadranglesOfOrder(self, elementOrder):
1987 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1989 ## Returns number of polygons in mesh
1990 def NbPolygons(self):
1991 return self.mesh.NbPolygons()
1993 ## Returns number of volumes in mesh
1994 def NbVolumes(self):
1995 return self.mesh.NbVolumes()
1997 ## Returns number of volumes with given order in mesh
1998 # @param elementOrder is order of elements:
1999 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2000 def NbVolumesOfOrder(self, elementOrder):
2001 return self.mesh.NbVolumesOfOrder(elementOrder)
2003 ## Returns number of tetrahedrons in mesh
2005 return self.mesh.NbTetras()
2007 ## Returns number of tetrahedrons with given order in mesh
2008 # @param elementOrder is order of elements:
2009 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2010 def NbTetrasOfOrder(self, elementOrder):
2011 return self.mesh.NbTetrasOfOrder(elementOrder)
2013 ## Returns number of hexahedrons in mesh
2015 return self.mesh.NbHexas()
2017 ## Returns number of hexahedrons with given order in mesh
2018 # @param elementOrder is order of elements:
2019 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2020 def NbHexasOfOrder(self, elementOrder):
2021 return self.mesh.NbHexasOfOrder(elementOrder)
2023 ## Returns number of pyramids in mesh
2024 def NbPyramids(self):
2025 return self.mesh.NbPyramids()
2027 ## Returns number of pyramids with given order in mesh
2028 # @param elementOrder is order of elements:
2029 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2030 def NbPyramidsOfOrder(self, elementOrder):
2031 return self.mesh.NbPyramidsOfOrder(elementOrder)
2033 ## Returns number of prisms in mesh
2035 return self.mesh.NbPrisms()
2037 ## Returns number of prisms with given order in mesh
2038 # @param elementOrder is order of elements:
2039 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2040 def NbPrismsOfOrder(self, elementOrder):
2041 return self.mesh.NbPrismsOfOrder(elementOrder)
2043 ## Returns number of polyhedrons in mesh
2044 def NbPolyhedrons(self):
2045 return self.mesh.NbPolyhedrons()
2047 ## Returns number of submeshes in mesh
2048 def NbSubMesh(self):
2049 return self.mesh.NbSubMesh()
2051 ## Returns list of mesh elements ids
2052 def GetElementsId(self):
2053 return self.mesh.GetElementsId()
2055 ## Returns list of ids of mesh elements with given type
2056 # @param elementType is required type of elements
2057 def GetElementsByType(self, elementType):
2058 return self.mesh.GetElementsByType(elementType)
2060 ## Returns list of mesh nodes ids
2061 def GetNodesId(self):
2062 return self.mesh.GetNodesId()
2064 # Get informations about mesh elements:
2065 # ------------------------------------
2067 ## Returns type of mesh element
2068 def GetElementType(self, id, iselem):
2069 return self.mesh.GetElementType(id, iselem)
2071 ## Returns list of submesh elements ids
2072 # @param shapeID is geom object(subshape) IOR
2073 def GetSubMeshElementsId(self, shapeID):
2074 return self.mesh.GetSubMeshElementsId(shapeID)
2076 ## Returns list of submesh nodes ids
2077 # @param shapeID is geom object(subshape) IOR
2078 def GetSubMeshNodesId(self, shapeID, all):
2079 return self.mesh.GetSubMeshNodesId(shapeID, all)
2081 ## Returns list of ids of submesh elements with given type
2082 # @param shapeID is geom object(subshape) IOR
2083 def GetSubMeshElementType(self, shapeID):
2084 return self.mesh.GetSubMeshElementType(shapeID)
2086 ## Get mesh description
2088 return self.mesh.Dump()
2091 # Get information about nodes and elements of mesh by its ids:
2092 # -----------------------------------------------------------
2094 ## Get XYZ coordinates of node as list of double
2095 # \n If there is not node for given ID - returns empty list
2096 def GetNodeXYZ(self, id):
2097 return self.mesh.GetNodeXYZ(id)
2099 ## For given node returns list of IDs of inverse elements
2100 # \n If there is not node for given ID - returns empty list
2101 def GetNodeInverseElements(self, id):
2102 return self.mesh.GetNodeInverseElements(id)
2104 ## If given element is node returns IDs of shape from position
2105 # \n If there is not node for given ID - returns -1
2106 def GetShapeID(self, id):
2107 return self.mesh.GetShapeID(id)
2109 ## For given element returns ID of result shape after
2110 # FindShape() from SMESH_MeshEditor
2111 # \n If there is not element for given ID - returns -1
2112 def GetShapeIDForElem(self,id):
2113 return self.mesh.GetShapeIDForElem(id)
2115 ## Returns number of nodes for given element
2116 # \n If there is not element for given ID - returns -1
2117 def GetElemNbNodes(self, id):
2118 return self.mesh.GetElemNbNodes(id)
2120 ## Returns ID of node by given index for given element
2121 # \n If there is not element for given ID - returns -1
2122 # \n If there is not node for given index - returns -2
2123 def GetElemNode(self, id, index):
2124 return self.mesh.GetElemNode(id, index)
2126 ## Returns IDs of nodes of given element
2127 def GetElemNodes(self, id):
2128 return self.mesh.GetElemNodes(id)
2130 ## Returns true if given node is medium node
2131 # in given quadratic element
2132 def IsMediumNode(self, elementID, nodeID):
2133 return self.mesh.IsMediumNode(elementID, nodeID)
2135 ## Returns true if given node is medium node
2136 # in one of quadratic elements
2137 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2138 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2140 ## Returns number of edges for given element
2141 def ElemNbEdges(self, id):
2142 return self.mesh.ElemNbEdges(id)
2144 ## Returns number of faces for given element
2145 def ElemNbFaces(self, id):
2146 return self.mesh.ElemNbFaces(id)
2148 ## Returns true if given element is polygon
2149 def IsPoly(self, id):
2150 return self.mesh.IsPoly(id)
2152 ## Returns true if given element is quadratic
2153 def IsQuadratic(self, id):
2154 return self.mesh.IsQuadratic(id)
2156 ## Returns XYZ coordinates of bary center for given element
2158 # \n If there is not element for given ID - returns empty list
2159 def BaryCenter(self, id):
2160 return self.mesh.BaryCenter(id)
2163 # Mesh edition (SMESH_MeshEditor functionality):
2164 # ---------------------------------------------
2166 ## Removes elements from mesh by ids
2167 # @param IDsOfElements is list of ids of elements to remove
2168 def RemoveElements(self, IDsOfElements):
2169 return self.editor.RemoveElements(IDsOfElements)
2171 ## Removes nodes from mesh by ids
2172 # @param IDsOfNodes is list of ids of nodes to remove
2173 def RemoveNodes(self, IDsOfNodes):
2174 return self.editor.RemoveNodes(IDsOfNodes)
2176 ## Add node to mesh by coordinates
2177 def AddNode(self, x, y, z):
2178 return self.editor.AddNode( x, y, z)
2181 ## Create edge both similar and quadratic (this is determed
2182 # by number of given nodes).
2183 # @param IdsOfNodes List of node IDs for creation of element.
2184 # Needed order of nodes in this list corresponds to description
2185 # of MED. \n This description is located by the following link:
2186 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2187 def AddEdge(self, IDsOfNodes):
2188 return self.editor.AddEdge(IDsOfNodes)
2190 ## Create face both similar and quadratic (this is determed
2191 # by number of given nodes).
2192 # @param IdsOfNodes List of node IDs for creation of element.
2193 # Needed order of nodes in this list corresponds to description
2194 # of MED. \n This description is located by the following link:
2195 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2196 def AddFace(self, IDsOfNodes):
2197 return self.editor.AddFace(IDsOfNodes)
2199 ## Add polygonal face to mesh by list of nodes ids
2200 def AddPolygonalFace(self, IdsOfNodes):
2201 return self.editor.AddPolygonalFace(IdsOfNodes)
2203 ## Create volume both similar and quadratic (this is determed
2204 # by number of given nodes).
2205 # @param IdsOfNodes List of node IDs for creation of element.
2206 # Needed order of nodes in this list corresponds to description
2207 # of MED. \n This description is located by the following link:
2208 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2209 def AddVolume(self, IDsOfNodes):
2210 return self.editor.AddVolume(IDsOfNodes)
2212 ## Create volume of many faces, giving nodes for each face.
2213 # @param IdsOfNodes List of node IDs for volume creation face by face.
2214 # @param Quantities List of integer values, Quantities[i]
2215 # gives quantity of nodes in face number i.
2216 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2217 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2219 ## Create volume of many faces, giving IDs of existing faces.
2220 # @param IdsOfFaces List of face IDs for volume creation.
2222 # Note: The created volume will refer only to nodes
2223 # of the given faces, not to the faces itself.
2224 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2225 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2227 ## Move node with given id
2228 # @param NodeID id of the node
2229 # @param x new X coordinate
2230 # @param y new Y coordinate
2231 # @param z new Z coordinate
2232 def MoveNode(self, NodeID, x, y, z):
2233 return self.editor.MoveNode(NodeID, x, y, z)
2235 ## Find a node closest to a point
2236 # @param x X coordinate of a point
2237 # @param y Y coordinate of a point
2238 # @param z Z coordinate of a point
2239 # @return id of a node
2240 def FindNodeClosestTo(self, x, y, z):
2241 preview = self.mesh.GetMeshEditPreviewer()
2242 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2244 ## Find a node closest to a point and move it to a point location
2245 # @param x X coordinate of a point
2246 # @param y Y coordinate of a point
2247 # @param z Z coordinate of a point
2248 # @return id of a moved node
2249 def MeshToPassThroughAPoint(self, x, y, z):
2250 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2252 ## Replace two neighbour triangles sharing Node1-Node2 link
2253 # with ones built on the same 4 nodes but having other common link.
2254 # @param NodeID1 first node id
2255 # @param NodeID2 second node id
2256 # @return false if proper faces not found
2257 def InverseDiag(self, NodeID1, NodeID2):
2258 return self.editor.InverseDiag(NodeID1, NodeID2)
2260 ## Replace two neighbour triangles sharing Node1-Node2 link
2261 # with a quadrangle built on the same 4 nodes.
2262 # @param NodeID1 first node id
2263 # @param NodeID2 second node id
2264 # @return false if proper faces not found
2265 def DeleteDiag(self, NodeID1, NodeID2):
2266 return self.editor.DeleteDiag(NodeID1, NodeID2)
2268 ## Reorient elements by ids
2269 # @param IDsOfElements if undefined reorient all mesh elements
2270 def Reorient(self, IDsOfElements=None):
2271 if IDsOfElements == None:
2272 IDsOfElements = self.GetElementsId()
2273 return self.editor.Reorient(IDsOfElements)
2275 ## Reorient all elements of the object
2276 # @param theObject is mesh, submesh or group
2277 def ReorientObject(self, theObject):
2278 return self.editor.ReorientObject(theObject)
2280 ## Fuse neighbour triangles into quadrangles.
2281 # @param IDsOfElements The triangles to be fused,
2282 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2283 # @param MaxAngle is a max angle between element normals at which fusion
2284 # is still performed; theMaxAngle is mesured in radians.
2285 # @return TRUE in case of success, FALSE otherwise.
2286 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2287 if IDsOfElements == []:
2288 IDsOfElements = self.GetElementsId()
2289 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2291 ## Fuse neighbour triangles of the object into quadrangles
2292 # @param theObject is mesh, submesh or group
2293 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2294 # @param MaxAngle is a max angle between element normals at which fusion
2295 # is still performed; theMaxAngle is mesured in radians.
2296 # @return TRUE in case of success, FALSE otherwise.
2297 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2298 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2300 ## Split quadrangles into triangles.
2301 # @param IDsOfElements the faces to be splitted.
2302 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2303 # @param @return TRUE in case of success, FALSE otherwise.
2304 def QuadToTri (self, IDsOfElements, theCriterion):
2305 if IDsOfElements == []:
2306 IDsOfElements = self.GetElementsId()
2307 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2309 ## Split quadrangles into triangles.
2310 # @param theObject object to taking list of elements from, is mesh, submesh or group
2311 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2312 def QuadToTriObject (self, theObject, theCriterion):
2313 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2315 ## Split quadrangles into triangles.
2316 # @param theElems The faces to be splitted
2317 # @param the13Diag is used to choose a diagonal for splitting.
2318 # @return TRUE in case of success, FALSE otherwise.
2319 def SplitQuad (self, IDsOfElements, Diag13):
2320 if IDsOfElements == []:
2321 IDsOfElements = self.GetElementsId()
2322 return self.editor.SplitQuad(IDsOfElements, Diag13)
2324 ## Split quadrangles into triangles.
2325 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2326 def SplitQuadObject (self, theObject, Diag13):
2327 return self.editor.SplitQuadObject(theObject, Diag13)
2329 ## Find better splitting of the given quadrangle.
2330 # @param IDOfQuad ID of the quadrangle to be splitted.
2331 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2332 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2333 # diagonal is better, 0 if error occurs.
2334 def BestSplit (self, IDOfQuad, theCriterion):
2335 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2337 ## Split quafrangle faces near triangular facets of volumes
2339 def SplitQuadsNearTriangularFacets(self):
2340 faces_array = self.GetElementsByType(SMESH.FACE)
2341 for face_id in faces_array:
2342 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2343 quad_nodes = self.mesh.GetElemNodes(face_id)
2344 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2345 isVolumeFound = False
2346 for node1_elem in node1_elems:
2347 if not isVolumeFound:
2348 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2349 nb_nodes = self.GetElemNbNodes(node1_elem)
2350 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2351 volume_elem = node1_elem
2352 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2353 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2354 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2355 isVolumeFound = True
2356 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2357 self.SplitQuad([face_id], False) # diagonal 2-4
2358 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2359 isVolumeFound = True
2360 self.SplitQuad([face_id], True) # diagonal 1-3
2361 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2362 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2363 isVolumeFound = True
2364 self.SplitQuad([face_id], True) # diagonal 1-3
2366 ## @brief Split hexahedrons into tetrahedrons.
2368 # Use pattern mapping functionality for splitting.
2369 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2370 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2371 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2372 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2373 # key-point will be mapped into <theNode001>-th node of each volume.
2374 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2375 # @return TRUE in case of success, FALSE otherwise.
2376 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2377 # Pattern: 5.---------.6
2382 # (0,0,1) 4.---------.7 * |
2389 # (0,0,0) 0.---------.3
2390 pattern_tetra = "!!! Nb of points: \n 8 \n\
2400 !!! Indices of points of 6 tetras: \n\
2408 pattern = self.smeshpyD.GetPattern()
2409 isDone = pattern.LoadFromFile(pattern_tetra)
2411 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2414 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2415 isDone = pattern.MakeMesh(self.mesh, False, False)
2416 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2418 # split quafrangle faces near triangular facets of volumes
2419 self.SplitQuadsNearTriangularFacets()
2423 ## @brief Split hexahedrons into prisms.
2425 # Use pattern mapping functionality for splitting.
2426 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2427 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2428 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2429 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2430 # key-point will be mapped into <theNode001>-th node of each volume.
2431 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2432 # @return TRUE in case of success, FALSE otherwise.
2433 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2434 # Pattern: 5.---------.6
2439 # (0,0,1) 4.---------.7 |
2446 # (0,0,0) 0.---------.3
2447 pattern_prism = "!!! Nb of points: \n 8 \n\
2457 !!! Indices of points of 2 prisms: \n\
2461 pattern = self.smeshpyD.GetPattern()
2462 isDone = pattern.LoadFromFile(pattern_prism)
2464 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2467 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2468 isDone = pattern.MakeMesh(self.mesh, False, False)
2469 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2471 # split quafrangle faces near triangular facets of volumes
2472 self.SplitQuadsNearTriangularFacets()
2477 # @param IDsOfElements list if ids of elements to smooth
2478 # @param IDsOfFixedNodes list of ids of fixed nodes.
2479 # Note that nodes built on edges and boundary nodes are always fixed.
2480 # @param MaxNbOfIterations maximum number of iterations
2481 # @param MaxAspectRatio varies in range [1.0, inf]
2482 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2483 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2484 MaxNbOfIterations, MaxAspectRatio, Method):
2485 if IDsOfElements == []:
2486 IDsOfElements = self.GetElementsId()
2487 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2488 MaxNbOfIterations, MaxAspectRatio, Method)
2490 ## Smooth elements belong to given object
2491 # @param theObject object to smooth
2492 # @param IDsOfFixedNodes list of ids of fixed nodes.
2493 # Note that nodes built on edges and boundary nodes are always fixed.
2494 # @param MaxNbOfIterations maximum number of iterations
2495 # @param MaxAspectRatio varies in range [1.0, inf]
2496 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2497 def SmoothObject(self, theObject, IDsOfFixedNodes,
2498 MaxNbOfIterations, MaxxAspectRatio, Method):
2499 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2500 MaxNbOfIterations, MaxxAspectRatio, Method)
2502 ## Parametric smooth the given elements
2503 # @param IDsOfElements list if ids of elements to smooth
2504 # @param IDsOfFixedNodes list of ids of fixed nodes.
2505 # Note that nodes built on edges and boundary nodes are always fixed.
2506 # @param MaxNbOfIterations maximum number of iterations
2507 # @param MaxAspectRatio varies in range [1.0, inf]
2508 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2509 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2510 MaxNbOfIterations, MaxAspectRatio, Method):
2511 if IDsOfElements == []:
2512 IDsOfElements = self.GetElementsId()
2513 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2514 MaxNbOfIterations, MaxAspectRatio, Method)
2516 ## Parametric smooth elements belong to given object
2517 # @param theObject object to smooth
2518 # @param IDsOfFixedNodes list of ids of fixed nodes.
2519 # Note that nodes built on edges and boundary nodes are always fixed.
2520 # @param MaxNbOfIterations maximum number of iterations
2521 # @param MaxAspectRatio varies in range [1.0, inf]
2522 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2523 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2524 MaxNbOfIterations, MaxAspectRatio, Method):
2525 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2526 MaxNbOfIterations, MaxAspectRatio, Method)
2528 ## Converts all mesh to quadratic one, deletes old elements, replacing
2529 # them with quadratic ones with the same id.
2530 def ConvertToQuadratic(self, theForce3d):
2531 self.editor.ConvertToQuadratic(theForce3d)
2533 ## Converts all mesh from quadratic to ordinary ones,
2534 # deletes old quadratic elements, \n replacing
2535 # them with ordinary mesh elements with the same id.
2536 def ConvertFromQuadratic(self):
2537 return self.editor.ConvertFromQuadratic()
2539 ## Renumber mesh nodes
2540 def RenumberNodes(self):
2541 self.editor.RenumberNodes()
2543 ## Renumber mesh elements
2544 def RenumberElements(self):
2545 self.editor.RenumberElements()
2547 ## Generate new elements by rotation of the elements around the axis
2548 # @param IDsOfElements list of ids of elements to sweep
2549 # @param Axix axis of rotation, AxisStruct or line(geom object)
2550 # @param AngleInRadians angle of Rotation
2551 # @param NbOfSteps number of steps
2552 # @param Tolerance tolerance
2553 # @param MakeGroups to generate new groups from existing ones
2554 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2555 if IDsOfElements == []:
2556 IDsOfElements = self.GetElementsId()
2557 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2558 Axix = self.smeshpyD.GetAxisStruct(Axix)
2560 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2561 AngleInRadians, NbOfSteps, Tolerance)
2562 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2565 ## Generate new elements by rotation of the elements of object around the axis
2566 # @param theObject object wich elements should be sweeped
2567 # @param Axix axis of rotation, AxisStruct or line(geom object)
2568 # @param AngleInRadians angle of Rotation
2569 # @param NbOfSteps number of steps
2570 # @param Tolerance tolerance
2571 # @param MakeGroups to generate new groups from existing ones
2572 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2573 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2574 Axix = self.smeshpyD.GetAxisStruct(Axix)
2576 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2577 NbOfSteps, Tolerance)
2578 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2581 ## Generate new elements by extrusion of the elements with given ids
2582 # @param IDsOfElements list of elements ids for extrusion
2583 # @param StepVector vector, defining the direction and value of extrusion
2584 # @param NbOfSteps the number of steps
2585 # @param MakeGroups to generate new groups from existing ones
2586 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2587 if IDsOfElements == []:
2588 IDsOfElements = self.GetElementsId()
2589 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2590 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2592 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2593 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2596 ## Generate new elements by extrusion of the elements with given ids
2597 # @param IDsOfElements is ids of elements
2598 # @param StepVector vector, defining the direction and value of extrusion
2599 # @param NbOfSteps the number of steps
2600 # @param ExtrFlags set flags for performing extrusion
2601 # @param SewTolerance uses for comparing locations of nodes if flag
2602 # EXTRUSION_FLAG_SEW is set
2603 # @param MakeGroups to generate new groups from existing ones
2604 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2605 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2606 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2608 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2609 ExtrFlags, SewTolerance)
2610 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2611 ExtrFlags, SewTolerance)
2614 ## Generate new elements by extrusion of the elements belong to object
2615 # @param theObject object wich elements should be processed
2616 # @param StepVector vector, defining the direction and value of extrusion
2617 # @param NbOfSteps the number of steps
2618 # @param MakeGroups to generate new groups from existing ones
2619 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2620 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2621 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2623 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2624 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2627 ## Generate new elements by extrusion of the elements belong to object
2628 # @param theObject object wich elements should be processed
2629 # @param StepVector vector, defining the direction and value of extrusion
2630 # @param NbOfSteps the number of steps
2631 # @param MakeGroups to generate new groups from existing ones
2632 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2633 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2634 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2636 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2637 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2640 ## Generate new elements by extrusion of the elements belong to object
2641 # @param theObject object wich elements should be processed
2642 # @param StepVector vector, defining the direction and value of extrusion
2643 # @param NbOfSteps the number of steps
2644 # @param MakeGroups to generate new groups from existing ones
2645 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2646 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2647 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2649 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2650 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2653 ## Generate new elements by extrusion of the given elements
2654 # A path of extrusion must be a meshed edge.
2655 # @param IDsOfElements is ids of elements
2656 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2657 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2658 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2659 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2660 # @param Angles list of angles
2661 # @param HasRefPoint allows to use base point
2662 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2663 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2664 # @param MakeGroups to generate new groups from existing ones
2665 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2666 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2667 HasAngles, Angles, HasRefPoint, RefPoint,
2668 MakeGroups=False, LinearVariation=False):
2669 if IDsOfElements == []:
2670 IDsOfElements = self.GetElementsId()
2671 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2672 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2675 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
2676 PathShape, NodeStart, HasAngles,
2677 Angles, HasRefPoint, RefPoint)
2678 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
2679 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2681 ## Generate new elements by extrusion of the elements belong to object
2682 # A path of extrusion must be a meshed edge.
2683 # @param IDsOfElements is ids of elements
2684 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2685 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2686 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2687 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2688 # @param Angles list of angles
2689 # @param HasRefPoint allows to use base point
2690 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2691 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2692 # @param MakeGroups to generate new groups from existing ones
2693 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2694 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2695 HasAngles, Angles, HasRefPoint, RefPoint,
2696 MakeGroups=False, LinearVariation=False):
2697 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2698 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2700 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
2701 PathShape, NodeStart, HasAngles,
2702 Angles, HasRefPoint, RefPoint)
2703 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
2704 NodeStart, HasAngles, Angles, HasRefPoint,
2707 ## Symmetrical copy of mesh elements
2708 # @param IDsOfElements list of elements ids
2709 # @param Mirror is AxisStruct or geom object(point, line, plane)
2710 # @param theMirrorType is POINT, AXIS or PLANE
2711 # If the Mirror is geom object this parameter is unnecessary
2712 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2713 # @param MakeGroups to generate new groups from existing ones (if Copy)
2714 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2715 if IDsOfElements == []:
2716 IDsOfElements = self.GetElementsId()
2717 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2718 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2719 if Copy and MakeGroups:
2720 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2721 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2724 ## Symmetrical copy of object
2725 # @param theObject mesh, submesh or group
2726 # @param Mirror is AxisStruct or geom object(point, line, plane)
2727 # @param theMirrorType is POINT, AXIS or PLANE
2728 # If the Mirror is geom object this parameter is unnecessary
2729 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2730 # @param MakeGroups to generate new groups from existing ones (if Copy)
2731 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2732 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2733 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2734 if Copy and MakeGroups:
2735 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2736 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2739 ## Translates the elements
2740 # @param IDsOfElements list of elements ids
2741 # @param Vector direction of translation(DirStruct or vector)
2742 # @param Copy allows to copy the translated elements
2743 # @param MakeGroups to generate new groups from existing ones (if Copy)
2744 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2745 if IDsOfElements == []:
2746 IDsOfElements = self.GetElementsId()
2747 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2748 Vector = self.smeshpyD.GetDirStruct(Vector)
2749 if Copy and MakeGroups:
2750 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2751 self.editor.Translate(IDsOfElements, Vector, Copy)
2754 ## Translates the object
2755 # @param theObject object to translate(mesh, submesh, or group)
2756 # @param Vector direction of translation(DirStruct or geom vector)
2757 # @param Copy allows to copy the translated elements
2758 # @param MakeGroups to generate new groups from existing ones (if Copy)
2759 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2760 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2761 Vector = self.smeshpyD.GetDirStruct(Vector)
2762 if Copy and MakeGroups:
2763 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2764 self.editor.TranslateObject(theObject, Vector, Copy)
2767 ## Rotates the elements
2768 # @param IDsOfElements list of elements ids
2769 # @param Axis axis of rotation(AxisStruct or geom line)
2770 # @param AngleInRadians angle of rotation(in radians)
2771 # @param Copy allows to copy the rotated elements
2772 # @param MakeGroups to generate new groups from existing ones (if Copy)
2773 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2774 if IDsOfElements == []:
2775 IDsOfElements = self.GetElementsId()
2776 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2777 Axis = self.smeshpyD.GetAxisStruct(Axis)
2778 if Copy and MakeGroups:
2779 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2780 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2783 ## Rotates the object
2784 # @param theObject object to rotate(mesh, submesh, or group)
2785 # @param Axis axis of rotation(AxisStruct or geom line)
2786 # @param AngleInRadians angle of rotation(in radians)
2787 # @param Copy allows to copy the rotated elements
2788 # @param MakeGroups to generate new groups from existing ones (if Copy)
2789 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2790 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2791 Axis = self.smeshpyD.GetAxisStruct(Axis)
2792 if Copy and MakeGroups:
2793 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2794 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2797 ## Find group of nodes close to each other within Tolerance.
2798 # @param Tolerance tolerance value
2799 # @param list of group of nodes
2800 def FindCoincidentNodes (self, Tolerance):
2801 return self.editor.FindCoincidentNodes(Tolerance)
2803 ## Find group of nodes close to each other within Tolerance.
2804 # @param Tolerance tolerance value
2805 # @param SubMeshOrGroup SubMesh or Group
2806 # @param list of group of nodes
2807 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2808 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2811 # @param list of group of nodes
2812 def MergeNodes (self, GroupsOfNodes):
2813 self.editor.MergeNodes(GroupsOfNodes)
2815 ## Find elements built on the same nodes.
2816 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2817 # @return a list of groups of equal elements
2818 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2819 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2821 ## Merge elements in each given group.
2822 # @param GroupsOfElementsID groups of elements for merging
2823 def MergeElements(self, GroupsOfElementsID):
2824 self.editor.MergeElements(GroupsOfElementsID)
2826 ## Remove all but one of elements built on the same nodes.
2827 def MergeEqualElements(self):
2828 self.editor.MergeEqualElements()
2831 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2832 FirstNodeID2, SecondNodeID2, LastNodeID2,
2833 CreatePolygons, CreatePolyedrs):
2834 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2835 FirstNodeID2, SecondNodeID2, LastNodeID2,
2836 CreatePolygons, CreatePolyedrs)
2838 ## Sew conform free borders
2839 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2840 FirstNodeID2, SecondNodeID2):
2841 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2842 FirstNodeID2, SecondNodeID2)
2844 ## Sew border to side
2845 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2846 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
2847 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
2848 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
2850 ## Sew two sides of a mesh. Nodes belonging to Side1 are
2851 # merged with nodes of elements of Side2.
2852 # Number of elements in theSide1 and in theSide2 must be
2853 # equal and they should have similar node connectivity.
2854 # The nodes to merge should belong to sides borders and
2855 # the first node should be linked to the second.
2856 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
2857 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2858 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
2859 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
2860 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
2861 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2863 ## Set new nodes for given element.
2864 # @param ide the element id
2865 # @param newIDs nodes ids
2866 # @return If number of nodes is not corresponded to type of element - returns false
2867 def ChangeElemNodes(self, ide, newIDs):
2868 return self.editor.ChangeElemNodes(ide, newIDs)
2870 ## If during last operation of MeshEditor some nodes were
2871 # created this method returns list of it's IDs, \n
2872 # if new nodes not created - returns empty list
2873 def GetLastCreatedNodes(self):
2874 return self.editor.GetLastCreatedNodes()
2876 ## If during last operation of MeshEditor some elements were
2877 # created this method returns list of it's IDs, \n
2878 # if new elements not creared - returns empty list
2879 def GetLastCreatedElems(self):
2880 return self.editor.GetLastCreatedElems()