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: 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):
810 if self.params is not None:
811 self.params.SetMaxSize(theSize)
813 ## Set SecondOrder flag
815 # Only for algoType == NETGEN
816 def SetSecondOrder(self, theVal):
819 if self.params is not None:
820 self.params.SetSecondOrder(theVal)
824 # Only for algoType == NETGEN
825 def SetOptimize(self, theVal):
828 if self.params is not None:
829 self.params.SetOptimize(theVal)
832 # @param theFineness is:
833 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
835 # Only for algoType == NETGEN
836 def SetFineness(self, theFineness):
839 if self.params is not None:
840 self.params.SetFineness(theFineness)
844 # Only for algoType == NETGEN
845 def SetGrowthRate(self, theRate):
848 if self.params is not None:
849 self.params.SetGrowthRate(theRate)
853 # Only for algoType == NETGEN
854 def SetNbSegPerEdge(self, theVal):
857 if self.params is not None:
858 self.params.SetNbSegPerEdge(theVal)
860 ## Set NbSegPerRadius
862 # Only for algoType == NETGEN
863 def SetNbSegPerRadius(self, theVal):
866 if self.params is not None:
867 self.params.SetNbSegPerRadius(theVal)
872 # Public class: Mesh_Quadrangle
873 # -----------------------------
875 ## Class to define a quadrangle 2D algorithm
878 class Mesh_Quadrangle(Mesh_Algorithm):
880 algo = 0 # algorithm object common for all Mesh_Quadrangle's
882 ## Private constructor.
883 def __init__(self, mesh, geom=0):
884 Mesh_Algorithm.__init__(self)
886 if not Mesh_Quadrangle.algo:
887 Mesh_Quadrangle.algo = self.Create(mesh, geom, "Quadrangle_2D")
889 self.Assign( Mesh_Quadrangle.algo, mesh, geom)
892 ## Define "QuadranglePreference" hypothesis, forcing construction
893 # of quadrangles if the number of nodes on opposite edges is not the same
894 # in the case where the global number of nodes on edges is even
895 def QuadranglePreference(self):
896 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1)
899 # Public class: Mesh_Tetrahedron
900 # ------------------------------
902 ## Class to define a tetrahedron 3D algorithm
905 class Mesh_Tetrahedron(Mesh_Algorithm):
910 algoNET = 0 # algorithm object common for all Mesh_Tetrahedron's
911 algoGHS = 0 # algorithm object common for all Mesh_Tetrahedron's
912 algoFNET = 0 # algorithm object common for all Mesh_Tetrahedron's
914 ## Private constructor.
915 def __init__(self, mesh, algoType, geom=0):
916 Mesh_Algorithm.__init__(self)
918 if algoType == NETGEN:
919 if not Mesh_Tetrahedron.algoNET:
920 Mesh_Tetrahedron.algoNET = self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
922 self.Assign( Mesh_Tetrahedron.algoNET, mesh, geom)
926 elif algoType == GHS3D:
927 if not Mesh_Tetrahedron.algoGHS:
929 Mesh_Tetrahedron.algoGHS = self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
931 self.Assign( Mesh_Tetrahedron.algoGHS, mesh, geom)
935 elif algoType == FULL_NETGEN:
937 print "Warning: NETGENPlugin module has not been imported."
938 if not Mesh_Tetrahedron.algoFNET:
939 Mesh_Tetrahedron.algoFNET = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
941 self.Assign( Mesh_Tetrahedron.algoFNET, mesh, geom)
945 self.algoType = algoType
947 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
948 # @param vol for the maximum volume of each tetrahedral
949 # @param UseExisting if ==true - search existing hypothesis created with
950 # same parameters, else (default) - create new
951 def MaxElementVolume(self, vol, UseExisting=0):
952 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting)
953 hyp.SetMaxElementVolume(vol)
956 ## Define "Netgen 3D Parameters" hypothesis
957 def Parameters(self):
958 if (self.algoType == FULL_NETGEN):
959 self.params = self.Hypothesis("NETGEN_Parameters", [],
960 "libNETGENEngine.so", UseExisting=0)
963 print "Algo doesn't support this hypothesis"
967 def SetMaxSize(self, theSize):
970 self.params.SetMaxSize(theSize)
972 ## Set SecondOrder flag
973 def SetSecondOrder(self, theVal):
976 self.params.SetSecondOrder(theVal)
979 def SetOptimize(self, theVal):
982 self.params.SetOptimize(theVal)
985 # @param theFineness is:
986 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
987 def SetFineness(self, theFineness):
990 self.params.SetFineness(theFineness)
993 def SetGrowthRate(self, theRate):
996 self.params.SetGrowthRate(theRate)
999 def SetNbSegPerEdge(self, theVal):
1000 if self.params == 0:
1002 self.params.SetNbSegPerEdge(theVal)
1004 ## Set NbSegPerRadius
1005 def SetNbSegPerRadius(self, theVal):
1006 if self.params == 0:
1008 self.params.SetNbSegPerRadius(theVal)
1010 # Public class: Mesh_Hexahedron
1011 # ------------------------------
1013 ## Class to define a hexahedron 3D algorithm
1016 class Mesh_Hexahedron(Mesh_Algorithm):
1018 algo = 0 # algorithm object common for all Mesh_Hexahedron's
1020 ## Private constructor.
1021 def __init__(self, mesh, geom=0):
1022 Mesh_Algorithm.__init__(self)
1024 if not Mesh_Hexahedron.algo:
1025 Mesh_Hexahedron.algo = self.Create(mesh, geom, "Hexa_3D")
1027 self.Assign( Mesh_Hexahedron.algo, mesh, geom)
1030 # Deprecated, only for compatibility!
1031 # Public class: Mesh_Netgen
1032 # ------------------------------
1034 ## Class to define a NETGEN-based 2D or 3D algorithm
1035 # that need no discrete boundary (i.e. independent)
1037 # This class is deprecated, only for compatibility!
1040 class Mesh_Netgen(Mesh_Algorithm):
1044 algoNET23 = 0 # algorithm object common for all Mesh_Netgen's
1045 algoNET2 = 0 # algorithm object common for all Mesh_Netgen's
1047 ## Private constructor.
1048 def __init__(self, mesh, is3D, geom=0):
1049 Mesh_Algorithm.__init__(self)
1052 print "Warning: NETGENPlugin module has not been imported."
1056 if not Mesh_Netgen.algoNET23:
1057 Mesh_Netgen.algoNET23 = self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1059 self.Assign( Mesh_Netgen.algoNET23, mesh, geom)
1064 if not Mesh_Netgen.algoNET2:
1065 Mesh_Netgen.algoNET2 = self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1067 self.Assign( Mesh_Netgen.algoNET2, mesh, geom)
1071 ## Define hypothesis containing parameters of the algorithm
1072 def Parameters(self):
1074 hyp = self.Hypothesis("NETGEN_Parameters", [],
1075 "libNETGENEngine.so", UseExisting=0)
1077 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1078 "libNETGENEngine.so", UseExisting=0)
1081 # Public class: Mesh_Projection1D
1082 # ------------------------------
1084 ## Class to define a projection 1D algorithm
1087 class Mesh_Projection1D(Mesh_Algorithm):
1089 algo = 0 # algorithm object common for all Mesh_Projection1D's
1091 ## Private constructor.
1092 def __init__(self, mesh, geom=0):
1093 Mesh_Algorithm.__init__(self)
1095 if not Mesh_Projection1D.algo:
1096 Mesh_Projection1D.algo = self.Create(mesh, geom, "Projection_1D")
1098 self.Assign( Mesh_Projection1D.algo, mesh, geom)
1101 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1102 # take a mesh pattern from, and optionally association of vertices
1103 # between the source edge and a target one (where a hipothesis is assigned to)
1104 # @param edge to take nodes distribution from
1105 # @param mesh to take nodes distribution from (optional)
1106 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1107 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1108 # to associate with \a srcV (optional)
1109 # @param UseExisting if ==true - search existing hypothesis created with
1110 # same parameters, else (default) - create new
1111 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1112 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV], UseExisting=UseExisting)
1113 hyp.SetSourceEdge( edge )
1114 if not mesh is None and isinstance(mesh, Mesh):
1115 mesh = mesh.GetMesh()
1116 hyp.SetSourceMesh( mesh )
1117 hyp.SetVertexAssociation( srcV, tgtV )
1121 # Public class: Mesh_Projection2D
1122 # ------------------------------
1124 ## Class to define a projection 2D algorithm
1127 class Mesh_Projection2D(Mesh_Algorithm):
1129 algo = 0 # algorithm object common for all Mesh_Projection2D's
1131 ## Private constructor.
1132 def __init__(self, mesh, geom=0):
1133 Mesh_Algorithm.__init__(self)
1135 if not Mesh_Projection2D.algo:
1136 Mesh_Projection2D.algo = self.Create(mesh, geom, "Projection_2D")
1138 self.Assign( Mesh_Projection2D.algo, mesh, geom)
1141 ## Define "Source Face" hypothesis, specifying a meshed face to
1142 # take a mesh pattern from, and optionally association of vertices
1143 # between the source face and a target one (where a hipothesis is assigned to)
1144 # @param face to take mesh pattern from
1145 # @param mesh to take mesh pattern from (optional)
1146 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1147 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1148 # to associate with \a srcV1 (optional)
1149 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1150 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1151 # to associate with \a srcV2 (optional)
1152 # @param UseExisting if ==true - search existing hypothesis created with
1153 # same parameters, else (default) - create new
1155 # Note: association vertices must belong to one edge of a face
1156 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1157 srcV2=None, tgtV2=None, UseExisting=0):
1158 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1159 UseExisting=UseExisting)
1160 hyp.SetSourceFace( face )
1161 if not mesh is None and isinstance(mesh, Mesh):
1162 mesh = mesh.GetMesh()
1163 hyp.SetSourceMesh( mesh )
1164 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1167 # Public class: Mesh_Projection3D
1168 # ------------------------------
1170 ## Class to define a projection 3D algorithm
1173 class Mesh_Projection3D(Mesh_Algorithm):
1175 algo = 0 # algorithm object common for all Mesh_Projection3D's
1177 ## Private constructor.
1178 def __init__(self, mesh, geom=0):
1179 Mesh_Algorithm.__init__(self)
1181 if not Mesh_Projection3D.algo:
1182 Mesh_Projection3D.algo = self.Create(mesh, geom, "Projection_3D")
1184 self.Assign( Mesh_Projection3D.algo, mesh, geom)
1187 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1188 # take a mesh pattern from, and optionally association of vertices
1189 # between the source solid and a target one (where a hipothesis is assigned to)
1190 # @param solid to take mesh pattern from
1191 # @param mesh to take mesh pattern from (optional)
1192 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1193 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1194 # to associate with \a srcV1 (optional)
1195 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1196 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1197 # to associate with \a srcV2 (optional)
1198 # @param UseExisting - if ==true - search existing hypothesis created with
1199 # same parameters, else (default) - create new
1201 # Note: association vertices must belong to one edge of a solid
1202 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1203 srcV2=0, tgtV2=0, UseExisting=0):
1204 hyp = self.Hypothesis("ProjectionSource3D",
1205 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1206 UseExisting=UseExisting)
1207 hyp.SetSource3DShape( solid )
1208 if not mesh is None and isinstance(mesh, Mesh):
1209 mesh = mesh.GetMesh()
1210 hyp.SetSourceMesh( mesh )
1211 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1215 # Public class: Mesh_Prism
1216 # ------------------------
1218 ## Class to define a 3D extrusion algorithm
1221 class Mesh_Prism3D(Mesh_Algorithm):
1223 algo = 0 # algorithm object common for all Mesh_Prism3D's
1225 ## Private constructor.
1226 def __init__(self, mesh, geom=0):
1227 Mesh_Algorithm.__init__(self)
1229 if not Mesh_Prism3D.algo:
1230 Mesh_Prism3D.algo = self.Create(mesh, geom, "Prism_3D")
1232 self.Assign( Mesh_Prism3D.algo, mesh, geom)
1235 # Public class: Mesh_RadialPrism
1236 # -------------------------------
1238 ## Class to define a Radial Prism 3D algorithm
1241 class Mesh_RadialPrism3D(Mesh_Algorithm):
1243 algo = 0 # algorithm object common for all Mesh_RadialPrism3D's
1245 ## Private constructor.
1246 def __init__(self, mesh, geom=0):
1247 Mesh_Algorithm.__init__(self)
1249 if not Mesh_RadialPrism3D.algo:
1250 Mesh_RadialPrism3D.algo = self.Create(mesh, geom, "RadialPrism_3D")
1252 self.Assign( Mesh_RadialPrism3D.algo, mesh, geom)
1254 self.distribHyp = self.Hypothesis( "LayerDistribution", UseExisting=0)
1255 self.nbLayers = None
1257 ## Return 3D hypothesis holding the 1D one
1258 def Get3DHypothesis(self):
1259 return self.distribHyp
1261 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1262 # hypothes. Returns the created hypothes
1263 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1264 print "OwnHypothesis",hypType
1265 if not self.nbLayers is None:
1266 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1267 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1268 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
1269 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1270 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
1271 self.distribHyp.SetLayerDistribution( hyp )
1274 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1275 # prisms to build between the inner and outer shells
1276 # @param UseExisting if ==true - search existing hypothesis created with
1277 # same parameters, else (default) - create new
1278 def NumberOfLayers(self, n, UseExisting=0):
1279 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1280 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting)
1281 self.nbLayers.SetNumberOfLayers( n )
1282 return self.nbLayers
1284 ## Define "LocalLength" hypothesis, specifying segment length
1285 # to build between the inner and outer shells
1286 # @param l for the length of segments
1287 def LocalLength(self, l):
1288 hyp = self.OwnHypothesis("LocalLength", [l] )
1292 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1293 # prisms to build between the inner and outer shells
1294 # @param n for the number of segments
1295 # @param s for the scale factor (optional)
1296 def NumberOfSegments(self, n, s=[]):
1298 hyp = self.OwnHypothesis("NumberOfSegments", [n] )
1300 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1301 hyp.SetDistrType( 1 )
1302 hyp.SetScaleFactor(s)
1303 hyp.SetNumberOfSegments(n)
1306 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1307 # to build between the inner and outer shells as arithmetic length increasing
1308 # @param start for the length of the first segment
1309 # @param end for the length of the last segment
1310 def Arithmetic1D(self, start, end ):
1311 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1312 hyp.SetLength(start, 1)
1313 hyp.SetLength(end , 0)
1316 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1317 # to build between the inner and outer shells as geometric length increasing
1318 # @param start for the length of the first segment
1319 # @param end for the length of the last segment
1320 def StartEndLength(self, start, end):
1321 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1322 hyp.SetLength(start, 1)
1323 hyp.SetLength(end , 0)
1326 ## Define "AutomaticLength" hypothesis, specifying number of segments
1327 # to build between the inner and outer shells
1328 # @param fineness for the fineness [0-1]
1329 def AutomaticLength(self, fineness=0):
1330 hyp = self.OwnHypothesis("AutomaticLength")
1331 hyp.SetFineness( fineness )
1334 # Private class: Mesh_UseExisting
1335 # -------------------------------
1336 class Mesh_UseExisting(Mesh_Algorithm):
1338 algo1D = 0 # StdMeshers_UseExisting_1D object common for all Mesh_UseExisting
1339 algo2D = 0 # StdMeshers_UseExisting_2D object common for all Mesh_UseExisting
1341 def __init__(self, dim, mesh, geom=0):
1343 if not Mesh_UseExisting.algo1D:
1344 Mesh_UseExisting.algo1D= self.Create(mesh, geom, "UseExisting_1D")
1346 self.Assign( Mesh_UseExisting.algo1D, mesh, geom)
1349 if not Mesh_UseExisting.algo2D:
1350 Mesh_UseExisting.algo2D= self.Create(mesh, geom, "UseExisting_2D")
1352 self.Assign( Mesh_UseExisting.algo2D, mesh, geom)
1355 # Public class: Mesh
1356 # ==================
1358 ## Class to define a mesh
1360 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1370 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1371 # sets GUI name of this mesh to \a name.
1372 # @param obj Shape to be meshed or SMESH_Mesh object
1373 # @param name Study name of the mesh
1374 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1375 self.smeshpyD=smeshpyD
1376 self.geompyD=geompyD
1380 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1382 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1383 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1386 self.mesh = self.smeshpyD.CreateEmptyMesh()
1388 SetName(self.mesh, name)
1390 SetName(self.mesh, GetName(obj))
1392 self.editor = self.mesh.GetMeshEditor()
1394 ## Method that inits the Mesh object from SMESH_Mesh interface
1395 # @param theMesh is SMESH_Mesh object
1396 def SetMesh(self, theMesh):
1398 self.geom = self.mesh.GetShapeToMesh()
1400 ## Method that returns the mesh
1401 # @return SMESH_Mesh object
1407 name = GetName(self.GetMesh())
1411 def SetName(self, name):
1412 SetName(self.GetMesh(), name)
1414 ## Get the subMesh object associated to a subShape. The subMesh object
1415 # gives access to nodes and elements IDs.
1416 # \n SubMesh will be used instead of SubShape in a next idl version to
1417 # adress a specific subMesh...
1418 def GetSubMesh(self, theSubObject, name):
1419 submesh = self.mesh.GetSubMesh(theSubObject, name)
1422 ## Method that returns the shape associated to the mesh
1423 # @return GEOM_Object
1427 ## Method that associates given shape to the mesh(entails the mesh recreation)
1428 # @param geom shape to be meshed(GEOM_Object)
1429 def SetShape(self, geom):
1430 self.mesh = self.smeshpyD.CreateMesh(geom)
1432 ## Return true if hypotheses are defined well
1433 # @param theMesh is an instance of Mesh class
1434 # @param theSubObject subshape of a mesh shape
1435 def IsReadyToCompute(self, theSubObject):
1436 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1438 ## Return errors of hypotheses definintion
1439 # error list is empty if everything is OK
1440 # @param theMesh is an instance of Mesh class
1441 # @param theSubObject subshape of a mesh shape
1442 # @return a list of errors
1443 def GetAlgoState(self, theSubObject):
1444 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1446 ## Return geometrical object the given element is built on.
1447 # The returned geometrical object, if not nil, is either found in the
1448 # study or is published by this method with the given name
1449 # @param theMesh is an instance of Mesh class
1450 # @param theElementID an id of the mesh element
1451 # @param theGeomName user defined name of geometrical object
1452 # @return GEOM::GEOM_Object instance
1453 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1454 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1456 ## Returns mesh dimension depending on shape one
1457 def MeshDimension(self):
1458 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1459 if len( shells ) > 0 :
1461 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1463 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1469 ## Creates a segment discretization 1D algorithm.
1470 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
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 algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1474 # @param geom If defined, subshape to be meshed
1475 def Segment(self, algo=REGULAR, geom=0):
1476 ## if Segment(geom) is called by mistake
1477 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1478 algo, geom = geom, algo
1479 if not algo: algo = REGULAR
1482 return Mesh_Segment(self, geom)
1483 elif algo == PYTHON:
1484 return Mesh_Segment_Python(self, geom)
1485 elif algo == COMPOSITE:
1486 return Mesh_CompositeSegment(self, geom)
1488 return Mesh_Segment(self, geom)
1490 ## Enable creation of nodes and segments usable by 2D algoritms.
1491 # Added nodes and segments must be bound to edges and vertices by
1492 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
1493 # If the optional \a geom parameter is not sets, this algorithm is global.
1494 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1495 # @param geom subshape to be manually meshed
1496 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
1497 def UseExistingSegments(self, geom=0):
1498 algo = Mesh_UseExisting(1,self,geom)
1499 return algo.GetAlgorithm()
1501 ## Enable creation of nodes and faces usable by 3D algoritms.
1502 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
1503 # and SetMeshElementOnShape()
1504 # If the optional \a geom parameter is not sets, this algorithm is global.
1505 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1506 # @param geom subshape to be manually meshed
1507 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
1508 def UseExistingFaces(self, geom=0):
1509 algo = Mesh_UseExisting(2,self,geom)
1510 return algo.GetAlgorithm()
1512 ## Creates a triangle 2D algorithm for faces.
1513 # If the optional \a geom parameter is not sets, this algorithm is global.
1514 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1515 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1516 # @param geom If defined, subshape to be meshed
1517 def Triangle(self, algo=MEFISTO, geom=0):
1518 ## if Triangle(geom) is called by mistake
1519 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1523 return Mesh_Triangle(self, algo, geom)
1525 ## Creates a quadrangle 2D algorithm for faces.
1526 # If the optional \a geom parameter is not sets, this algorithm is global.
1527 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1528 # @param geom If defined, subshape to be meshed
1529 def Quadrangle(self, geom=0):
1530 return Mesh_Quadrangle(self, geom)
1532 ## Creates a tetrahedron 3D algorithm for solids.
1533 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1534 # If the optional \a geom parameter is not sets, this algorithm is global.
1535 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1536 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1537 # @param geom If defined, subshape to be meshed
1538 def Tetrahedron(self, algo=NETGEN, geom=0):
1539 ## if Tetrahedron(geom) is called by mistake
1540 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1541 algo, geom = geom, algo
1542 if not algo: algo = NETGEN
1544 return Mesh_Tetrahedron(self, algo, geom)
1546 ## Creates a hexahedron 3D algorithm for solids.
1547 # If the optional \a geom parameter is not sets, this algorithm is global.
1548 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1549 # @param geom If defined, subshape to be meshed
1550 def Hexahedron(self, geom=0):
1551 return Mesh_Hexahedron(self, geom)
1553 ## Deprecated, only for compatibility!
1554 def Netgen(self, is3D, geom=0):
1555 return Mesh_Netgen(self, is3D, geom)
1557 ## Creates a projection 1D algorithm for edges.
1558 # If the optional \a geom parameter is not sets, this algorithm is global.
1559 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1560 # @param geom If defined, subshape to be meshed
1561 def Projection1D(self, geom=0):
1562 return Mesh_Projection1D(self, geom)
1564 ## Creates a projection 2D algorithm for faces.
1565 # If the optional \a geom parameter is not sets, this algorithm is global.
1566 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1567 # @param geom If defined, subshape to be meshed
1568 def Projection2D(self, geom=0):
1569 return Mesh_Projection2D(self, geom)
1571 ## Creates a projection 3D algorithm for solids.
1572 # If the optional \a geom parameter is not sets, this algorithm is global.
1573 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1574 # @param geom If defined, subshape to be meshed
1575 def Projection3D(self, geom=0):
1576 return Mesh_Projection3D(self, geom)
1578 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1579 # If the optional \a geom parameter is not sets, this algorithm is global.
1580 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1581 # @param geom If defined, subshape to be meshed
1582 def Prism(self, geom=0):
1586 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
1587 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
1588 if nbSolids == 0 or nbSolids == nbShells:
1589 return Mesh_Prism3D(self, geom)
1590 return Mesh_RadialPrism3D(self, geom)
1592 ## Compute the mesh and return the status of the computation
1593 def Compute(self, geom=0):
1594 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1596 print "Compute impossible: mesh is not constructed on geom shape."
1602 ok = self.smeshpyD.Compute(self.mesh, geom)
1603 except SALOME.SALOME_Exception, ex:
1604 print "Mesh computation failed, exception caught:"
1605 print " ", ex.details.text
1608 print "Mesh computation failed, exception caught:"
1609 traceback.print_exc()
1611 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1614 if err.isGlobalAlgo:
1622 reason = '%s %sD algorithm is missing' % (glob, dim)
1623 elif err.state == HYP_MISSING:
1624 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1625 % (glob, dim, name, dim))
1626 elif err.state == HYP_NOTCONFORM:
1627 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1628 elif err.state == HYP_BAD_PARAMETER:
1629 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1630 % ( glob, dim, name ))
1631 elif err.state == HYP_BAD_GEOMETRY:
1632 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1633 'its expectation' % ( glob, dim, name ))
1635 reason = "For unknown reason."+\
1636 " Revise Mesh.Compute() implementation in smesh.py!"
1638 if allReasons != "":
1641 allReasons += reason
1643 if allReasons != "":
1644 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1647 print '"' + GetName(self.mesh) + '"',"has not been computed."
1650 if salome.sg.hasDesktop():
1651 smeshgui = salome.ImportComponentGUI("SMESH")
1652 smeshgui.Init(salome.myStudyId)
1653 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1654 salome.sg.updateObjBrowser(1)
1658 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1659 # The parameter \a fineness [0,-1] defines mesh fineness
1660 def AutomaticTetrahedralization(self, fineness=0):
1661 dim = self.MeshDimension()
1663 self.RemoveGlobalHypotheses()
1664 self.Segment().AutomaticLength(fineness)
1666 self.Triangle().LengthFromEdges()
1669 self.Tetrahedron(NETGEN)
1671 return self.Compute()
1673 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1674 # The parameter \a fineness [0,-1] defines mesh fineness
1675 def AutomaticHexahedralization(self, fineness=0):
1676 dim = self.MeshDimension()
1678 self.RemoveGlobalHypotheses()
1679 self.Segment().AutomaticLength(fineness)
1686 return self.Compute()
1688 ## Assign hypothesis
1689 # @param hyp is a hypothesis to assign
1690 # @param geom is subhape of mesh geometry
1691 def AddHypothesis(self, hyp, geom=0 ):
1692 if isinstance( hyp, Mesh_Algorithm ):
1693 hyp = hyp.GetAlgorithm()
1698 status = self.mesh.AddHypothesis(geom, hyp)
1699 isAlgo = hyp._narrow( SMESH_Algo )
1700 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1703 ## Unassign hypothesis
1704 # @param hyp is a hypothesis to unassign
1705 # @param geom is subhape of mesh geometry
1706 def RemoveHypothesis(self, hyp, geom=0 ):
1707 if isinstance( hyp, Mesh_Algorithm ):
1708 hyp = hyp.GetAlgorithm()
1713 status = self.mesh.RemoveHypothesis(geom, hyp)
1716 ## Get the list of hypothesis added on a geom
1717 # @param geom is subhape of mesh geometry
1718 def GetHypothesisList(self, geom):
1719 return self.mesh.GetHypothesisList( geom )
1721 ## Removes all global hypotheses
1722 def RemoveGlobalHypotheses(self):
1723 current_hyps = self.mesh.GetHypothesisList( self.geom )
1724 for hyp in current_hyps:
1725 self.mesh.RemoveHypothesis( self.geom, hyp )
1729 ## Create a mesh group based on geometric object \a grp
1730 # and give a \a name, \n if this parameter is not defined
1731 # the name is the same as the geometric group name \n
1732 # Note: Works like GroupOnGeom().
1733 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1734 # @param name is the name of the mesh group
1735 # @return SMESH_GroupOnGeom
1736 def Group(self, grp, name=""):
1737 return self.GroupOnGeom(grp, name)
1739 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1740 # Export the mesh in a file with the MED format and choice the \a version of MED format
1741 # @param f is the file name
1742 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1743 def ExportToMED(self, f, version, opt=0):
1744 self.mesh.ExportToMED(f, opt, version)
1746 ## Export the mesh in a file with the MED format
1747 # @param f is the file name
1748 # @param auto_groups boolean parameter for creating/not creating
1749 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1750 # the typical use is auto_groups=false.
1751 # @param version MED format version(MED_V2_1 or MED_V2_2)
1752 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1753 self.mesh.ExportToMED(f, auto_groups, version)
1755 ## Export the mesh in a file with the DAT format
1756 # @param f is the file name
1757 def ExportDAT(self, f):
1758 self.mesh.ExportDAT(f)
1760 ## Export the mesh in a file with the UNV format
1761 # @param f is the file name
1762 def ExportUNV(self, f):
1763 self.mesh.ExportUNV(f)
1765 ## Export the mesh in a file with the STL format
1766 # @param f is the file name
1767 # @param ascii defined the kind of file contents
1768 def ExportSTL(self, f, ascii=1):
1769 self.mesh.ExportSTL(f, ascii)
1772 # Operations with groups:
1773 # ----------------------
1775 ## Creates an empty mesh group
1776 # @param elementType is the type of elements in the group
1777 # @param name is the name of the mesh group
1778 # @return SMESH_Group
1779 def CreateEmptyGroup(self, elementType, name):
1780 return self.mesh.CreateGroup(elementType, name)
1782 ## Creates a mesh group based on geometric object \a grp
1783 # and give a \a name, \n if this parameter is not defined
1784 # the name is the same as the geometric group name
1785 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1786 # @param name is the name of the mesh group
1787 # @return SMESH_GroupOnGeom
1788 def GroupOnGeom(self, grp, name="", typ=None):
1790 name = grp.GetName()
1793 tgeo = str(grp.GetShapeType())
1794 if tgeo == "VERTEX":
1796 elif tgeo == "EDGE":
1798 elif tgeo == "FACE":
1800 elif tgeo == "SOLID":
1802 elif tgeo == "SHELL":
1804 elif tgeo == "COMPOUND":
1805 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1806 print "Mesh.Group: empty geometric group", GetName( grp )
1808 tgeo = self.geompyD.GetType(grp)
1809 if tgeo == geompyDC.ShapeType["VERTEX"]:
1811 elif tgeo == geompyDC.ShapeType["EDGE"]:
1813 elif tgeo == geompyDC.ShapeType["FACE"]:
1815 elif tgeo == geompyDC.ShapeType["SOLID"]:
1819 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1822 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1824 ## Create a mesh group by the given ids of elements
1825 # @param groupName is the name of the mesh group
1826 # @param elementType is the type of elements in the group
1827 # @param elemIDs is the list of ids
1828 # @return SMESH_Group
1829 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1830 group = self.mesh.CreateGroup(elementType, groupName)
1834 ## Create a mesh group by the given conditions
1835 # @param groupName is the name of the mesh group
1836 # @param elementType is the type of elements in the group
1837 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1838 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1839 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
1840 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
1841 # @return SMESH_Group
1845 CritType=FT_Undefined,
1848 UnaryOp=FT_Undefined):
1849 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
1850 group = self.MakeGroupByCriterion(groupName, aCriterion)
1853 ## Create a mesh group by the given criterion
1854 # @param groupName is the name of the mesh group
1855 # @param Criterion is the instance of Criterion class
1856 # @return SMESH_Group
1857 def MakeGroupByCriterion(self, groupName, Criterion):
1858 aFilterMgr = self.smeshpyD.CreateFilterManager()
1859 aFilter = aFilterMgr.CreateFilter()
1861 aCriteria.append(Criterion)
1862 aFilter.SetCriteria(aCriteria)
1863 group = self.MakeGroupByFilter(groupName, aFilter)
1866 ## Create a mesh group by the given criteria(list of criterions)
1867 # @param groupName is the name of the mesh group
1868 # @param Criteria is the list of criterions
1869 # @return SMESH_Group
1870 def MakeGroupByCriteria(self, groupName, theCriteria):
1871 aFilterMgr = self.smeshpyD.CreateFilterManager()
1872 aFilter = aFilterMgr.CreateFilter()
1873 aFilter.SetCriteria(theCriteria)
1874 group = self.MakeGroupByFilter(groupName, aFilter)
1877 ## Create a mesh group by the given filter
1878 # @param groupName is the name of the mesh group
1879 # @param Criterion is the instance of Filter class
1880 # @return SMESH_Group
1881 def MakeGroupByFilter(self, groupName, theFilter):
1882 anIds = theFilter.GetElementsId(self.mesh)
1883 anElemType = theFilter.GetElementType()
1884 group = self.MakeGroupByIds(groupName, anElemType, anIds)
1887 ## Pass mesh elements through the given filter and return ids
1888 # @param theFilter is SMESH_Filter
1889 # @return list of ids
1890 def GetIdsFromFilter(self, theFilter):
1891 return theFilter.GetElementsId(self.mesh)
1893 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
1894 # Returns list of special structures(borders).
1895 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
1896 def GetFreeBorders(self):
1897 aFilterMgr = self.smeshpyD.CreateFilterManager()
1898 aPredicate = aFilterMgr.CreateFreeEdges()
1899 aPredicate.SetMesh(self.mesh)
1900 aBorders = aPredicate.GetBorders()
1904 def RemoveGroup(self, group):
1905 self.mesh.RemoveGroup(group)
1907 ## Remove group with its contents
1908 def RemoveGroupWithContents(self, group):
1909 self.mesh.RemoveGroupWithContents(group)
1911 ## Get the list of groups existing in the mesh
1912 def GetGroups(self):
1913 return self.mesh.GetGroups()
1915 ## Get number of groups existing in the mesh
1917 return self.mesh.NbGroups()
1919 ## Get the list of names of groups existing in the mesh
1920 def GetGroupNames(self):
1921 groups = self.GetGroups()
1923 for group in groups:
1924 names.append(group.GetName())
1927 ## Union of two groups
1928 # New group is created. All mesh elements that are
1929 # present in initial groups are added to the new one
1930 def UnionGroups(self, group1, group2, name):
1931 return self.mesh.UnionGroups(group1, group2, name)
1933 ## Intersection of two groups
1934 # New group is created. All mesh elements that are
1935 # present in both initial groups are added to the new one.
1936 def IntersectGroups(self, group1, group2, name):
1937 return self.mesh.IntersectGroups(group1, group2, name)
1939 ## Cut of two groups
1940 # New group is created. All mesh elements that are present in
1941 # main group but do not present in tool group are added to the new one
1942 def CutGroups(self, mainGroup, toolGroup, name):
1943 return self.mesh.CutGroups(mainGroup, toolGroup, name)
1946 # Get some info about mesh:
1947 # ------------------------
1949 ## Get the log of nodes and elements added or removed since previous
1951 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1952 # @return list of log_block structures:
1957 def GetLog(self, clearAfterGet):
1958 return self.mesh.GetLog(clearAfterGet)
1960 ## Clear the log of nodes and elements added or removed since previous
1961 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1963 self.mesh.ClearLog()
1965 def SetAutoColor(self, color):
1966 self.mesh.SetAutoColor(color)
1968 def GetAutoColor(self):
1969 return self.mesh.GetAutoColor()
1971 ## Get the internal Id
1973 return self.mesh.GetId()
1976 def GetStudyId(self):
1977 return self.mesh.GetStudyId()
1979 ## Check group names for duplications.
1980 # Consider maximum group name length stored in MED file.
1981 def HasDuplicatedGroupNamesMED(self):
1982 return self.mesh.HasDuplicatedGroupNamesMED()
1984 ## Obtain instance of SMESH_MeshEditor
1985 def GetMeshEditor(self):
1986 return self.mesh.GetMeshEditor()
1989 def GetMEDMesh(self):
1990 return self.mesh.GetMEDMesh()
1993 # Get informations about mesh contents:
1994 # ------------------------------------
1996 ## Returns number of nodes in mesh
1998 return self.mesh.NbNodes()
2000 ## Returns number of elements in mesh
2001 def NbElements(self):
2002 return self.mesh.NbElements()
2004 ## Returns number of edges in mesh
2006 return self.mesh.NbEdges()
2008 ## Returns number of edges with given order in mesh
2009 # @param elementOrder is order of elements:
2010 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2011 def NbEdgesOfOrder(self, elementOrder):
2012 return self.mesh.NbEdgesOfOrder(elementOrder)
2014 ## Returns number of faces in mesh
2016 return self.mesh.NbFaces()
2018 ## Returns number of faces with given order in mesh
2019 # @param elementOrder is order of elements:
2020 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2021 def NbFacesOfOrder(self, elementOrder):
2022 return self.mesh.NbFacesOfOrder(elementOrder)
2024 ## Returns number of triangles in mesh
2025 def NbTriangles(self):
2026 return self.mesh.NbTriangles()
2028 ## Returns number of triangles with given order in mesh
2029 # @param elementOrder is order of elements:
2030 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2031 def NbTrianglesOfOrder(self, elementOrder):
2032 return self.mesh.NbTrianglesOfOrder(elementOrder)
2034 ## Returns number of quadrangles in mesh
2035 def NbQuadrangles(self):
2036 return self.mesh.NbQuadrangles()
2038 ## Returns number of quadrangles with given order in mesh
2039 # @param elementOrder is order of elements:
2040 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2041 def NbQuadranglesOfOrder(self, elementOrder):
2042 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2044 ## Returns number of polygons in mesh
2045 def NbPolygons(self):
2046 return self.mesh.NbPolygons()
2048 ## Returns number of volumes in mesh
2049 def NbVolumes(self):
2050 return self.mesh.NbVolumes()
2052 ## Returns number of volumes with given order in mesh
2053 # @param elementOrder is order of elements:
2054 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2055 def NbVolumesOfOrder(self, elementOrder):
2056 return self.mesh.NbVolumesOfOrder(elementOrder)
2058 ## Returns number of tetrahedrons in mesh
2060 return self.mesh.NbTetras()
2062 ## Returns number of tetrahedrons with given order in mesh
2063 # @param elementOrder is order of elements:
2064 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2065 def NbTetrasOfOrder(self, elementOrder):
2066 return self.mesh.NbTetrasOfOrder(elementOrder)
2068 ## Returns number of hexahedrons in mesh
2070 return self.mesh.NbHexas()
2072 ## Returns number of hexahedrons with given order in mesh
2073 # @param elementOrder is order of elements:
2074 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2075 def NbHexasOfOrder(self, elementOrder):
2076 return self.mesh.NbHexasOfOrder(elementOrder)
2078 ## Returns number of pyramids in mesh
2079 def NbPyramids(self):
2080 return self.mesh.NbPyramids()
2082 ## Returns number of pyramids with given order in mesh
2083 # @param elementOrder is order of elements:
2084 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2085 def NbPyramidsOfOrder(self, elementOrder):
2086 return self.mesh.NbPyramidsOfOrder(elementOrder)
2088 ## Returns number of prisms in mesh
2090 return self.mesh.NbPrisms()
2092 ## Returns number of prisms with given order in mesh
2093 # @param elementOrder is order of elements:
2094 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2095 def NbPrismsOfOrder(self, elementOrder):
2096 return self.mesh.NbPrismsOfOrder(elementOrder)
2098 ## Returns number of polyhedrons in mesh
2099 def NbPolyhedrons(self):
2100 return self.mesh.NbPolyhedrons()
2102 ## Returns number of submeshes in mesh
2103 def NbSubMesh(self):
2104 return self.mesh.NbSubMesh()
2106 ## Returns list of mesh elements ids
2107 def GetElementsId(self):
2108 return self.mesh.GetElementsId()
2110 ## Returns list of ids of mesh elements with given type
2111 # @param elementType is required type of elements
2112 def GetElementsByType(self, elementType):
2113 return self.mesh.GetElementsByType(elementType)
2115 ## Returns list of mesh nodes ids
2116 def GetNodesId(self):
2117 return self.mesh.GetNodesId()
2119 # Get informations about mesh elements:
2120 # ------------------------------------
2122 ## Returns type of mesh element
2123 def GetElementType(self, id, iselem):
2124 return self.mesh.GetElementType(id, iselem)
2126 ## Returns list of submesh elements ids
2127 # @param Shape is geom object(subshape) IOR
2128 # Shape must be subshape of a ShapeToMesh()
2129 def GetSubMeshElementsId(self, Shape):
2130 if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)):
2131 ShapeID = Shape.GetSubShapeIndices()[0]
2134 return self.mesh.GetSubMeshElementsId(ShapeID)
2136 ## Returns list of submesh nodes ids
2137 # @param Shape is geom object(subshape) IOR
2138 # Shape must be subshape of a ShapeToMesh()
2139 def GetSubMeshNodesId(self, Shape, all):
2140 if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)):
2141 ShapeID = Shape.GetSubShapeIndices()[0]
2144 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2146 ## Returns list of ids of submesh elements with given type
2147 # @param Shape is geom object(subshape) IOR
2148 # Shape must be subshape of a ShapeToMesh()
2149 def GetSubMeshElementType(self, Shape):
2150 if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)):
2151 ShapeID = Shape.GetSubShapeIndices()[0]
2154 return self.mesh.GetSubMeshElementType(ShapeID)
2156 ## Get mesh description
2158 return self.mesh.Dump()
2161 # Get information about nodes and elements of mesh by its ids:
2162 # -----------------------------------------------------------
2164 ## Get XYZ coordinates of node as list of double
2165 # \n If there is not node for given ID - returns empty list
2166 def GetNodeXYZ(self, id):
2167 return self.mesh.GetNodeXYZ(id)
2169 ## For given node returns list of IDs of inverse elements
2170 # \n If there is not node for given ID - returns empty list
2171 def GetNodeInverseElements(self, id):
2172 return self.mesh.GetNodeInverseElements(id)
2174 ## @brief Return position of a node on shape
2175 # @return SMESH::NodePosition
2176 def GetNodePosition(self,NodeID):
2177 return self.mesh.GetNodePosition(NodeID)
2179 ## If given element is node returns IDs of shape from position
2180 # \n If there is not node for given ID - returns -1
2181 def GetShapeID(self, id):
2182 return self.mesh.GetShapeID(id)
2184 ## For given element returns ID of result shape after
2185 # FindShape() from SMESH_MeshEditor
2186 # \n If there is not element for given ID - returns -1
2187 def GetShapeIDForElem(self,id):
2188 return self.mesh.GetShapeIDForElem(id)
2190 ## Returns number of nodes for given element
2191 # \n If there is not element for given ID - returns -1
2192 def GetElemNbNodes(self, id):
2193 return self.mesh.GetElemNbNodes(id)
2195 ## Returns ID of node by given index for given element
2196 # \n If there is not element for given ID - returns -1
2197 # \n If there is not node for given index - returns -2
2198 def GetElemNode(self, id, index):
2199 return self.mesh.GetElemNode(id, index)
2201 ## Returns IDs of nodes of given element
2202 def GetElemNodes(self, id):
2203 return self.mesh.GetElemNodes(id)
2205 ## Returns true if given node is medium node
2206 # in given quadratic element
2207 def IsMediumNode(self, elementID, nodeID):
2208 return self.mesh.IsMediumNode(elementID, nodeID)
2210 ## Returns true if given node is medium node
2211 # in one of quadratic elements
2212 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2213 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2215 ## Returns number of edges for given element
2216 def ElemNbEdges(self, id):
2217 return self.mesh.ElemNbEdges(id)
2219 ## Returns number of faces for given element
2220 def ElemNbFaces(self, id):
2221 return self.mesh.ElemNbFaces(id)
2223 ## Returns true if given element is polygon
2224 def IsPoly(self, id):
2225 return self.mesh.IsPoly(id)
2227 ## Returns true if given element is quadratic
2228 def IsQuadratic(self, id):
2229 return self.mesh.IsQuadratic(id)
2231 ## Returns XYZ coordinates of bary center for given element
2233 # \n If there is not element for given ID - returns empty list
2234 def BaryCenter(self, id):
2235 return self.mesh.BaryCenter(id)
2238 # Mesh edition (SMESH_MeshEditor functionality):
2239 # ---------------------------------------------
2241 ## Removes elements from mesh by ids
2242 # @param IDsOfElements is list of ids of elements to remove
2243 def RemoveElements(self, IDsOfElements):
2244 return self.editor.RemoveElements(IDsOfElements)
2246 ## Removes nodes from mesh by ids
2247 # @param IDsOfNodes is list of ids of nodes to remove
2248 def RemoveNodes(self, IDsOfNodes):
2249 return self.editor.RemoveNodes(IDsOfNodes)
2251 ## Add node to mesh by coordinates
2252 def AddNode(self, x, y, z):
2253 return self.editor.AddNode( x, y, z)
2256 ## Create edge both similar and quadratic (this is determed
2257 # by number of given nodes).
2258 # @param IdsOfNodes List of node IDs for creation of element.
2259 # Needed order of nodes in this list corresponds to description
2260 # of MED. \n This description is located by the following link:
2261 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2262 def AddEdge(self, IDsOfNodes):
2263 return self.editor.AddEdge(IDsOfNodes)
2265 ## Create face both similar and quadratic (this is determed
2266 # by number of given nodes).
2267 # @param IdsOfNodes List of node IDs for creation of element.
2268 # Needed order of nodes in this list corresponds to description
2269 # of MED. \n This description is located by the following link:
2270 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2271 def AddFace(self, IDsOfNodes):
2272 return self.editor.AddFace(IDsOfNodes)
2274 ## Add polygonal face to mesh by list of nodes ids
2275 def AddPolygonalFace(self, IdsOfNodes):
2276 return self.editor.AddPolygonalFace(IdsOfNodes)
2278 ## Create volume both similar and quadratic (this is determed
2279 # by number of given nodes).
2280 # @param IdsOfNodes List of node IDs for creation of element.
2281 # Needed order of nodes in this list corresponds to description
2282 # of MED. \n This description is located by the following link:
2283 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2284 def AddVolume(self, IDsOfNodes):
2285 return self.editor.AddVolume(IDsOfNodes)
2287 ## Create volume of many faces, giving nodes for each face.
2288 # @param IdsOfNodes List of node IDs for volume creation face by face.
2289 # @param Quantities List of integer values, Quantities[i]
2290 # gives quantity of nodes in face number i.
2291 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2292 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2294 ## Create volume of many faces, giving IDs of existing faces.
2295 # @param IdsOfFaces List of face IDs for volume creation.
2297 # Note: The created volume will refer only to nodes
2298 # of the given faces, not to the faces itself.
2299 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2300 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2303 ## @brief Bind a node to a vertex
2304 # @param NodeID - node ID
2305 # @param Vertex - vertex or vertex ID
2306 # @return True if succeed else raise an exception
2307 def SetNodeOnVertex(self, NodeID, Vertex):
2308 if ( isinstance( Vertex, geompy.GEOM._objref_GEOM_Object)):
2309 VertexID = Vertex.GetSubShapeIndices()[0]
2313 self.editor.SetNodeOnVertex(NodeID, VertexID)
2314 except SALOME.SALOME_Exception, inst:
2315 raise ValueError, inst.details.text
2319 ## @brief Store node position on an edge
2320 # @param NodeID - node ID
2321 # @param Edge - edge or edge ID
2322 # @param paramOnEdge - parameter on edge where the node is located
2323 # @return True if succeed else raise an exception
2324 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2325 if ( isinstance( Edge, geompy.GEOM._objref_GEOM_Object)):
2326 EdgeID = Edge.GetSubShapeIndices()[0]
2330 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2331 except SALOME.SALOME_Exception, inst:
2332 raise ValueError, inst.details.text
2335 ## @brief Store node position on a face
2336 # @param NodeID - node ID
2337 # @param Face - face or face ID
2338 # @param u - U parameter on face where the node is located
2339 # @param v - V parameter on face where the node is located
2340 # @return True if succeed else raise an exception
2341 def SetNodeOnFace(self, NodeID, Face, u, v):
2342 if ( isinstance( Face, geompy.GEOM._objref_GEOM_Object)):
2343 FaceID = Face.GetSubShapeIndices()[0]
2347 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2348 except SALOME.SALOME_Exception, inst:
2349 raise ValueError, inst.details.text
2352 ## @brief Bind a node to a solid
2353 # @param NodeID - node ID
2354 # @param Solid - solid or solid ID
2355 # @return True if succeed else raise an exception
2356 def SetNodeInVolume(self, NodeID, Solid):
2357 if ( isinstance( Solid, geompy.GEOM._objref_GEOM_Object)):
2358 SolidID = Solid.GetSubShapeIndices()[0]
2362 self.editor.SetNodeInVolume(NodeID, SolidID)
2363 except SALOME.SALOME_Exception, inst:
2364 raise ValueError, inst.details.text
2367 ## @brief Bind an element to a shape
2368 # @param ElementID - element ID
2369 # @param Shape - shape or shape ID
2370 # @return True if succeed else raise an exception
2371 def SetMeshElementOnShape(self, ElementID, Shape):
2372 if ( isinstance( Shape, geompy.GEOM._objref_GEOM_Object)):
2373 ShapeID = Shape.GetSubShapeIndices()[0]
2377 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2378 except SALOME.SALOME_Exception, inst:
2379 raise ValueError, inst.details.text
2383 ## Move node with given id
2384 # @param NodeID id of the node
2385 # @param x new X coordinate
2386 # @param y new Y coordinate
2387 # @param z new Z coordinate
2388 def MoveNode(self, NodeID, x, y, z):
2389 return self.editor.MoveNode(NodeID, x, y, z)
2391 ## Find a node closest to a point
2392 # @param x X coordinate of a point
2393 # @param y Y coordinate of a point
2394 # @param z Z coordinate of a point
2395 # @return id of a node
2396 def FindNodeClosestTo(self, x, y, z):
2397 preview = self.mesh.GetMeshEditPreviewer()
2398 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2400 ## Find a node closest to a point and move it to a point location
2401 # @param x X coordinate of a point
2402 # @param y Y coordinate of a point
2403 # @param z Z coordinate of a point
2404 # @return id of a moved node
2405 def MeshToPassThroughAPoint(self, x, y, z):
2406 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2408 ## Replace two neighbour triangles sharing Node1-Node2 link
2409 # with ones built on the same 4 nodes but having other common link.
2410 # @param NodeID1 first node id
2411 # @param NodeID2 second node id
2412 # @return false if proper faces not found
2413 def InverseDiag(self, NodeID1, NodeID2):
2414 return self.editor.InverseDiag(NodeID1, NodeID2)
2416 ## Replace two neighbour triangles sharing Node1-Node2 link
2417 # with a quadrangle built on the same 4 nodes.
2418 # @param NodeID1 first node id
2419 # @param NodeID2 second node id
2420 # @return false if proper faces not found
2421 def DeleteDiag(self, NodeID1, NodeID2):
2422 return self.editor.DeleteDiag(NodeID1, NodeID2)
2424 ## Reorient elements by ids
2425 # @param IDsOfElements if undefined reorient all mesh elements
2426 def Reorient(self, IDsOfElements=None):
2427 if IDsOfElements == None:
2428 IDsOfElements = self.GetElementsId()
2429 return self.editor.Reorient(IDsOfElements)
2431 ## Reorient all elements of the object
2432 # @param theObject is mesh, submesh or group
2433 def ReorientObject(self, theObject):
2434 return self.editor.ReorientObject(theObject)
2436 ## Fuse neighbour triangles into quadrangles.
2437 # @param IDsOfElements The triangles to be fused,
2438 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2439 # @param MaxAngle is a max angle between element normals at which fusion
2440 # is still performed; theMaxAngle is mesured in radians.
2441 # @return TRUE in case of success, FALSE otherwise.
2442 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2443 if IDsOfElements == []:
2444 IDsOfElements = self.GetElementsId()
2445 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2447 ## Fuse neighbour triangles of the object into quadrangles
2448 # @param theObject is mesh, submesh or group
2449 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2450 # @param MaxAngle is a max angle between element normals at which fusion
2451 # is still performed; theMaxAngle is mesured in radians.
2452 # @return TRUE in case of success, FALSE otherwise.
2453 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2454 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2456 ## Split quadrangles into triangles.
2457 # @param IDsOfElements the faces to be splitted.
2458 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2459 # @param @return TRUE in case of success, FALSE otherwise.
2460 def QuadToTri (self, IDsOfElements, theCriterion):
2461 if IDsOfElements == []:
2462 IDsOfElements = self.GetElementsId()
2463 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2465 ## Split quadrangles into triangles.
2466 # @param theObject object to taking list of elements from, is mesh, submesh or group
2467 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2468 def QuadToTriObject (self, theObject, theCriterion):
2469 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2471 ## Split quadrangles into triangles.
2472 # @param theElems The faces to be splitted
2473 # @param the13Diag is used to choose a diagonal for splitting.
2474 # @return TRUE in case of success, FALSE otherwise.
2475 def SplitQuad (self, IDsOfElements, Diag13):
2476 if IDsOfElements == []:
2477 IDsOfElements = self.GetElementsId()
2478 return self.editor.SplitQuad(IDsOfElements, Diag13)
2480 ## Split quadrangles into triangles.
2481 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2482 def SplitQuadObject (self, theObject, Diag13):
2483 return self.editor.SplitQuadObject(theObject, Diag13)
2485 ## Find better splitting of the given quadrangle.
2486 # @param IDOfQuad ID of the quadrangle to be splitted.
2487 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2488 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2489 # diagonal is better, 0 if error occurs.
2490 def BestSplit (self, IDOfQuad, theCriterion):
2491 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2493 ## Split quafrangle faces near triangular facets of volumes
2495 def SplitQuadsNearTriangularFacets(self):
2496 faces_array = self.GetElementsByType(SMESH.FACE)
2497 for face_id in faces_array:
2498 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2499 quad_nodes = self.mesh.GetElemNodes(face_id)
2500 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2501 isVolumeFound = False
2502 for node1_elem in node1_elems:
2503 if not isVolumeFound:
2504 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2505 nb_nodes = self.GetElemNbNodes(node1_elem)
2506 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2507 volume_elem = node1_elem
2508 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2509 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2510 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2511 isVolumeFound = True
2512 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2513 self.SplitQuad([face_id], False) # diagonal 2-4
2514 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2515 isVolumeFound = True
2516 self.SplitQuad([face_id], True) # diagonal 1-3
2517 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2518 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2519 isVolumeFound = True
2520 self.SplitQuad([face_id], True) # diagonal 1-3
2522 ## @brief Split hexahedrons into tetrahedrons.
2524 # Use pattern mapping functionality for splitting.
2525 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2526 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2527 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2528 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2529 # key-point will be mapped into <theNode001>-th node of each volume.
2530 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2531 # @return TRUE in case of success, FALSE otherwise.
2532 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2533 # Pattern: 5.---------.6
2538 # (0,0,1) 4.---------.7 * |
2545 # (0,0,0) 0.---------.3
2546 pattern_tetra = "!!! Nb of points: \n 8 \n\
2556 !!! Indices of points of 6 tetras: \n\
2564 pattern = self.smeshpyD.GetPattern()
2565 isDone = pattern.LoadFromFile(pattern_tetra)
2567 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2570 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2571 isDone = pattern.MakeMesh(self.mesh, False, False)
2572 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2574 # split quafrangle faces near triangular facets of volumes
2575 self.SplitQuadsNearTriangularFacets()
2579 ## @brief Split hexahedrons into prisms.
2581 # Use pattern mapping functionality for splitting.
2582 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2583 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2584 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2585 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2586 # key-point will be mapped into <theNode001>-th node of each volume.
2587 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2588 # @return TRUE in case of success, FALSE otherwise.
2589 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2590 # Pattern: 5.---------.6
2595 # (0,0,1) 4.---------.7 |
2602 # (0,0,0) 0.---------.3
2603 pattern_prism = "!!! Nb of points: \n 8 \n\
2613 !!! Indices of points of 2 prisms: \n\
2617 pattern = self.smeshpyD.GetPattern()
2618 isDone = pattern.LoadFromFile(pattern_prism)
2620 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2623 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2624 isDone = pattern.MakeMesh(self.mesh, False, False)
2625 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2627 # split quafrangle faces near triangular facets of volumes
2628 self.SplitQuadsNearTriangularFacets()
2633 # @param IDsOfElements list if ids of elements to smooth
2634 # @param IDsOfFixedNodes list of ids of fixed nodes.
2635 # Note that nodes built on edges and boundary nodes are always fixed.
2636 # @param MaxNbOfIterations maximum number of iterations
2637 # @param MaxAspectRatio varies in range [1.0, inf]
2638 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2639 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2640 MaxNbOfIterations, MaxAspectRatio, Method):
2641 if IDsOfElements == []:
2642 IDsOfElements = self.GetElementsId()
2643 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2644 MaxNbOfIterations, MaxAspectRatio, Method)
2646 ## Smooth elements belong to given object
2647 # @param theObject object to smooth
2648 # @param IDsOfFixedNodes list of ids of fixed nodes.
2649 # Note that nodes built on edges and boundary nodes are always fixed.
2650 # @param MaxNbOfIterations maximum number of iterations
2651 # @param MaxAspectRatio varies in range [1.0, inf]
2652 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2653 def SmoothObject(self, theObject, IDsOfFixedNodes,
2654 MaxNbOfIterations, MaxxAspectRatio, Method):
2655 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2656 MaxNbOfIterations, MaxxAspectRatio, Method)
2658 ## Parametric smooth the given elements
2659 # @param IDsOfElements list if ids of elements to smooth
2660 # @param IDsOfFixedNodes list of ids of fixed nodes.
2661 # Note that nodes built on edges and boundary nodes are always fixed.
2662 # @param MaxNbOfIterations maximum number of iterations
2663 # @param MaxAspectRatio varies in range [1.0, inf]
2664 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2665 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2666 MaxNbOfIterations, MaxAspectRatio, Method):
2667 if IDsOfElements == []:
2668 IDsOfElements = self.GetElementsId()
2669 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2670 MaxNbOfIterations, MaxAspectRatio, Method)
2672 ## Parametric smooth elements belong to given object
2673 # @param theObject object to smooth
2674 # @param IDsOfFixedNodes list of ids of fixed nodes.
2675 # Note that nodes built on edges and boundary nodes are always fixed.
2676 # @param MaxNbOfIterations maximum number of iterations
2677 # @param MaxAspectRatio varies in range [1.0, inf]
2678 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2679 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2680 MaxNbOfIterations, MaxAspectRatio, Method):
2681 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2682 MaxNbOfIterations, MaxAspectRatio, Method)
2684 ## Converts all mesh to quadratic one, deletes old elements, replacing
2685 # them with quadratic ones with the same id.
2686 def ConvertToQuadratic(self, theForce3d):
2687 self.editor.ConvertToQuadratic(theForce3d)
2689 ## Converts all mesh from quadratic to ordinary ones,
2690 # deletes old quadratic elements, \n replacing
2691 # them with ordinary mesh elements with the same id.
2692 def ConvertFromQuadratic(self):
2693 return self.editor.ConvertFromQuadratic()
2695 ## Renumber mesh nodes
2696 def RenumberNodes(self):
2697 self.editor.RenumberNodes()
2699 ## Renumber mesh elements
2700 def RenumberElements(self):
2701 self.editor.RenumberElements()
2703 ## Generate new elements by rotation of the elements around the axis
2704 # @param IDsOfElements list of ids of elements to sweep
2705 # @param Axix axis of rotation, AxisStruct or line(geom object)
2706 # @param AngleInRadians angle of Rotation
2707 # @param NbOfSteps number of steps
2708 # @param Tolerance tolerance
2709 # @param MakeGroups to generate new groups from existing ones
2710 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2711 if IDsOfElements == []:
2712 IDsOfElements = self.GetElementsId()
2713 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2714 Axix = self.smeshpyD.GetAxisStruct(Axix)
2716 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2717 AngleInRadians, NbOfSteps, Tolerance)
2718 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2721 ## Generate new elements by rotation of the elements of object around the axis
2722 # @param theObject object wich elements should be sweeped
2723 # @param Axix axis of rotation, AxisStruct or line(geom object)
2724 # @param AngleInRadians angle of Rotation
2725 # @param NbOfSteps number of steps
2726 # @param Tolerance tolerance
2727 # @param MakeGroups to generate new groups from existing ones
2728 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2729 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2730 Axix = self.smeshpyD.GetAxisStruct(Axix)
2732 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2733 NbOfSteps, Tolerance)
2734 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2737 ## Generate new elements by extrusion of the elements with given ids
2738 # @param IDsOfElements list of elements ids for extrusion
2739 # @param StepVector vector, defining the direction and value of extrusion
2740 # @param NbOfSteps the number of steps
2741 # @param MakeGroups to generate new groups from existing ones
2742 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2743 if IDsOfElements == []:
2744 IDsOfElements = self.GetElementsId()
2745 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2746 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2748 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2749 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2752 ## Generate new elements by extrusion of the elements with given ids
2753 # @param IDsOfElements is ids of elements
2754 # @param StepVector vector, defining the direction and value of extrusion
2755 # @param NbOfSteps the number of steps
2756 # @param ExtrFlags set flags for performing extrusion
2757 # @param SewTolerance uses for comparing locations of nodes if flag
2758 # EXTRUSION_FLAG_SEW is set
2759 # @param MakeGroups to generate new groups from existing ones
2760 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2761 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2762 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2764 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2765 ExtrFlags, SewTolerance)
2766 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2767 ExtrFlags, SewTolerance)
2770 ## Generate new elements by extrusion of the elements belong to object
2771 # @param theObject object wich elements should be processed
2772 # @param StepVector vector, defining the direction and value of extrusion
2773 # @param NbOfSteps the number of steps
2774 # @param MakeGroups to generate new groups from existing ones
2775 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2776 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2777 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2779 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2780 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2783 ## Generate new elements by extrusion of the elements belong to object
2784 # @param theObject object wich elements should be processed
2785 # @param StepVector vector, defining the direction and value of extrusion
2786 # @param NbOfSteps the number of steps
2787 # @param MakeGroups to generate new groups from existing ones
2788 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2789 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2790 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2792 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2793 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2796 ## Generate new elements by extrusion of the elements belong to object
2797 # @param theObject object wich elements should be processed
2798 # @param StepVector vector, defining the direction and value of extrusion
2799 # @param NbOfSteps the number of steps
2800 # @param MakeGroups to generate new groups from existing ones
2801 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2802 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2803 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2805 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2806 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2809 ## Generate new elements by extrusion of the given elements
2810 # A path of extrusion must be a meshed edge.
2811 # @param IDsOfElements is ids of elements
2812 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2813 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2814 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2815 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2816 # @param Angles list of angles
2817 # @param HasRefPoint allows to use base point
2818 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2819 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2820 # @param MakeGroups to generate new groups from existing ones
2821 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2822 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
2823 HasAngles, Angles, HasRefPoint, RefPoint,
2824 MakeGroups=False, LinearVariation=False):
2825 if IDsOfElements == []:
2826 IDsOfElements = self.GetElementsId()
2827 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2828 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2831 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
2832 PathShape, NodeStart, HasAngles,
2833 Angles, HasRefPoint, RefPoint)
2834 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
2835 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
2837 ## Generate new elements by extrusion of the elements belong to object
2838 # A path of extrusion must be a meshed edge.
2839 # @param IDsOfElements is ids of elements
2840 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2841 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2842 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2843 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2844 # @param Angles list of angles
2845 # @param HasRefPoint allows to use base point
2846 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2847 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
2848 # @param MakeGroups to generate new groups from existing ones
2849 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
2850 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
2851 HasAngles, Angles, HasRefPoint, RefPoint,
2852 MakeGroups=False, LinearVariation=False):
2853 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
2854 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
2856 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
2857 PathShape, NodeStart, HasAngles,
2858 Angles, HasRefPoint, RefPoint)
2859 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
2860 NodeStart, HasAngles, Angles, HasRefPoint,
2863 ## Symmetrical copy of mesh elements
2864 # @param IDsOfElements list of elements ids
2865 # @param Mirror is AxisStruct or geom object(point, line, plane)
2866 # @param theMirrorType is POINT, AXIS or PLANE
2867 # If the Mirror is geom object this parameter is unnecessary
2868 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2869 # @param MakeGroups to generate new groups from existing ones (if Copy)
2870 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2871 if IDsOfElements == []:
2872 IDsOfElements = self.GetElementsId()
2873 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2874 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2875 if Copy and MakeGroups:
2876 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
2877 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
2880 ## Symmetrical copy of object
2881 # @param theObject mesh, submesh or group
2882 # @param Mirror is AxisStruct or geom object(point, line, plane)
2883 # @param theMirrorType is POINT, AXIS or PLANE
2884 # If the Mirror is geom object this parameter is unnecessary
2885 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
2886 # @param MakeGroups to generate new groups from existing ones (if Copy)
2887 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
2888 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
2889 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
2890 if Copy and MakeGroups:
2891 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
2892 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
2895 ## Translates the elements
2896 # @param IDsOfElements list of elements ids
2897 # @param Vector direction of translation(DirStruct or vector)
2898 # @param Copy allows to copy the translated elements
2899 # @param MakeGroups to generate new groups from existing ones (if Copy)
2900 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
2901 if IDsOfElements == []:
2902 IDsOfElements = self.GetElementsId()
2903 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2904 Vector = self.smeshpyD.GetDirStruct(Vector)
2905 if Copy and MakeGroups:
2906 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
2907 self.editor.Translate(IDsOfElements, Vector, Copy)
2910 ## Translates the object
2911 # @param theObject object to translate(mesh, submesh, or group)
2912 # @param Vector direction of translation(DirStruct or geom vector)
2913 # @param Copy allows to copy the translated elements
2914 # @param MakeGroups to generate new groups from existing ones (if Copy)
2915 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
2916 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
2917 Vector = self.smeshpyD.GetDirStruct(Vector)
2918 if Copy and MakeGroups:
2919 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
2920 self.editor.TranslateObject(theObject, Vector, Copy)
2923 ## Rotates the elements
2924 # @param IDsOfElements list of elements ids
2925 # @param Axis axis of rotation(AxisStruct or geom line)
2926 # @param AngleInRadians angle of rotation(in radians)
2927 # @param Copy allows to copy the rotated elements
2928 # @param MakeGroups to generate new groups from existing ones (if Copy)
2929 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
2930 if IDsOfElements == []:
2931 IDsOfElements = self.GetElementsId()
2932 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2933 Axis = self.smeshpyD.GetAxisStruct(Axis)
2934 if Copy and MakeGroups:
2935 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
2936 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
2939 ## Rotates the object
2940 # @param theObject object to rotate(mesh, submesh, or group)
2941 # @param Axis axis of rotation(AxisStruct or geom line)
2942 # @param AngleInRadians angle of rotation(in radians)
2943 # @param Copy allows to copy the rotated elements
2944 # @param MakeGroups to generate new groups from existing ones (if Copy)
2945 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
2946 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
2947 Axis = self.smeshpyD.GetAxisStruct(Axis)
2948 if Copy and MakeGroups:
2949 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
2950 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
2953 ## Find group of nodes close to each other within Tolerance.
2954 # @param Tolerance tolerance value
2955 # @param list of group of nodes
2956 def FindCoincidentNodes (self, Tolerance):
2957 return self.editor.FindCoincidentNodes(Tolerance)
2959 ## Find group of nodes close to each other within Tolerance.
2960 # @param Tolerance tolerance value
2961 # @param SubMeshOrGroup SubMesh or Group
2962 # @param list of group of nodes
2963 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
2964 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
2967 # @param list of group of nodes
2968 def MergeNodes (self, GroupsOfNodes):
2969 self.editor.MergeNodes(GroupsOfNodes)
2971 ## Find elements built on the same nodes.
2972 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
2973 # @return a list of groups of equal elements
2974 def FindEqualElements (self, MeshOrSubMeshOrGroup):
2975 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
2977 ## Merge elements in each given group.
2978 # @param GroupsOfElementsID groups of elements for merging
2979 def MergeElements(self, GroupsOfElementsID):
2980 self.editor.MergeElements(GroupsOfElementsID)
2982 ## Remove all but one of elements built on the same nodes.
2983 def MergeEqualElements(self):
2984 self.editor.MergeEqualElements()
2987 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2988 FirstNodeID2, SecondNodeID2, LastNodeID2,
2989 CreatePolygons, CreatePolyedrs):
2990 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2991 FirstNodeID2, SecondNodeID2, LastNodeID2,
2992 CreatePolygons, CreatePolyedrs)
2994 ## Sew conform free borders
2995 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
2996 FirstNodeID2, SecondNodeID2):
2997 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
2998 FirstNodeID2, SecondNodeID2)
3000 ## Sew border to side
3001 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3002 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3003 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3004 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3006 ## Sew two sides of a mesh. Nodes belonging to Side1 are
3007 # merged with nodes of elements of Side2.
3008 # Number of elements in theSide1 and in theSide2 must be
3009 # equal and they should have similar node connectivity.
3010 # The nodes to merge should belong to sides borders and
3011 # the first node should be linked to the second.
3012 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3013 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3014 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3015 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3016 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3017 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3019 ## Set new nodes for given element.
3020 # @param ide the element id
3021 # @param newIDs nodes ids
3022 # @return If number of nodes is not corresponded to type of element - returns false
3023 def ChangeElemNodes(self, ide, newIDs):
3024 return self.editor.ChangeElemNodes(ide, newIDs)
3026 ## If during last operation of MeshEditor some nodes were
3027 # created this method returns list of it's IDs, \n
3028 # if new nodes not created - returns empty list
3029 def GetLastCreatedNodes(self):
3030 return self.editor.GetLastCreatedNodes()
3032 ## If during last operation of MeshEditor some elements were
3033 # created this method returns list of it's IDs, \n
3034 # if new elements not creared - returns empty list
3035 def GetLastCreatedElems(self):
3036 return self.editor.GetLastCreatedElems()