1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Francis KLOSS, OCC
32 import SMESH # necessary for back compatibility
39 # import NETGENPlugin module if possible
58 NETGEN_1D2D3D = FULL_NETGEN
59 NETGEN_FULL = FULL_NETGEN
64 # MirrorType enumeration
65 POINT = SMESH_MeshEditor.POINT
66 AXIS = SMESH_MeshEditor.AXIS
67 PLANE = SMESH_MeshEditor.PLANE
69 # Smooth_Method enumeration
70 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
71 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
73 # Fineness enumeration(for NETGEN)
81 PrecisionConfusion = 1e-07
83 def IsEqual(val1, val2, tol=PrecisionConfusion):
84 if abs(val1 - val2) < tol:
92 ior = salome.orb.object_to_string(obj)
93 sobj = salome.myStudy.FindObjectIOR(ior)
97 attr = sobj.FindAttribute("AttributeName")[1]
100 ## Sets name to object
101 def SetName(obj, name):
102 ior = salome.orb.object_to_string(obj)
103 sobj = salome.myStudy.FindObjectIOR(ior)
105 attr = sobj.FindAttribute("AttributeName")[1]
108 ## Print error message if a hypothesis was not assigned.
109 def TreatHypoStatus(status, hypName, geomName, isAlgo):
111 hypType = "algorithm"
113 hypType = "hypothesis"
115 if status == HYP_UNKNOWN_FATAL :
116 reason = "for unknown reason"
117 elif status == HYP_INCOMPATIBLE :
118 reason = "this hypothesis mismatches algorithm"
119 elif status == HYP_NOTCONFORM :
120 reason = "not conform mesh would be built"
121 elif status == HYP_ALREADY_EXIST :
122 reason = hypType + " of the same dimension already assigned to this shape"
123 elif status == HYP_BAD_DIM :
124 reason = hypType + " mismatches shape"
125 elif status == HYP_CONCURENT :
126 reason = "there are concurrent hypotheses on sub-shapes"
127 elif status == HYP_BAD_SUBSHAPE :
128 reason = "shape is neither the main one, nor its subshape, nor a valid group"
129 elif status == HYP_BAD_GEOMETRY:
130 reason = "geometry mismatches algorithm's expectation"
131 elif status == HYP_HIDDEN_ALGO:
132 reason = "it is hidden by an algorithm of upper dimension generating all-dimensions elements"
133 elif status == HYP_HIDING_ALGO:
134 reason = "it hides algorithm(s) of lower dimension by generating all-dimensions elements"
137 hypName = '"' + hypName + '"'
138 geomName= '"' + geomName+ '"'
139 if status < HYP_UNKNOWN_FATAL:
140 print hypName, "was assigned to", geomName,"but", reason
142 print hypName, "was not assigned to",geomName,":", reason
145 class smeshDC(SMESH._objref_SMESH_Gen):
147 def init_smesh(self,theStudy,geompyD):
149 self.SetGeomEngine(geompyD)
150 self.SetCurrentStudy(theStudy)
152 def Mesh(self, obj=0, name=0):
153 return Mesh(self,self.geompyD,obj,name)
155 ## Returns long value from enumeration
156 # Uses for SMESH.FunctorType enumeration
157 def EnumToLong(self,theItem):
160 ## Get PointStruct from vertex
161 # @param theVertex is GEOM object(vertex)
162 # @return SMESH.PointStruct
163 def GetPointStruct(self,theVertex):
164 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
165 return PointStruct(x,y,z)
167 ## Get DirStruct from vector
168 # @param theVector is GEOM object(vector)
169 # @return SMESH.DirStruct
170 def GetDirStruct(self,theVector):
171 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
172 if(len(vertices) != 2):
173 print "Error: vector object is incorrect."
175 p1 = self.geompyD.PointCoordinates(vertices[0])
176 p2 = self.geompyD.PointCoordinates(vertices[1])
177 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
178 dirst = DirStruct(pnt)
181 ## Make DirStruct from a triplet
182 # @param x,y,z are vector components
183 # @return SMESH.DirStruct
184 def MakeDirStruct(self,x,y,z):
185 pnt = PointStruct(x,y,z)
186 return DirStruct(pnt)
188 ## Get AxisStruct from object
189 # @param theObj is GEOM object(line or plane)
190 # @return SMESH.AxisStruct
191 def GetAxisStruct(self,theObj):
192 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
194 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
195 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
196 vertex1 = self.geompyD.PointCoordinates(vertex1)
197 vertex2 = self.geompyD.PointCoordinates(vertex2)
198 vertex3 = self.geompyD.PointCoordinates(vertex3)
199 vertex4 = self.geompyD.PointCoordinates(vertex4)
200 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
201 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
202 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] ]
203 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
205 elif len(edges) == 1:
206 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
207 p1 = self.geompyD.PointCoordinates( vertex1 )
208 p2 = self.geompyD.PointCoordinates( vertex2 )
209 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
213 # From SMESH_Gen interface:
214 # ------------------------
216 ## Set the current mode
217 def SetEmbeddedMode( self,theMode ):
218 #self.SetEmbeddedMode(theMode)
219 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
221 ## Get the current mode
222 def IsEmbeddedMode(self):
223 #return self.IsEmbeddedMode()
224 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
226 ## Set the current study
227 def SetCurrentStudy( self, theStudy ):
228 #self.SetCurrentStudy(theStudy)
229 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
231 ## Get the current study
232 def GetCurrentStudy(self):
233 #return self.GetCurrentStudy()
234 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
236 ## Create Mesh object importing data from given UNV file
237 # @return an instance of Mesh class
238 def CreateMeshesFromUNV( self,theFileName ):
239 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
240 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
243 ## Create Mesh object(s) importing data from given MED file
244 # @return a list of Mesh class instances
245 def CreateMeshesFromMED( self,theFileName ):
246 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
248 for iMesh in range(len(aSmeshMeshes)) :
249 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
250 aMeshes.append(aMesh)
251 return aMeshes, aStatus
253 ## Create Mesh object importing data from given STL file
254 # @return an instance of Mesh class
255 def CreateMeshesFromSTL( self, theFileName ):
256 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
257 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
260 ## From SMESH_Gen interface
261 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
262 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
264 ## From SMESH_Gen interface. Creates pattern
265 def GetPattern(self):
266 return SMESH._objref_SMESH_Gen.GetPattern(self)
270 # Filtering. Auxiliary functions:
271 # ------------------------------
273 ## Creates an empty criterion
274 # @return SMESH.Filter.Criterion
275 def GetEmptyCriterion(self):
276 Type = self.EnumToLong(FT_Undefined)
277 Compare = self.EnumToLong(FT_Undefined)
281 UnaryOp = self.EnumToLong(FT_Undefined)
282 BinaryOp = self.EnumToLong(FT_Undefined)
285 Precision = -1 ##@1e-07
286 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
287 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
289 ## Creates a criterion by given parameters
290 # @param elementType is the type of elements(NODE, EDGE, FACE, VOLUME)
291 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
292 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
293 # @param Treshold is threshold value (range of ids as string, shape, numeric)
294 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
295 # @param BinaryOp is binary logical operation FT_LogicalAND, FT_LogicalOR or
296 # FT_Undefined(must be for the last criterion in criteria)
297 # @return SMESH.Filter.Criterion
298 def GetCriterion(self,elementType,
300 Compare = FT_EqualTo,
302 UnaryOp=FT_Undefined,
303 BinaryOp=FT_Undefined):
304 aCriterion = self.GetEmptyCriterion()
305 aCriterion.TypeOfElement = elementType
306 aCriterion.Type = self.EnumToLong(CritType)
310 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
311 aCriterion.Compare = self.EnumToLong(Compare)
312 elif Compare == "=" or Compare == "==":
313 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
315 aCriterion.Compare = self.EnumToLong(FT_LessThan)
317 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
319 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
322 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
323 FT_BelongToCylinder, FT_LyingOnGeom]:
325 if isinstance(aTreshold, geompyDC.GEOM._objref_GEOM_Object):
326 aCriterion.ThresholdStr = GetName(aTreshold)
327 aCriterion.ThresholdID = salome.ObjectToID(aTreshold)
329 print "Error: Treshold should be a shape."
331 elif CritType == FT_RangeOfIds:
333 if isinstance(aTreshold, str):
334 aCriterion.ThresholdStr = aTreshold
336 print "Error: Treshold should be a string."
338 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_BadOrientedVolume]:
339 # Here we do not need treshold
340 if aTreshold == FT_LogicalNOT:
341 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
342 elif aTreshold in [FT_LogicalAND, FT_LogicalOR]:
343 aCriterion.BinaryOp = aTreshold
347 aTreshold = float(aTreshold)
348 aCriterion.Threshold = aTreshold
350 print "Error: Treshold should be a number."
353 if Treshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
354 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
356 if Treshold in [FT_LogicalAND, FT_LogicalOR]:
357 aCriterion.BinaryOp = self.EnumToLong(Treshold)
359 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
360 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
362 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
363 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
367 ## Creates filter by given parameters of criterion
368 # @param elementType is the type of elements in the group
369 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
370 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
371 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
372 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
373 # @return SMESH_Filter
374 def GetFilter(self,elementType,
375 CritType=FT_Undefined,
378 UnaryOp=FT_Undefined):
379 aCriterion = self.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
380 aFilterMgr = self.CreateFilterManager()
381 aFilter = aFilterMgr.CreateFilter()
383 aCriteria.append(aCriterion)
384 aFilter.SetCriteria(aCriteria)
387 ## Creates numerical functor by its type
388 # @param theCrierion is FT_...; functor type
389 # @return SMESH_NumericalFunctor
390 def GetFunctor(self,theCriterion):
391 aFilterMgr = self.CreateFilterManager()
392 if theCriterion == FT_AspectRatio:
393 return aFilterMgr.CreateAspectRatio()
394 elif theCriterion == FT_AspectRatio3D:
395 return aFilterMgr.CreateAspectRatio3D()
396 elif theCriterion == FT_Warping:
397 return aFilterMgr.CreateWarping()
398 elif theCriterion == FT_MinimumAngle:
399 return aFilterMgr.CreateMinimumAngle()
400 elif theCriterion == FT_Taper:
401 return aFilterMgr.CreateTaper()
402 elif theCriterion == FT_Skew:
403 return aFilterMgr.CreateSkew()
404 elif theCriterion == FT_Area:
405 return aFilterMgr.CreateArea()
406 elif theCriterion == FT_Volume3D:
407 return aFilterMgr.CreateVolume3D()
408 elif theCriterion == FT_MultiConnection:
409 return aFilterMgr.CreateMultiConnection()
410 elif theCriterion == FT_MultiConnection2D:
411 return aFilterMgr.CreateMultiConnection2D()
412 elif theCriterion == FT_Length:
413 return aFilterMgr.CreateLength()
414 elif theCriterion == FT_Length2D:
415 return aFilterMgr.CreateLength2D()
417 print "Error: given parameter is not numerucal functor type."
420 #Register the new proxy for SMESH_Gen
421 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
424 ## Mother class to define algorithm, recommended to do not use directly.
427 class Mesh_Algorithm:
428 # @class Mesh_Algorithm
429 # @brief Class Mesh_Algorithm
431 #def __init__(self,smesh):
439 ## Find hypothesis in study by its type name and parameters.
440 # Find only those hypothesis, which was created in smeshpyD engine.
441 def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
442 study = smeshpyD.GetCurrentStudy()
443 #to do: find component by smeshpyD object, not by its data type
444 scomp = study.FindComponent(smeshpyD.ComponentDataType())
445 if scomp is not None:
446 res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
447 # is hypotheses root label exists?
448 if res and hypRoot is not None:
449 iter = study.NewChildIterator(hypRoot)
450 # check all published hypotheses
452 hypo_so_i = iter.Value()
453 attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
456 hypo_o_i = salome.orb.string_to_object(anIOR)
457 if hypo_o_i is not None:
459 hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
460 if hypo_i is not None:
461 # belongs to this engine?
462 if smeshpyD.GetObjectId(hypo_i) > 0:
463 # is it the needed hypothesis?
464 if hypo_i.GetName() == hypname:
466 if CompareMethod(hypo_i, args):
480 ## Find algorithm in study by its type name.
481 # Find only those algorithm, which was created in smeshpyD engine.
482 def FindAlgorithm (self, algoname, smeshpyD):
483 study = smeshpyD.GetCurrentStudy()
484 #to do: find component by smeshpyD object, not by its data type
485 scomp = study.FindComponent(smeshpyD.ComponentDataType())
486 if scomp is not None:
487 res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
488 # is algorithms root label exists?
489 if res and hypRoot is not None:
490 iter = study.NewChildIterator(hypRoot)
491 # check all published algorithms
493 algo_so_i = iter.Value()
494 attr = algo_so_i.FindAttribute("AttributeIOR")[1]
497 algo_o_i = salome.orb.string_to_object(anIOR)
498 if algo_o_i is not None:
500 algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
501 if algo_i is not None:
502 # belongs to this engine?
503 if smeshpyD.GetObjectId(algo_i) > 0:
504 # is it the needed algorithm?
505 if algo_i.GetName() == algoname:
518 ## If the algorithm is global, return 0; \n
519 # else return the submesh associated to this algorithm.
520 def GetSubMesh(self):
523 ## Return the wrapped mesher.
524 def GetAlgorithm(self):
527 ## Get list of hypothesis that can be used with this algorithm
528 def GetCompatibleHypothesis(self):
531 mylist = self.algo.GetCompatibleHypothesis()
539 def SetName(self, name):
540 SetName(self.algo, name)
544 return self.algo.GetId()
547 def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
549 raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
550 algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
552 algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
554 self.Assign(algo, mesh, geom)
558 def Assign(self, algo, mesh, geom):
560 raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
569 name = mesh.geompyD.SubShapeName(geom, piece)
570 mesh.geompyD.addToStudyInFather(piece, geom, name)
571 self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
574 status = mesh.mesh.AddHypothesis(self.geom, self.algo)
575 TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
577 def CompareHyp (self, hyp, args):
578 print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
581 def CompareEqualHyp (self, hyp, args):
585 def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
586 UseExisting=0, CompareMethod=""):
589 if CompareMethod == "": CompareMethod = self.CompareHyp
590 hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
593 hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
599 a = a + s + str(args[i])
603 SetName(hypo, hyp + a)
605 status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
606 TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
610 # Public class: Mesh_Segment
611 # --------------------------
613 ## Class to define a segment 1D algorithm for discretization
616 class Mesh_Segment(Mesh_Algorithm):
618 ## Private constructor.
619 def __init__(self, mesh, geom=0):
620 Mesh_Algorithm.__init__(self)
621 self.Create(mesh, geom, "Regular_1D")
623 ## Define "LocalLength" hypothesis to cut an edge in several segments with the same length
624 # @param l for the length of segments that cut an edge
625 # @param UseExisting if ==true - search existing hypothesis created with
626 # same parameters, else (default) - create new
627 def LocalLength(self, l, UseExisting=0):
628 hyp = self.Hypothesis("LocalLength", [l], UseExisting=UseExisting,
629 CompareMethod=self.CompareLocalLength)
633 ## Check if the given "LocalLength" hypothesis has the same parameters as given arguments
634 def CompareLocalLength(self, hyp, args):
635 return IsEqual(hyp.GetLength(), args[0])
637 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
638 # @param n for the number of segments that cut an edge
639 # @param s for the scale factor (optional)
640 # @param UseExisting if ==true - search existing hypothesis created with
641 # same parameters, else (default) - create new
642 def NumberOfSegments(self, n, s=[], UseExisting=0):
644 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
645 CompareMethod=self.CompareNumberOfSegments)
647 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
648 CompareMethod=self.CompareNumberOfSegments)
649 hyp.SetDistrType( 1 )
650 hyp.SetScaleFactor(s)
651 hyp.SetNumberOfSegments(n)
654 ## Check if the given "NumberOfSegments" hypothesis has the same parameters as given arguments
655 def CompareNumberOfSegments(self, hyp, args):
656 if hyp.GetNumberOfSegments() == args[0]:
660 if hyp.GetDistrType() == 1:
661 if IsEqual(hyp.GetScaleFactor(), args[1]):
665 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
666 # @param start for the length of the first segment
667 # @param end for the length of the last segment
668 # @param UseExisting if ==true - search existing hypothesis created with
669 # same parameters, else (default) - create new
670 def Arithmetic1D(self, start, end, UseExisting=0):
671 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
672 CompareMethod=self.CompareArithmetic1D)
673 hyp.SetLength(start, 1)
674 hyp.SetLength(end , 0)
677 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as given arguments
678 def CompareArithmetic1D(self, hyp, args):
679 if IsEqual(hyp.GetLength(1), args[0]):
680 if IsEqual(hyp.GetLength(0), args[1]):
684 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
685 # @param start for the length of the first segment
686 # @param end for the length of the last segment
687 # @param UseExisting if ==true - search existing hypothesis created with
688 # same parameters, else (default) - create new
689 def StartEndLength(self, start, end, UseExisting=0):
690 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
691 CompareMethod=self.CompareStartEndLength)
692 hyp.SetLength(start, 1)
693 hyp.SetLength(end , 0)
696 ## Check if the given "StartEndLength" hypothesis has the same parameters as given arguments
697 def CompareStartEndLength(self, hyp, args):
698 if IsEqual(hyp.GetLength(1), args[0]):
699 if IsEqual(hyp.GetLength(0), args[1]):
703 ## Define "Deflection1D" hypothesis
704 # @param d for the deflection
705 # @param UseExisting if ==true - search existing hypothesis created with
706 # same parameters, else (default) - create new
707 def Deflection1D(self, d, UseExisting=0):
708 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
709 CompareMethod=self.CompareDeflection1D)
713 ## Check if the given "Deflection1D" hypothesis has the same parameters as given arguments
714 def CompareDeflection1D(self, hyp, args):
715 return IsEqual(hyp.GetDeflection(), args[0])
717 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
718 # the opposite side in the case of quadrangular faces
719 def Propagation(self):
720 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
722 ## Define "AutomaticLength" hypothesis
723 # @param fineness for the fineness [0-1]
724 # @param UseExisting if ==true - search existing hypothesis created with
725 # same parameters, else (default) - create new
726 def AutomaticLength(self, fineness=0, UseExisting=0):
727 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
728 CompareMethod=self.CompareAutomaticLength)
729 hyp.SetFineness( fineness )
732 ## Check if the given "AutomaticLength" hypothesis has the same parameters as given arguments
733 def CompareAutomaticLength(self, hyp, args):
734 return IsEqual(hyp.GetFineness(), args[0])
736 ## Define "SegmentLengthAroundVertex" hypothesis
737 # @param length for the segment length
738 # @param vertex for the length localization: vertex index [0,1] | vertex object.
739 # Any other integer value means what hypo will be set on the
740 # whole 1D shape, where Mesh_Segment algorithm is assigned.
741 # @param UseExisting if ==true - search existing hypothesis created with
742 # same parameters, else (default) - create new
743 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
745 store_geom = self.geom
746 if type(vertex) is types.IntType:
747 if vertex == 0 or vertex == 1:
748 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
756 if self.geom is None:
757 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
758 name = GetName(self.geom)
760 piece = self.mesh.geom
761 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
762 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
763 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
765 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
767 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
768 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
770 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
771 CompareMethod=self.CompareLengthNearVertex)
772 self.geom = store_geom
773 hyp.SetLength( length )
776 ## Check if the given "LengthNearVertex" hypothesis has the same parameters as given arguments
777 def CompareLengthNearVertex(self, hyp, args):
778 return IsEqual(hyp.GetLength(), args[0])
780 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
781 # If the 2D mesher sees that all boundary edges are quadratic ones,
782 # it generates quadratic faces, else it generates linear faces using
783 # medium nodes as if they were vertex ones.
784 # The 3D mesher generates quadratic volumes only if all boundary faces
785 # are quadratic ones, else it fails.
786 def QuadraticMesh(self):
787 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
790 # Public class: Mesh_CompositeSegment
791 # --------------------------
793 ## Class to define a segment 1D algorithm for discretization
796 class Mesh_CompositeSegment(Mesh_Segment):
798 ## Private constructor.
799 def __init__(self, mesh, geom=0):
800 self.Create(mesh, geom, "CompositeSegment_1D")
803 # Public class: Mesh_Segment_Python
804 # ---------------------------------
806 ## Class to define a segment 1D algorithm for discretization with python function
809 class Mesh_Segment_Python(Mesh_Segment):
811 ## Private constructor.
812 def __init__(self, mesh, geom=0):
813 import Python1dPlugin
814 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
816 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
817 # @param n for the number of segments that cut an edge
818 # @param func for the python function that calculate the length of all segments
819 # @param UseExisting if ==true - search existing hypothesis created with
820 # same parameters, else (default) - create new
821 def PythonSplit1D(self, n, func, UseExisting=0):
822 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
823 UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
824 hyp.SetNumberOfSegments(n)
825 hyp.SetPythonLog10RatioFunction(func)
828 ## Check if the given "PythonSplit1D" hypothesis has the same parameters as given arguments
829 def ComparePythonSplit1D(self, hyp, args):
830 #if hyp.GetNumberOfSegments() == args[0]:
831 # if hyp.GetPythonLog10RatioFunction() == args[1]:
835 # Public class: Mesh_Triangle
836 # ---------------------------
838 ## Class to define a triangle 2D algorithm
841 class Mesh_Triangle(Mesh_Algorithm):
850 ## Private constructor.
851 def __init__(self, mesh, algoType, geom=0):
852 Mesh_Algorithm.__init__(self)
854 self.algoType = algoType
855 if algoType == MEFISTO:
856 self.Create(mesh, geom, "MEFISTO_2D")
858 elif algoType == BLSURF:
860 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
861 self.SetPhysicalMesh()
862 elif algoType == NETGEN:
864 print "Warning: NETGENPlugin module unavailable"
866 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
868 elif algoType == NETGEN_2D:
870 print "Warning: NETGENPlugin module unavailable"
872 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
875 ## Define "MaxElementArea" hypothesis to give the maximum area of each triangle
876 # @param area for the maximum area of each triangle
877 # @param UseExisting if ==true - search existing hypothesis created with
878 # same parameters, else (default) - create new
880 # Only for algoType == MEFISTO || NETGEN_2D
881 def MaxElementArea(self, area, UseExisting=0):
882 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
883 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
884 CompareMethod=self.CompareMaxElementArea)
885 hyp.SetMaxElementArea(area)
887 elif self.algoType == NETGEN:
888 print "Netgen 1D-2D algo doesn't support this hypothesis"
891 ## Check if the given "MaxElementArea" hypothesis has the same parameters as given arguments
892 def CompareMaxElementArea(self, hyp, args):
893 return IsEqual(hyp.GetMaxElementArea(), args[0])
895 ## Define "LengthFromEdges" hypothesis to build triangles
896 # based on the length of the edges taken from the wire
898 # Only for algoType == MEFISTO || NETGEN_2D
899 def LengthFromEdges(self):
900 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
901 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
903 elif self.algoType == NETGEN:
904 print "Netgen 1D-2D algo doesn't support this hypothesis"
908 # @param thePhysicalMesh is:
909 # DefaultSize or Custom
910 def SetPhysicalMesh(self, thePhysicalMesh=1):
913 self.params.SetPhysicalMesh(thePhysicalMesh)
916 def SetPhySize(self, theVal):
919 self.params.SetPhySize(theVal)
922 # @param theGeometricMesh is:
923 # DefaultGeom or Custom
924 def SetGeometricMesh(self, theGeometricMesh=0):
927 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
928 self.params.SetGeometricMesh(theGeometricMesh)
930 ## Set AngleMeshS flag
931 def SetAngleMeshS(self, theVal=_angleMeshS):
934 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
935 self.params.SetAngleMeshS(theVal)
937 ## Set Gradation flag
938 def SetGradation(self, theVal=_gradation):
941 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
942 self.params.SetGradation(theVal)
944 ## Set QuadAllowed flag
946 # Only for algoType == NETGEN || NETGEN_2D
947 def SetQuadAllowed(self, toAllow=True):
948 if self.algoType == NETGEN_2D:
949 if toAllow: # add QuadranglePreference
950 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
951 else: # remove QuadranglePreference
952 for hyp in self.mesh.GetHypothesisList( self.geom ):
953 if hyp.GetName() == "QuadranglePreference":
954 self.mesh.RemoveHypothesis( self.geom, hyp )
962 self.params.SetQuadAllowed(toAllow)
965 ## Define "Netgen 2D Parameters" hypothesis
967 # Only for algoType == NETGEN
968 def Parameters(self):
969 if self.algoType == NETGEN:
970 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
971 "libNETGENEngine.so", UseExisting=0)
973 elif self.algoType == MEFISTO:
974 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
976 elif self.algoType == NETGEN_2D:
977 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
978 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
980 elif self.algoType == BLSURF:
981 self.params = self.Hypothesis("BLSURF_Parameters", [],
982 "libBLSURFEngine.so", UseExisting=0)
988 # Only for algoType == NETGEN
989 def SetMaxSize(self, theSize):
992 if self.params is not None:
993 self.params.SetMaxSize(theSize)
995 ## Set SecondOrder flag
997 # Only for algoType == NETGEN
998 def SetSecondOrder(self, theVal):
1001 if self.params is not None:
1002 self.params.SetSecondOrder(theVal)
1004 ## Set Optimize flag
1006 # Only for algoType == NETGEN
1007 def SetOptimize(self, theVal):
1008 if self.params == 0:
1010 if self.params is not None:
1011 self.params.SetOptimize(theVal)
1014 # @param theFineness is:
1015 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
1017 # Only for algoType == NETGEN
1018 def SetFineness(self, theFineness):
1019 if self.params == 0:
1021 if self.params is not None:
1022 self.params.SetFineness(theFineness)
1026 # Only for algoType == NETGEN
1027 def SetGrowthRate(self, theRate):
1028 if self.params == 0:
1030 if self.params is not None:
1031 self.params.SetGrowthRate(theRate)
1035 # Only for algoType == NETGEN
1036 def SetNbSegPerEdge(self, theVal):
1037 if self.params == 0:
1039 if self.params is not None:
1040 self.params.SetNbSegPerEdge(theVal)
1042 ## Set NbSegPerRadius
1044 # Only for algoType == NETGEN
1045 def SetNbSegPerRadius(self, theVal):
1046 if self.params == 0:
1048 if self.params is not None:
1049 self.params.SetNbSegPerRadius(theVal)
1051 ## Set Decimesh flag
1052 def SetDecimesh(self, toAllow=False):
1053 if self.params == 0:
1055 self.params.SetDecimesh(toAllow)
1060 # Public class: Mesh_Quadrangle
1061 # -----------------------------
1063 ## Class to define a quadrangle 2D algorithm
1066 class Mesh_Quadrangle(Mesh_Algorithm):
1068 ## Private constructor.
1069 def __init__(self, mesh, geom=0):
1070 Mesh_Algorithm.__init__(self)
1071 self.Create(mesh, geom, "Quadrangle_2D")
1073 ## Define "QuadranglePreference" hypothesis, forcing construction
1074 # of quadrangles if the number of nodes on opposite edges is not the same
1075 # in the case where the global number of nodes on edges is even
1076 def QuadranglePreference(self):
1077 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
1078 CompareMethod=self.CompareEqualHyp)
1081 # Public class: Mesh_Tetrahedron
1082 # ------------------------------
1084 ## Class to define a tetrahedron 3D algorithm
1087 class Mesh_Tetrahedron(Mesh_Algorithm):
1092 ## Private constructor.
1093 def __init__(self, mesh, algoType, geom=0):
1094 Mesh_Algorithm.__init__(self)
1096 if algoType == NETGEN:
1097 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
1100 elif algoType == GHS3D:
1102 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
1105 elif algoType == FULL_NETGEN:
1107 print "Warning: NETGENPlugin module has not been imported."
1108 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1111 self.algoType = algoType
1113 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
1114 # @param vol for the maximum volume of each tetrahedral
1115 # @param UseExisting if ==true - search existing hypothesis created with
1116 # same parameters, else (default) - create new
1117 def MaxElementVolume(self, vol, UseExisting=0):
1118 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
1119 CompareMethod=self.CompareMaxElementVolume)
1120 hyp.SetMaxElementVolume(vol)
1123 ## Check if the given "MaxElementVolume" hypothesis has the same parameters as given arguments
1124 def CompareMaxElementVolume(self, hyp, args):
1125 return IsEqual(hyp.GetMaxElementVolume(), args[0])
1127 ## Define "Netgen 3D Parameters" hypothesis
1128 def Parameters(self):
1129 if (self.algoType == FULL_NETGEN):
1130 self.params = self.Hypothesis("NETGEN_Parameters", [],
1131 "libNETGENEngine.so", UseExisting=0)
1134 print "Algo doesn't support this hypothesis"
1138 def SetMaxSize(self, theSize):
1139 if self.params == 0:
1141 self.params.SetMaxSize(theSize)
1143 ## Set SecondOrder flag
1144 def SetSecondOrder(self, theVal):
1145 if self.params == 0:
1147 self.params.SetSecondOrder(theVal)
1149 ## Set Optimize flag
1150 def SetOptimize(self, theVal):
1151 if self.params == 0:
1153 self.params.SetOptimize(theVal)
1156 # @param theFineness is:
1157 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
1158 def SetFineness(self, theFineness):
1159 if self.params == 0:
1161 self.params.SetFineness(theFineness)
1164 def SetGrowthRate(self, theRate):
1165 if self.params == 0:
1167 self.params.SetGrowthRate(theRate)
1170 def SetNbSegPerEdge(self, theVal):
1171 if self.params == 0:
1173 self.params.SetNbSegPerEdge(theVal)
1175 ## Set NbSegPerRadius
1176 def SetNbSegPerRadius(self, theVal):
1177 if self.params == 0:
1179 self.params.SetNbSegPerRadius(theVal)
1181 # Public class: Mesh_Hexahedron
1182 # ------------------------------
1184 ## Class to define a hexahedron 3D algorithm
1187 class Mesh_Hexahedron(Mesh_Algorithm):
1192 ## Private constructor.
1193 def __init__(self, mesh, algoType=Hexa, geom=0):
1194 Mesh_Algorithm.__init__(self)
1196 self.algoType = algoType
1198 if algoType == Hexa:
1199 self.Create(mesh, geom, "Hexa_3D")
1202 elif algoType == Hexotic:
1203 import HexoticPlugin
1204 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
1207 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
1208 def MinMaxQuad(self, min=3, max=8, quad=True):
1209 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
1211 self.params.SetHexesMinLevel(min)
1212 self.params.SetHexesMaxLevel(max)
1213 self.params.SetHexoticQuadrangles(quad)
1216 # Deprecated, only for compatibility!
1217 # Public class: Mesh_Netgen
1218 # ------------------------------
1220 ## Class to define a NETGEN-based 2D or 3D algorithm
1221 # that need no discrete boundary (i.e. independent)
1223 # This class is deprecated, only for compatibility!
1226 class Mesh_Netgen(Mesh_Algorithm):
1230 ## Private constructor.
1231 def __init__(self, mesh, is3D, geom=0):
1232 Mesh_Algorithm.__init__(self)
1235 print "Warning: NETGENPlugin module has not been imported."
1239 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1243 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1246 ## Define hypothesis containing parameters of the algorithm
1247 def Parameters(self):
1249 hyp = self.Hypothesis("NETGEN_Parameters", [],
1250 "libNETGENEngine.so", UseExisting=0)
1252 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1253 "libNETGENEngine.so", UseExisting=0)
1256 # Public class: Mesh_Projection1D
1257 # ------------------------------
1259 ## Class to define a projection 1D algorithm
1262 class Mesh_Projection1D(Mesh_Algorithm):
1264 ## Private constructor.
1265 def __init__(self, mesh, geom=0):
1266 Mesh_Algorithm.__init__(self)
1267 self.Create(mesh, geom, "Projection_1D")
1269 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1270 # take a mesh pattern from, and optionally association of vertices
1271 # between the source edge and a target one (where a hipothesis is assigned to)
1272 # @param edge to take nodes distribution from
1273 # @param mesh to take nodes distribution from (optional)
1274 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1275 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1276 # to associate with \a srcV (optional)
1277 # @param UseExisting if ==true - search existing hypothesis created with
1278 # same parameters, else (default) - create new
1279 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1280 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
1282 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
1283 hyp.SetSourceEdge( edge )
1284 if not mesh is None and isinstance(mesh, Mesh):
1285 mesh = mesh.GetMesh()
1286 hyp.SetSourceMesh( mesh )
1287 hyp.SetVertexAssociation( srcV, tgtV )
1290 ## Check if the given "SourceEdge" hypothesis has the same parameters as given arguments
1291 #def CompareSourceEdge(self, hyp, args):
1292 # # seems to be not really useful to reuse existing "SourceEdge" hypothesis
1296 # Public class: Mesh_Projection2D
1297 # ------------------------------
1299 ## Class to define a projection 2D algorithm
1302 class Mesh_Projection2D(Mesh_Algorithm):
1304 ## Private constructor.
1305 def __init__(self, mesh, geom=0):
1306 Mesh_Algorithm.__init__(self)
1307 self.Create(mesh, geom, "Projection_2D")
1309 ## Define "Source Face" hypothesis, specifying a meshed face to
1310 # take a mesh pattern from, and optionally association of vertices
1311 # between the source face and a target one (where a hipothesis is assigned to)
1312 # @param face to take mesh pattern from
1313 # @param mesh to take mesh pattern from (optional)
1314 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1315 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1316 # to associate with \a srcV1 (optional)
1317 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1318 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1319 # to associate with \a srcV2 (optional)
1320 # @param UseExisting if ==true - search existing hypothesis created with
1321 # same parameters, else (default) - create new
1323 # Note: association vertices must belong to one edge of a face
1324 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1325 srcV2=None, tgtV2=None, UseExisting=0):
1326 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1328 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1329 hyp.SetSourceFace( face )
1330 if not mesh is None and isinstance(mesh, Mesh):
1331 mesh = mesh.GetMesh()
1332 hyp.SetSourceMesh( mesh )
1333 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1336 ## Check if the given "SourceFace" hypothesis has the same parameters as given arguments
1337 #def CompareSourceFace(self, hyp, args):
1338 # # seems to be not really useful to reuse existing "SourceFace" hypothesis
1341 # Public class: Mesh_Projection3D
1342 # ------------------------------
1344 ## Class to define a projection 3D algorithm
1347 class Mesh_Projection3D(Mesh_Algorithm):
1349 ## Private constructor.
1350 def __init__(self, mesh, geom=0):
1351 Mesh_Algorithm.__init__(self)
1352 self.Create(mesh, geom, "Projection_3D")
1354 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1355 # take a mesh pattern from, and optionally association of vertices
1356 # between the source solid and a target one (where a hipothesis is assigned to)
1357 # @param solid to take mesh pattern from
1358 # @param mesh to take mesh pattern from (optional)
1359 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1360 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1361 # to associate with \a srcV1 (optional)
1362 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1363 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1364 # to associate with \a srcV2 (optional)
1365 # @param UseExisting - if ==true - search existing hypothesis created with
1366 # same parameters, else (default) - create new
1368 # Note: association vertices must belong to one edge of a solid
1369 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1370 srcV2=0, tgtV2=0, UseExisting=0):
1371 hyp = self.Hypothesis("ProjectionSource3D",
1372 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1374 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1375 hyp.SetSource3DShape( solid )
1376 if not mesh is None and isinstance(mesh, Mesh):
1377 mesh = mesh.GetMesh()
1378 hyp.SetSourceMesh( mesh )
1379 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1382 ## Check if the given "SourceShape3D" hypothesis has the same parameters as given arguments
1383 #def CompareSourceShape3D(self, hyp, args):
1384 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1388 # Public class: Mesh_Prism
1389 # ------------------------
1391 ## Class to define a 3D extrusion algorithm
1394 class Mesh_Prism3D(Mesh_Algorithm):
1396 ## Private constructor.
1397 def __init__(self, mesh, geom=0):
1398 Mesh_Algorithm.__init__(self)
1399 self.Create(mesh, geom, "Prism_3D")
1401 # Public class: Mesh_RadialPrism
1402 # -------------------------------
1404 ## Class to define a Radial Prism 3D algorithm
1407 class Mesh_RadialPrism3D(Mesh_Algorithm):
1409 ## Private constructor.
1410 def __init__(self, mesh, geom=0):
1411 Mesh_Algorithm.__init__(self)
1412 self.Create(mesh, geom, "RadialPrism_3D")
1414 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1415 self.nbLayers = None
1417 ## Return 3D hypothesis holding the 1D one
1418 def Get3DHypothesis(self):
1419 return self.distribHyp
1421 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1422 # hypothes. Returns the created hypothes
1423 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1424 print "OwnHypothesis",hypType
1425 if not self.nbLayers is None:
1426 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1427 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1428 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
1429 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1430 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
1431 self.distribHyp.SetLayerDistribution( hyp )
1434 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1435 # prisms to build between the inner and outer shells
1436 # @param UseExisting if ==true - search existing hypothesis created with
1437 # same parameters, else (default) - create new
1438 def NumberOfLayers(self, n, UseExisting=0):
1439 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1440 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1441 CompareMethod=self.CompareNumberOfLayers)
1442 self.nbLayers.SetNumberOfLayers( n )
1443 return self.nbLayers
1445 ## Check if the given "NumberOfLayers" hypothesis has the same parameters as given arguments
1446 def CompareNumberOfLayers(self, hyp, args):
1447 return IsEqual(hyp.GetNumberOfLayers(), args[0])
1449 ## Define "LocalLength" hypothesis, specifying segment length
1450 # to build between the inner and outer shells
1451 # @param l for the length of segments
1452 def LocalLength(self, l):
1453 hyp = self.OwnHypothesis("LocalLength", [l])
1457 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1458 # prisms to build between the inner and outer shells
1459 # @param n for the number of segments
1460 # @param s for the scale factor (optional)
1461 def NumberOfSegments(self, n, s=[]):
1463 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1465 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1466 hyp.SetDistrType( 1 )
1467 hyp.SetScaleFactor(s)
1468 hyp.SetNumberOfSegments(n)
1471 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1472 # to build between the inner and outer shells as arithmetic length increasing
1473 # @param start for the length of the first segment
1474 # @param end for the length of the last segment
1475 def Arithmetic1D(self, start, end ):
1476 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1477 hyp.SetLength(start, 1)
1478 hyp.SetLength(end , 0)
1481 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1482 # to build between the inner and outer shells as geometric length increasing
1483 # @param start for the length of the first segment
1484 # @param end for the length of the last segment
1485 def StartEndLength(self, start, end):
1486 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1487 hyp.SetLength(start, 1)
1488 hyp.SetLength(end , 0)
1491 ## Define "AutomaticLength" hypothesis, specifying number of segments
1492 # to build between the inner and outer shells
1493 # @param fineness for the fineness [0-1]
1494 def AutomaticLength(self, fineness=0):
1495 hyp = self.OwnHypothesis("AutomaticLength")
1496 hyp.SetFineness( fineness )
1499 # Private class: Mesh_UseExisting
1500 # -------------------------------
1501 class Mesh_UseExisting(Mesh_Algorithm):
1503 def __init__(self, dim, mesh, geom=0):
1505 self.Create(mesh, geom, "UseExisting_1D")
1507 self.Create(mesh, geom, "UseExisting_2D")
1509 # Public class: Mesh
1510 # ==================
1512 ## Class to define a mesh
1514 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1524 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1525 # sets GUI name of this mesh to \a name.
1526 # @param obj Shape to be meshed or SMESH_Mesh object
1527 # @param name Study name of the mesh
1528 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1529 self.smeshpyD=smeshpyD
1530 self.geompyD=geompyD
1534 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1536 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1537 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1540 self.mesh = self.smeshpyD.CreateEmptyMesh()
1542 SetName(self.mesh, name)
1544 SetName(self.mesh, GetName(obj))
1546 self.editor = self.mesh.GetMeshEditor()
1548 ## Method that inits the Mesh object from SMESH_Mesh interface
1549 # @param theMesh is SMESH_Mesh object
1550 def SetMesh(self, theMesh):
1552 self.geom = self.mesh.GetShapeToMesh()
1554 ## Method that returns the mesh
1555 # @return SMESH_Mesh object
1561 name = GetName(self.GetMesh())
1565 def SetName(self, name):
1566 SetName(self.GetMesh(), name)
1568 ## Get the subMesh object associated to a subShape. The subMesh object
1569 # gives access to nodes and elements IDs.
1570 # \n SubMesh will be used instead of SubShape in a next idl version to
1571 # adress a specific subMesh...
1572 def GetSubMesh(self, theSubObject, name):
1573 submesh = self.mesh.GetSubMesh(theSubObject, name)
1576 ## Method that returns the shape associated to the mesh
1577 # @return GEOM_Object
1581 ## Method that associates given shape to the mesh(entails the mesh recreation)
1582 # @param geom shape to be meshed(GEOM_Object)
1583 def SetShape(self, geom):
1584 self.mesh = self.smeshpyD.CreateMesh(geom)
1586 ## Return true if hypotheses are defined well
1587 # @param theMesh is an instance of Mesh class
1588 # @param theSubObject subshape of a mesh shape
1589 def IsReadyToCompute(self, theSubObject):
1590 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1592 ## Return errors of hypotheses definintion
1593 # error list is empty if everything is OK
1594 # @param theMesh is an instance of Mesh class
1595 # @param theSubObject subshape of a mesh shape
1596 # @return a list of errors
1597 def GetAlgoState(self, theSubObject):
1598 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1600 ## Return geometrical object the given element is built on.
1601 # The returned geometrical object, if not nil, is either found in the
1602 # study or is published by this method with the given name
1603 # @param theMesh is an instance of Mesh class
1604 # @param theElementID an id of the mesh element
1605 # @param theGeomName user defined name of geometrical object
1606 # @return GEOM::GEOM_Object instance
1607 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1608 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1610 ## Returns mesh dimension depending on shape one
1611 def MeshDimension(self):
1612 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1613 if len( shells ) > 0 :
1615 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1617 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1623 ## Creates a segment discretization 1D algorithm.
1624 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1625 # If the optional \a geom parameter is not sets, this algorithm is global.
1626 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1627 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1628 # @param geom If defined, subshape to be meshed
1629 def Segment(self, algo=REGULAR, geom=0):
1630 ## if Segment(geom) is called by mistake
1631 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1632 algo, geom = geom, algo
1633 if not algo: algo = REGULAR
1636 return Mesh_Segment(self, geom)
1637 elif algo == PYTHON:
1638 return Mesh_Segment_Python(self, geom)
1639 elif algo == COMPOSITE:
1640 return Mesh_CompositeSegment(self, geom)
1642 return Mesh_Segment(self, geom)
1644 ## Enable creation of nodes and segments usable by 2D algoritms.
1645 # Added nodes and segments must be bound to edges and vertices by
1646 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
1647 # If the optional \a geom parameter is not sets, this algorithm is global.
1648 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1649 # @param geom subshape to be manually meshed
1650 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
1651 def UseExistingSegments(self, geom=0):
1652 algo = Mesh_UseExisting(1,self,geom)
1653 return algo.GetAlgorithm()
1655 ## Enable creation of nodes and faces usable by 3D algoritms.
1656 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
1657 # and SetMeshElementOnShape()
1658 # If the optional \a geom parameter is not sets, this algorithm is global.
1659 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1660 # @param geom subshape to be manually meshed
1661 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
1662 def UseExistingFaces(self, geom=0):
1663 algo = Mesh_UseExisting(2,self,geom)
1664 return algo.GetAlgorithm()
1666 ## Creates a triangle 2D algorithm for faces.
1667 # If the optional \a geom parameter is not sets, this algorithm is global.
1668 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1669 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1670 # @param geom If defined, subshape to be meshed
1671 def Triangle(self, algo=MEFISTO, geom=0):
1672 ## if Triangle(geom) is called by mistake
1673 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1677 return Mesh_Triangle(self, algo, geom)
1679 ## Creates a quadrangle 2D algorithm for faces.
1680 # If the optional \a geom parameter is not sets, this algorithm is global.
1681 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1682 # @param geom If defined, subshape to be meshed
1683 def Quadrangle(self, geom=0):
1684 return Mesh_Quadrangle(self, geom)
1686 ## Creates a tetrahedron 3D algorithm for solids.
1687 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1688 # If the optional \a geom parameter is not sets, this algorithm is global.
1689 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1690 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1691 # @param geom If defined, subshape to be meshed
1692 def Tetrahedron(self, algo=NETGEN, geom=0):
1693 ## if Tetrahedron(geom) is called by mistake
1694 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1695 algo, geom = geom, algo
1696 if not algo: algo = NETGEN
1698 return Mesh_Tetrahedron(self, algo, geom)
1700 ## Creates a hexahedron 3D algorithm for solids.
1701 # If the optional \a geom parameter is not sets, this algorithm is global.
1702 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1703 # @param geom If defined, subshape to be meshed
1704 ## def Hexahedron(self, geom=0):
1705 ## return Mesh_Hexahedron(self, geom)
1706 def Hexahedron(self, algo=Hexa, geom=0):
1707 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1708 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
1709 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
1710 elif geom == 0: algo, geom = Hexa, algo
1711 return Mesh_Hexahedron(self, algo, geom)
1713 ## Deprecated, only for compatibility!
1714 def Netgen(self, is3D, geom=0):
1715 return Mesh_Netgen(self, is3D, geom)
1717 ## Creates a projection 1D algorithm for edges.
1718 # If the optional \a geom parameter is not sets, this algorithm is global.
1719 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1720 # @param geom If defined, subshape to be meshed
1721 def Projection1D(self, geom=0):
1722 return Mesh_Projection1D(self, geom)
1724 ## Creates a projection 2D algorithm for faces.
1725 # If the optional \a geom parameter is not sets, this algorithm is global.
1726 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1727 # @param geom If defined, subshape to be meshed
1728 def Projection2D(self, geom=0):
1729 return Mesh_Projection2D(self, geom)
1731 ## Creates a projection 3D algorithm for solids.
1732 # If the optional \a geom parameter is not sets, this algorithm is global.
1733 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1734 # @param geom If defined, subshape to be meshed
1735 def Projection3D(self, geom=0):
1736 return Mesh_Projection3D(self, geom)
1738 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1739 # If the optional \a geom parameter is not sets, this algorithm is global.
1740 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1741 # @param geom If defined, subshape to be meshed
1742 def Prism(self, geom=0):
1746 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
1747 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
1748 if nbSolids == 0 or nbSolids == nbShells:
1749 return Mesh_Prism3D(self, geom)
1750 return Mesh_RadialPrism3D(self, geom)
1752 ## Compute the mesh and return the status of the computation
1753 def Compute(self, geom=0):
1754 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1756 print "Compute impossible: mesh is not constructed on geom shape."
1762 ok = self.smeshpyD.Compute(self.mesh, geom)
1763 except SALOME.SALOME_Exception, ex:
1764 print "Mesh computation failed, exception caught:"
1765 print " ", ex.details.text
1768 print "Mesh computation failed, exception caught:"
1769 traceback.print_exc()
1771 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1774 if err.isGlobalAlgo:
1782 reason = '%s %sD algorithm is missing' % (glob, dim)
1783 elif err.state == HYP_MISSING:
1784 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1785 % (glob, dim, name, dim))
1786 elif err.state == HYP_NOTCONFORM:
1787 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1788 elif err.state == HYP_BAD_PARAMETER:
1789 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1790 % ( glob, dim, name ))
1791 elif err.state == HYP_BAD_GEOMETRY:
1792 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1793 'its expectation' % ( glob, dim, name ))
1795 reason = "For unknown reason."+\
1796 " Revise Mesh.Compute() implementation in smeshDC.py!"
1798 if allReasons != "":
1801 allReasons += reason
1803 if allReasons != "":
1804 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1807 print '"' + GetName(self.mesh) + '"',"has not been computed."
1810 if salome.sg.hasDesktop():
1811 smeshgui = salome.ImportComponentGUI("SMESH")
1812 smeshgui.Init(salome.myStudyId)
1813 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1814 salome.sg.updateObjBrowser(1)
1818 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1819 # The parameter \a fineness [0,-1] defines mesh fineness
1820 def AutomaticTetrahedralization(self, fineness=0):
1821 dim = self.MeshDimension()
1823 self.RemoveGlobalHypotheses()
1824 self.Segment().AutomaticLength(fineness)
1826 self.Triangle().LengthFromEdges()
1829 self.Tetrahedron(NETGEN)
1831 return self.Compute()
1833 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1834 # The parameter \a fineness [0,-1] defines mesh fineness
1835 def AutomaticHexahedralization(self, fineness=0):
1836 dim = self.MeshDimension()
1838 self.RemoveGlobalHypotheses()
1839 self.Segment().AutomaticLength(fineness)
1846 return self.Compute()
1848 ## Assign hypothesis
1849 # @param hyp is a hypothesis to assign
1850 # @param geom is subhape of mesh geometry
1851 def AddHypothesis(self, hyp, geom=0):
1852 if isinstance( hyp, Mesh_Algorithm ):
1853 hyp = hyp.GetAlgorithm()
1858 status = self.mesh.AddHypothesis(geom, hyp)
1859 isAlgo = hyp._narrow( SMESH_Algo )
1860 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1863 ## Unassign hypothesis
1864 # @param hyp is a hypothesis to unassign
1865 # @param geom is subhape of mesh geometry
1866 def RemoveHypothesis(self, hyp, geom=0):
1867 if isinstance( hyp, Mesh_Algorithm ):
1868 hyp = hyp.GetAlgorithm()
1873 status = self.mesh.RemoveHypothesis(geom, hyp)
1876 ## Get the list of hypothesis added on a geom
1877 # @param geom is subhape of mesh geometry
1878 def GetHypothesisList(self, geom):
1879 return self.mesh.GetHypothesisList( geom )
1881 ## Removes all global hypotheses
1882 def RemoveGlobalHypotheses(self):
1883 current_hyps = self.mesh.GetHypothesisList( self.geom )
1884 for hyp in current_hyps:
1885 self.mesh.RemoveHypothesis( self.geom, hyp )
1889 ## Create a mesh group based on geometric object \a grp
1890 # and give a \a name, \n if this parameter is not defined
1891 # the name is the same as the geometric group name \n
1892 # Note: Works like GroupOnGeom().
1893 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1894 # @param name is the name of the mesh group
1895 # @return SMESH_GroupOnGeom
1896 def Group(self, grp, name=""):
1897 return self.GroupOnGeom(grp, name)
1899 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1900 # Export the mesh in a file with the MED format and choice the \a version of MED format
1901 # @param f is the file name
1902 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1903 def ExportToMED(self, f, version, opt=0):
1904 self.mesh.ExportToMED(f, opt, version)
1906 ## Export the mesh in a file with the MED format
1907 # @param f is the file name
1908 # @param auto_groups boolean parameter for creating/not creating
1909 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1910 # the typical use is auto_groups=false.
1911 # @param version MED format version(MED_V2_1 or MED_V2_2)
1912 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1913 self.mesh.ExportToMED(f, auto_groups, version)
1915 ## Export the mesh in a file with the DAT format
1916 # @param f is the file name
1917 def ExportDAT(self, f):
1918 self.mesh.ExportDAT(f)
1920 ## Export the mesh in a file with the UNV format
1921 # @param f is the file name
1922 def ExportUNV(self, f):
1923 self.mesh.ExportUNV(f)
1925 ## Export the mesh in a file with the STL format
1926 # @param f is the file name
1927 # @param ascii defined the kind of file contents
1928 def ExportSTL(self, f, ascii=1):
1929 self.mesh.ExportSTL(f, ascii)
1932 # Operations with groups:
1933 # ----------------------
1935 ## Creates an empty mesh group
1936 # @param elementType is the type of elements in the group
1937 # @param name is the name of the mesh group
1938 # @return SMESH_Group
1939 def CreateEmptyGroup(self, elementType, name):
1940 return self.mesh.CreateGroup(elementType, name)
1942 ## Creates a mesh group based on geometric object \a grp
1943 # and give a \a name, \n if this parameter is not defined
1944 # the name is the same as the geometric group name
1945 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1946 # @param name is the name of the mesh group
1947 # @return SMESH_GroupOnGeom
1948 def GroupOnGeom(self, grp, name="", typ=None):
1950 name = grp.GetName()
1953 tgeo = str(grp.GetShapeType())
1954 if tgeo == "VERTEX":
1956 elif tgeo == "EDGE":
1958 elif tgeo == "FACE":
1960 elif tgeo == "SOLID":
1962 elif tgeo == "SHELL":
1964 elif tgeo == "COMPOUND":
1965 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1966 print "Mesh.Group: empty geometric group", GetName( grp )
1968 tgeo = self.geompyD.GetType(grp)
1969 if tgeo == geompyDC.ShapeType["VERTEX"]:
1971 elif tgeo == geompyDC.ShapeType["EDGE"]:
1973 elif tgeo == geompyDC.ShapeType["FACE"]:
1975 elif tgeo == geompyDC.ShapeType["SOLID"]:
1979 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1982 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1984 ## Create a mesh group by the given ids of elements
1985 # @param groupName is the name of the mesh group
1986 # @param elementType is the type of elements in the group
1987 # @param elemIDs is the list of ids
1988 # @return SMESH_Group
1989 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1990 group = self.mesh.CreateGroup(elementType, groupName)
1994 ## Create a mesh group by the given conditions
1995 # @param groupName is the name of the mesh group
1996 # @param elementType is the type of elements in the group
1997 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1998 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1999 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
2000 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
2001 # @return SMESH_Group
2005 CritType=FT_Undefined,
2008 UnaryOp=FT_Undefined):
2009 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
2010 group = self.MakeGroupByCriterion(groupName, aCriterion)
2013 ## Create a mesh group by the given criterion
2014 # @param groupName is the name of the mesh group
2015 # @param Criterion is the instance of Criterion class
2016 # @return SMESH_Group
2017 def MakeGroupByCriterion(self, groupName, Criterion):
2018 aFilterMgr = self.smeshpyD.CreateFilterManager()
2019 aFilter = aFilterMgr.CreateFilter()
2021 aCriteria.append(Criterion)
2022 aFilter.SetCriteria(aCriteria)
2023 group = self.MakeGroupByFilter(groupName, aFilter)
2026 ## Create a mesh group by the given criteria(list of criterions)
2027 # @param groupName is the name of the mesh group
2028 # @param Criteria is the list of criterions
2029 # @return SMESH_Group
2030 def MakeGroupByCriteria(self, groupName, theCriteria):
2031 aFilterMgr = self.smeshpyD.CreateFilterManager()
2032 aFilter = aFilterMgr.CreateFilter()
2033 aFilter.SetCriteria(theCriteria)
2034 group = self.MakeGroupByFilter(groupName, aFilter)
2037 ## Create a mesh group by the given filter
2038 # @param groupName is the name of the mesh group
2039 # @param Criterion is the instance of Filter class
2040 # @return SMESH_Group
2041 def MakeGroupByFilter(self, groupName, theFilter):
2042 anIds = theFilter.GetElementsId(self.mesh)
2043 anElemType = theFilter.GetElementType()
2044 group = self.MakeGroupByIds(groupName, anElemType, anIds)
2047 ## Pass mesh elements through the given filter and return ids
2048 # @param theFilter is SMESH_Filter
2049 # @return list of ids
2050 def GetIdsFromFilter(self, theFilter):
2051 return theFilter.GetElementsId(self.mesh)
2053 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
2054 # Returns list of special structures(borders).
2055 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
2056 def GetFreeBorders(self):
2057 aFilterMgr = self.smeshpyD.CreateFilterManager()
2058 aPredicate = aFilterMgr.CreateFreeEdges()
2059 aPredicate.SetMesh(self.mesh)
2060 aBorders = aPredicate.GetBorders()
2064 def RemoveGroup(self, group):
2065 self.mesh.RemoveGroup(group)
2067 ## Remove group with its contents
2068 def RemoveGroupWithContents(self, group):
2069 self.mesh.RemoveGroupWithContents(group)
2071 ## Get the list of groups existing in the mesh
2072 def GetGroups(self):
2073 return self.mesh.GetGroups()
2075 ## Get number of groups existing in the mesh
2077 return self.mesh.NbGroups()
2079 ## Get the list of names of groups existing in the mesh
2080 def GetGroupNames(self):
2081 groups = self.GetGroups()
2083 for group in groups:
2084 names.append(group.GetName())
2087 ## Union of two groups
2088 # New group is created. All mesh elements that are
2089 # present in initial groups are added to the new one
2090 def UnionGroups(self, group1, group2, name):
2091 return self.mesh.UnionGroups(group1, group2, name)
2093 ## Intersection of two groups
2094 # New group is created. All mesh elements that are
2095 # present in both initial groups are added to the new one.
2096 def IntersectGroups(self, group1, group2, name):
2097 return self.mesh.IntersectGroups(group1, group2, name)
2099 ## Cut of two groups
2100 # New group is created. All mesh elements that are present in
2101 # main group but do not present in tool group are added to the new one
2102 def CutGroups(self, mainGroup, toolGroup, name):
2103 return self.mesh.CutGroups(mainGroup, toolGroup, name)
2106 # Get some info about mesh:
2107 # ------------------------
2109 ## Get the log of nodes and elements added or removed since previous
2111 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
2112 # @return list of log_block structures:
2117 def GetLog(self, clearAfterGet):
2118 return self.mesh.GetLog(clearAfterGet)
2120 ## Clear the log of nodes and elements added or removed since previous
2121 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2123 self.mesh.ClearLog()
2125 def SetAutoColor(self, color):
2126 self.mesh.SetAutoColor(color)
2128 def GetAutoColor(self):
2129 return self.mesh.GetAutoColor()
2131 ## Get the internal Id
2133 return self.mesh.GetId()
2136 def GetStudyId(self):
2137 return self.mesh.GetStudyId()
2139 ## Check group names for duplications.
2140 # Consider maximum group name length stored in MED file.
2141 def HasDuplicatedGroupNamesMED(self):
2142 return self.mesh.HasDuplicatedGroupNamesMED()
2144 ## Obtain instance of SMESH_MeshEditor
2145 def GetMeshEditor(self):
2146 return self.mesh.GetMeshEditor()
2149 def GetMEDMesh(self):
2150 return self.mesh.GetMEDMesh()
2153 # Get informations about mesh contents:
2154 # ------------------------------------
2156 ## Returns number of nodes in mesh
2158 return self.mesh.NbNodes()
2160 ## Returns number of elements in mesh
2161 def NbElements(self):
2162 return self.mesh.NbElements()
2164 ## Returns number of edges in mesh
2166 return self.mesh.NbEdges()
2168 ## Returns number of edges with given order in mesh
2169 # @param elementOrder is order of elements:
2170 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2171 def NbEdgesOfOrder(self, elementOrder):
2172 return self.mesh.NbEdgesOfOrder(elementOrder)
2174 ## Returns number of faces in mesh
2176 return self.mesh.NbFaces()
2178 ## Returns number of faces with given order in mesh
2179 # @param elementOrder is order of elements:
2180 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2181 def NbFacesOfOrder(self, elementOrder):
2182 return self.mesh.NbFacesOfOrder(elementOrder)
2184 ## Returns number of triangles in mesh
2185 def NbTriangles(self):
2186 return self.mesh.NbTriangles()
2188 ## Returns number of triangles with given order in mesh
2189 # @param elementOrder is order of elements:
2190 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2191 def NbTrianglesOfOrder(self, elementOrder):
2192 return self.mesh.NbTrianglesOfOrder(elementOrder)
2194 ## Returns number of quadrangles in mesh
2195 def NbQuadrangles(self):
2196 return self.mesh.NbQuadrangles()
2198 ## Returns number of quadrangles with given order in mesh
2199 # @param elementOrder is order of elements:
2200 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2201 def NbQuadranglesOfOrder(self, elementOrder):
2202 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2204 ## Returns number of polygons in mesh
2205 def NbPolygons(self):
2206 return self.mesh.NbPolygons()
2208 ## Returns number of volumes in mesh
2209 def NbVolumes(self):
2210 return self.mesh.NbVolumes()
2212 ## Returns number of volumes with given order in mesh
2213 # @param elementOrder is order of elements:
2214 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2215 def NbVolumesOfOrder(self, elementOrder):
2216 return self.mesh.NbVolumesOfOrder(elementOrder)
2218 ## Returns number of tetrahedrons in mesh
2220 return self.mesh.NbTetras()
2222 ## Returns number of tetrahedrons with given order in mesh
2223 # @param elementOrder is order of elements:
2224 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2225 def NbTetrasOfOrder(self, elementOrder):
2226 return self.mesh.NbTetrasOfOrder(elementOrder)
2228 ## Returns number of hexahedrons in mesh
2230 return self.mesh.NbHexas()
2232 ## Returns number of hexahedrons with given order in mesh
2233 # @param elementOrder is order of elements:
2234 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2235 def NbHexasOfOrder(self, elementOrder):
2236 return self.mesh.NbHexasOfOrder(elementOrder)
2238 ## Returns number of pyramids in mesh
2239 def NbPyramids(self):
2240 return self.mesh.NbPyramids()
2242 ## Returns number of pyramids with given order in mesh
2243 # @param elementOrder is order of elements:
2244 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2245 def NbPyramidsOfOrder(self, elementOrder):
2246 return self.mesh.NbPyramidsOfOrder(elementOrder)
2248 ## Returns number of prisms in mesh
2250 return self.mesh.NbPrisms()
2252 ## Returns number of prisms with given order in mesh
2253 # @param elementOrder is order of elements:
2254 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2255 def NbPrismsOfOrder(self, elementOrder):
2256 return self.mesh.NbPrismsOfOrder(elementOrder)
2258 ## Returns number of polyhedrons in mesh
2259 def NbPolyhedrons(self):
2260 return self.mesh.NbPolyhedrons()
2262 ## Returns number of submeshes in mesh
2263 def NbSubMesh(self):
2264 return self.mesh.NbSubMesh()
2266 ## Returns list of mesh elements ids
2267 def GetElementsId(self):
2268 return self.mesh.GetElementsId()
2270 ## Returns list of ids of mesh elements with given type
2271 # @param elementType is required type of elements
2272 def GetElementsByType(self, elementType):
2273 return self.mesh.GetElementsByType(elementType)
2275 ## Returns list of mesh nodes ids
2276 def GetNodesId(self):
2277 return self.mesh.GetNodesId()
2279 # Get informations about mesh elements:
2280 # ------------------------------------
2282 ## Returns type of mesh element
2283 def GetElementType(self, id, iselem):
2284 return self.mesh.GetElementType(id, iselem)
2286 ## Returns list of submesh elements ids
2287 # @param Shape is geom object(subshape) IOR
2288 # Shape must be subshape of a ShapeToMesh()
2289 def GetSubMeshElementsId(self, Shape):
2290 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2291 ShapeID = Shape.GetSubShapeIndices()[0]
2294 return self.mesh.GetSubMeshElementsId(ShapeID)
2296 ## Returns list of submesh nodes ids
2297 # @param Shape is geom object(subshape) IOR
2298 # Shape must be subshape of a ShapeToMesh()
2299 def GetSubMeshNodesId(self, Shape, all):
2300 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2301 ShapeID = Shape.GetSubShapeIndices()[0]
2304 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2306 ## Returns list of ids of submesh elements with given type
2307 # @param Shape is geom object(subshape) IOR
2308 # Shape must be subshape of a ShapeToMesh()
2309 def GetSubMeshElementType(self, Shape):
2310 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2311 ShapeID = Shape.GetSubShapeIndices()[0]
2314 return self.mesh.GetSubMeshElementType(ShapeID)
2316 ## Get mesh description
2318 return self.mesh.Dump()
2321 # Get information about nodes and elements of mesh by its ids:
2322 # -----------------------------------------------------------
2324 ## Get XYZ coordinates of node as list of double
2325 # \n If there is not node for given ID - returns empty list
2326 def GetNodeXYZ(self, id):
2327 return self.mesh.GetNodeXYZ(id)
2329 ## For given node returns list of IDs of inverse elements
2330 # \n If there is not node for given ID - returns empty list
2331 def GetNodeInverseElements(self, id):
2332 return self.mesh.GetNodeInverseElements(id)
2334 ## @brief Return position of a node on shape
2335 # @return SMESH::NodePosition
2336 def GetNodePosition(self,NodeID):
2337 return self.mesh.GetNodePosition(NodeID)
2339 ## If given element is node returns IDs of shape from position
2340 # \n If there is not node for given ID - returns -1
2341 def GetShapeID(self, id):
2342 return self.mesh.GetShapeID(id)
2344 ## For given element returns ID of result shape after
2345 # FindShape() from SMESH_MeshEditor
2346 # \n If there is not element for given ID - returns -1
2347 def GetShapeIDForElem(self,id):
2348 return self.mesh.GetShapeIDForElem(id)
2350 ## Returns number of nodes for given element
2351 # \n If there is not element for given ID - returns -1
2352 def GetElemNbNodes(self, id):
2353 return self.mesh.GetElemNbNodes(id)
2355 ## Returns ID of node by given index for given element
2356 # \n If there is not element for given ID - returns -1
2357 # \n If there is not node for given index - returns -2
2358 def GetElemNode(self, id, index):
2359 return self.mesh.GetElemNode(id, index)
2361 ## Returns IDs of nodes of given element
2362 def GetElemNodes(self, id):
2363 return self.mesh.GetElemNodes(id)
2365 ## Returns true if given node is medium node
2366 # in given quadratic element
2367 def IsMediumNode(self, elementID, nodeID):
2368 return self.mesh.IsMediumNode(elementID, nodeID)
2370 ## Returns true if given node is medium node
2371 # in one of quadratic elements
2372 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2373 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2375 ## Returns number of edges for given element
2376 def ElemNbEdges(self, id):
2377 return self.mesh.ElemNbEdges(id)
2379 ## Returns number of faces for given element
2380 def ElemNbFaces(self, id):
2381 return self.mesh.ElemNbFaces(id)
2383 ## Returns true if given element is polygon
2384 def IsPoly(self, id):
2385 return self.mesh.IsPoly(id)
2387 ## Returns true if given element is quadratic
2388 def IsQuadratic(self, id):
2389 return self.mesh.IsQuadratic(id)
2391 ## Returns XYZ coordinates of bary center for given element
2393 # \n If there is not element for given ID - returns empty list
2394 def BaryCenter(self, id):
2395 return self.mesh.BaryCenter(id)
2398 # Mesh edition (SMESH_MeshEditor functionality):
2399 # ---------------------------------------------
2401 ## Removes elements from mesh by ids
2402 # @param IDsOfElements is list of ids of elements to remove
2403 def RemoveElements(self, IDsOfElements):
2404 return self.editor.RemoveElements(IDsOfElements)
2406 ## Removes nodes from mesh by ids
2407 # @param IDsOfNodes is list of ids of nodes to remove
2408 def RemoveNodes(self, IDsOfNodes):
2409 return self.editor.RemoveNodes(IDsOfNodes)
2411 ## Add node to mesh by coordinates
2412 def AddNode(self, x, y, z):
2413 return self.editor.AddNode( x, y, z)
2416 ## Create edge both similar and quadratic (this is determed
2417 # by number of given nodes).
2418 # @param IdsOfNodes List of node IDs for creation of element.
2419 # Needed order of nodes in this list corresponds to description
2420 # of MED. \n This description is located by the following link:
2421 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2422 def AddEdge(self, IDsOfNodes):
2423 return self.editor.AddEdge(IDsOfNodes)
2425 ## Create face both similar and quadratic (this is determed
2426 # by number of given nodes).
2427 # @param IdsOfNodes List of node IDs for creation of element.
2428 # Needed order of nodes in this list corresponds to description
2429 # of MED. \n This description is located by the following link:
2430 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2431 def AddFace(self, IDsOfNodes):
2432 return self.editor.AddFace(IDsOfNodes)
2434 ## Add polygonal face to mesh by list of nodes ids
2435 def AddPolygonalFace(self, IdsOfNodes):
2436 return self.editor.AddPolygonalFace(IdsOfNodes)
2438 ## Create volume both similar and quadratic (this is determed
2439 # by number of given nodes).
2440 # @param IdsOfNodes List of node IDs for creation of element.
2441 # Needed order of nodes in this list corresponds to description
2442 # of MED. \n This description is located by the following link:
2443 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2444 def AddVolume(self, IDsOfNodes):
2445 return self.editor.AddVolume(IDsOfNodes)
2447 ## Create volume of many faces, giving nodes for each face.
2448 # @param IdsOfNodes List of node IDs for volume creation face by face.
2449 # @param Quantities List of integer values, Quantities[i]
2450 # gives quantity of nodes in face number i.
2451 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2452 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2454 ## Create volume of many faces, giving IDs of existing faces.
2455 # @param IdsOfFaces List of face IDs for volume creation.
2457 # Note: The created volume will refer only to nodes
2458 # of the given faces, not to the faces itself.
2459 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2460 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2463 ## @brief Bind a node to a vertex
2464 # @param NodeID - node ID
2465 # @param Vertex - vertex or vertex ID
2466 # @return True if succeed else raise an exception
2467 def SetNodeOnVertex(self, NodeID, Vertex):
2468 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2469 VertexID = Vertex.GetSubShapeIndices()[0]
2473 self.editor.SetNodeOnVertex(NodeID, VertexID)
2474 except SALOME.SALOME_Exception, inst:
2475 raise ValueError, inst.details.text
2479 ## @brief Store node position on an edge
2480 # @param NodeID - node ID
2481 # @param Edge - edge or edge ID
2482 # @param paramOnEdge - parameter on edge where the node is located
2483 # @return True if succeed else raise an exception
2484 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2485 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2486 EdgeID = Edge.GetSubShapeIndices()[0]
2490 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2491 except SALOME.SALOME_Exception, inst:
2492 raise ValueError, inst.details.text
2495 ## @brief Store node position on a face
2496 # @param NodeID - node ID
2497 # @param Face - face or face ID
2498 # @param u - U parameter on face where the node is located
2499 # @param v - V parameter on face where the node is located
2500 # @return True if succeed else raise an exception
2501 def SetNodeOnFace(self, NodeID, Face, u, v):
2502 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2503 FaceID = Face.GetSubShapeIndices()[0]
2507 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2508 except SALOME.SALOME_Exception, inst:
2509 raise ValueError, inst.details.text
2512 ## @brief Bind a node to a solid
2513 # @param NodeID - node ID
2514 # @param Solid - solid or solid ID
2515 # @return True if succeed else raise an exception
2516 def SetNodeInVolume(self, NodeID, Solid):
2517 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2518 SolidID = Solid.GetSubShapeIndices()[0]
2522 self.editor.SetNodeInVolume(NodeID, SolidID)
2523 except SALOME.SALOME_Exception, inst:
2524 raise ValueError, inst.details.text
2527 ## @brief Bind an element to a shape
2528 # @param ElementID - element ID
2529 # @param Shape - shape or shape ID
2530 # @return True if succeed else raise an exception
2531 def SetMeshElementOnShape(self, ElementID, Shape):
2532 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2533 ShapeID = Shape.GetSubShapeIndices()[0]
2537 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2538 except SALOME.SALOME_Exception, inst:
2539 raise ValueError, inst.details.text
2543 ## Move node with given id
2544 # @param NodeID id of the node
2545 # @param x new X coordinate
2546 # @param y new Y coordinate
2547 # @param z new Z coordinate
2548 def MoveNode(self, NodeID, x, y, z):
2549 return self.editor.MoveNode(NodeID, x, y, z)
2551 ## Find a node closest to a point
2552 # @param x X coordinate of a point
2553 # @param y Y coordinate of a point
2554 # @param z Z coordinate of a point
2555 # @return id of a node
2556 def FindNodeClosestTo(self, x, y, z):
2557 preview = self.mesh.GetMeshEditPreviewer()
2558 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2560 ## Find a node closest to a point and move it to a point location
2561 # @param x X coordinate of a point
2562 # @param y Y coordinate of a point
2563 # @param z Z coordinate of a point
2564 # @return id of a moved node
2565 def MeshToPassThroughAPoint(self, x, y, z):
2566 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2568 ## Replace two neighbour triangles sharing Node1-Node2 link
2569 # with ones built on the same 4 nodes but having other common link.
2570 # @param NodeID1 first node id
2571 # @param NodeID2 second node id
2572 # @return false if proper faces not found
2573 def InverseDiag(self, NodeID1, NodeID2):
2574 return self.editor.InverseDiag(NodeID1, NodeID2)
2576 ## Replace two neighbour triangles sharing Node1-Node2 link
2577 # with a quadrangle built on the same 4 nodes.
2578 # @param NodeID1 first node id
2579 # @param NodeID2 second node id
2580 # @return false if proper faces not found
2581 def DeleteDiag(self, NodeID1, NodeID2):
2582 return self.editor.DeleteDiag(NodeID1, NodeID2)
2584 ## Reorient elements by ids
2585 # @param IDsOfElements if undefined reorient all mesh elements
2586 def Reorient(self, IDsOfElements=None):
2587 if IDsOfElements == None:
2588 IDsOfElements = self.GetElementsId()
2589 return self.editor.Reorient(IDsOfElements)
2591 ## Reorient all elements of the object
2592 # @param theObject is mesh, submesh or group
2593 def ReorientObject(self, theObject):
2594 if ( isinstance( theObject, Mesh )):
2595 theObject = theObject.GetMesh()
2596 return self.editor.ReorientObject(theObject)
2598 ## Fuse neighbour triangles into quadrangles.
2599 # @param IDsOfElements The triangles to be fused,
2600 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2601 # @param MaxAngle is a max angle between element normals at which fusion
2602 # is still performed; theMaxAngle is mesured in radians.
2603 # @return TRUE in case of success, FALSE otherwise.
2604 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2605 if IDsOfElements == []:
2606 IDsOfElements = self.GetElementsId()
2607 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2609 ## Fuse neighbour triangles of the object into quadrangles
2610 # @param theObject is mesh, submesh or group
2611 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2612 # @param MaxAngle is a max angle between element normals at which fusion
2613 # is still performed; theMaxAngle is mesured in radians.
2614 # @return TRUE in case of success, FALSE otherwise.
2615 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2616 if ( isinstance( theObject, Mesh )):
2617 theObject = theObject.GetMesh()
2618 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2620 ## Split quadrangles into triangles.
2621 # @param IDsOfElements the faces to be splitted.
2622 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2623 # @return TRUE in case of success, FALSE otherwise.
2624 def QuadToTri (self, IDsOfElements, theCriterion):
2625 if IDsOfElements == []:
2626 IDsOfElements = self.GetElementsId()
2627 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2629 ## Split quadrangles into triangles.
2630 # @param theObject object to taking list of elements from, is mesh, submesh or group
2631 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2632 def QuadToTriObject (self, theObject, theCriterion):
2633 if ( isinstance( theObject, Mesh )):
2634 theObject = theObject.GetMesh()
2635 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2637 ## Split quadrangles into triangles.
2638 # @param theElems The faces to be splitted
2639 # @param the13Diag is used to choose a diagonal for splitting.
2640 # @return TRUE in case of success, FALSE otherwise.
2641 def SplitQuad (self, IDsOfElements, Diag13):
2642 if IDsOfElements == []:
2643 IDsOfElements = self.GetElementsId()
2644 return self.editor.SplitQuad(IDsOfElements, Diag13)
2646 ## Split quadrangles into triangles.
2647 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2648 def SplitQuadObject (self, theObject, Diag13):
2649 if ( isinstance( theObject, Mesh )):
2650 theObject = theObject.GetMesh()
2651 return self.editor.SplitQuadObject(theObject, Diag13)
2653 ## Find better splitting of the given quadrangle.
2654 # @param IDOfQuad ID of the quadrangle to be splitted.
2655 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2656 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2657 # diagonal is better, 0 if error occurs.
2658 def BestSplit (self, IDOfQuad, theCriterion):
2659 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2661 ## Split quafrangle faces near triangular facets of volumes
2663 def SplitQuadsNearTriangularFacets(self):
2664 faces_array = self.GetElementsByType(SMESH.FACE)
2665 for face_id in faces_array:
2666 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2667 quad_nodes = self.mesh.GetElemNodes(face_id)
2668 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2669 isVolumeFound = False
2670 for node1_elem in node1_elems:
2671 if not isVolumeFound:
2672 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2673 nb_nodes = self.GetElemNbNodes(node1_elem)
2674 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2675 volume_elem = node1_elem
2676 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2677 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2678 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2679 isVolumeFound = True
2680 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2681 self.SplitQuad([face_id], False) # diagonal 2-4
2682 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2683 isVolumeFound = True
2684 self.SplitQuad([face_id], True) # diagonal 1-3
2685 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2686 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2687 isVolumeFound = True
2688 self.SplitQuad([face_id], True) # diagonal 1-3
2690 ## @brief Split hexahedrons into tetrahedrons.
2692 # Use pattern mapping functionality for splitting.
2693 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2694 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2695 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2696 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2697 # key-point will be mapped into <theNode001>-th node of each volume.
2698 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2699 # @return TRUE in case of success, FALSE otherwise.
2700 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2701 # Pattern: 5.---------.6
2706 # (0,0,1) 4.---------.7 * |
2713 # (0,0,0) 0.---------.3
2714 pattern_tetra = "!!! Nb of points: \n 8 \n\
2724 !!! Indices of points of 6 tetras: \n\
2732 pattern = self.smeshpyD.GetPattern()
2733 isDone = pattern.LoadFromFile(pattern_tetra)
2735 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2738 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2739 isDone = pattern.MakeMesh(self.mesh, False, False)
2740 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2742 # split quafrangle faces near triangular facets of volumes
2743 self.SplitQuadsNearTriangularFacets()
2747 ## @brief Split hexahedrons into prisms.
2749 # Use pattern mapping functionality for splitting.
2750 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2751 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2752 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2753 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2754 # key-point will be mapped into <theNode001>-th node of each volume.
2755 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2756 # @return TRUE in case of success, FALSE otherwise.
2757 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2758 # Pattern: 5.---------.6
2763 # (0,0,1) 4.---------.7 |
2770 # (0,0,0) 0.---------.3
2771 pattern_prism = "!!! Nb of points: \n 8 \n\
2781 !!! Indices of points of 2 prisms: \n\
2785 pattern = self.smeshpyD.GetPattern()
2786 isDone = pattern.LoadFromFile(pattern_prism)
2788 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2791 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2792 isDone = pattern.MakeMesh(self.mesh, False, False)
2793 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2795 # split quafrangle faces near triangular facets of volumes
2796 self.SplitQuadsNearTriangularFacets()
2801 # @param IDsOfElements list if ids of elements to smooth
2802 # @param IDsOfFixedNodes list of ids of fixed nodes.
2803 # Note that nodes built on edges and boundary nodes are always fixed.
2804 # @param MaxNbOfIterations maximum number of iterations
2805 # @param MaxAspectRatio varies in range [1.0, inf]
2806 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2807 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2808 MaxNbOfIterations, MaxAspectRatio, Method):
2809 if IDsOfElements == []:
2810 IDsOfElements = self.GetElementsId()
2811 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2812 MaxNbOfIterations, MaxAspectRatio, Method)
2814 ## Smooth elements belong to given object
2815 # @param theObject object to smooth
2816 # @param IDsOfFixedNodes list of ids of fixed nodes.
2817 # Note that nodes built on edges and boundary nodes are always fixed.
2818 # @param MaxNbOfIterations maximum number of iterations
2819 # @param MaxAspectRatio varies in range [1.0, inf]
2820 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2821 def SmoothObject(self, theObject, IDsOfFixedNodes,
2822 MaxNbOfIterations, MaxxAspectRatio, Method):
2823 if ( isinstance( theObject, Mesh )):
2824 theObject = theObject.GetMesh()
2825 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2826 MaxNbOfIterations, MaxxAspectRatio, Method)
2828 ## Parametric smooth the given elements
2829 # @param IDsOfElements list if ids of elements to smooth
2830 # @param IDsOfFixedNodes list of ids of fixed nodes.
2831 # Note that nodes built on edges and boundary nodes are always fixed.
2832 # @param MaxNbOfIterations maximum number of iterations
2833 # @param MaxAspectRatio varies in range [1.0, inf]
2834 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2835 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2836 MaxNbOfIterations, MaxAspectRatio, Method):
2837 if IDsOfElements == []:
2838 IDsOfElements = self.GetElementsId()
2839 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2840 MaxNbOfIterations, MaxAspectRatio, Method)
2842 ## Parametric smooth elements belong to given object
2843 # @param theObject object to smooth
2844 # @param IDsOfFixedNodes list of ids of fixed nodes.
2845 # Note that nodes built on edges and boundary nodes are always fixed.
2846 # @param MaxNbOfIterations maximum number of iterations
2847 # @param MaxAspectRatio varies in range [1.0, inf]
2848 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2849 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2850 MaxNbOfIterations, MaxAspectRatio, Method):
2851 if ( isinstance( theObject, Mesh )):
2852 theObject = theObject.GetMesh()
2853 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2854 MaxNbOfIterations, MaxAspectRatio, Method)
2856 ## Converts all mesh to quadratic one, deletes old elements, replacing
2857 # them with quadratic ones with the same id.
2858 def ConvertToQuadratic(self, theForce3d):
2859 self.editor.ConvertToQuadratic(theForce3d)
2861 ## Converts all mesh from quadratic to ordinary ones,
2862 # deletes old quadratic elements, \n replacing
2863 # them with ordinary mesh elements with the same id.
2864 def ConvertFromQuadratic(self):
2865 return self.editor.ConvertFromQuadratic()
2867 ## Renumber mesh nodes
2868 def RenumberNodes(self):
2869 self.editor.RenumberNodes()
2871 ## Renumber mesh elements
2872 def RenumberElements(self):
2873 self.editor.RenumberElements()
2875 ## Generate new elements by rotation of the elements around the axis
2876 # @param IDsOfElements list of ids of elements to sweep
2877 # @param Axix axis of rotation, AxisStruct or line(geom object)
2878 # @param AngleInRadians angle of Rotation
2879 # @param NbOfSteps number of steps
2880 # @param Tolerance tolerance
2881 # @param MakeGroups to generate new groups from existing ones
2882 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2883 if IDsOfElements == []:
2884 IDsOfElements = self.GetElementsId()
2885 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2886 Axix = self.smeshpyD.GetAxisStruct(Axix)
2888 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2889 AngleInRadians, NbOfSteps, Tolerance)
2890 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2893 ## Generate new elements by rotation of the elements of object around the axis
2894 # @param theObject object wich elements should be sweeped
2895 # @param Axix axis of rotation, AxisStruct or line(geom object)
2896 # @param AngleInRadians angle of Rotation
2897 # @param NbOfSteps number of steps
2898 # @param Tolerance tolerance
2899 # @param MakeGroups to generate new groups from existing ones
2900 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2901 if ( isinstance( theObject, Mesh )):
2902 theObject = theObject.GetMesh()
2903 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2904 Axix = self.smeshpyD.GetAxisStruct(Axix)
2906 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2907 NbOfSteps, Tolerance)
2908 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2911 ## Generate new elements by extrusion of the elements with given ids
2912 # @param IDsOfElements list of elements ids for extrusion
2913 # @param StepVector vector, defining the direction and value of extrusion
2914 # @param NbOfSteps the number of steps
2915 # @param MakeGroups to generate new groups from existing ones
2916 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2917 if IDsOfElements == []:
2918 IDsOfElements = self.GetElementsId()
2919 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2920 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2922 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2923 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2926 ## Generate new elements by extrusion of the elements with given ids
2927 # @param IDsOfElements is ids of elements
2928 # @param StepVector vector, defining the direction and value of extrusion
2929 # @param NbOfSteps the number of steps
2930 # @param ExtrFlags set flags for performing extrusion
2931 # @param SewTolerance uses for comparing locations of nodes if flag
2932 # EXTRUSION_FLAG_SEW is set
2933 # @param MakeGroups to generate new groups from existing ones
2934 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2935 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2936 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2938 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2939 ExtrFlags, SewTolerance)
2940 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2941 ExtrFlags, SewTolerance)
2944 ## Generate new elements by extrusion of the elements belong to object
2945 # @param theObject object wich elements should be processed
2946 # @param StepVector vector, defining the direction and value of extrusion
2947 # @param NbOfSteps the number of steps
2948 # @param MakeGroups to generate new groups from existing ones
2949 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2950 if ( isinstance( theObject, Mesh )):
2951 theObject = theObject.GetMesh()
2952 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2953 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2955 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2956 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2959 ## Generate new elements by extrusion of the elements belong to object
2960 # @param theObject object wich elements should be processed
2961 # @param StepVector vector, defining the direction and value of extrusion
2962 # @param NbOfSteps the number of steps
2963 # @param MakeGroups to generate new groups from existing ones
2964 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2965 if ( isinstance( theObject, Mesh )):
2966 theObject = theObject.GetMesh()
2967 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2968 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2970 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2971 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2974 ## Generate new elements by extrusion of the elements belong to object
2975 # @param theObject object wich elements should be processed
2976 # @param StepVector vector, defining the direction and value of extrusion
2977 # @param NbOfSteps the number of steps
2978 # @param MakeGroups to generate new groups from existing ones
2979 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2980 if ( isinstance( theObject, Mesh )):
2981 theObject = theObject.GetMesh()
2982 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2983 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2985 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
2986 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
2989 ## Generate new elements by extrusion of the given elements
2990 # A path of extrusion must be a meshed edge.
2991 # @param IDsOfElements is ids of elements
2992 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
2993 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
2994 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
2995 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
2996 # @param Angles list of angles
2997 # @param HasRefPoint allows to use base point
2998 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
2999 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
3000 # @param MakeGroups to generate new groups from existing ones
3001 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
3002 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3003 HasAngles, Angles, HasRefPoint, RefPoint,
3004 MakeGroups=False, LinearVariation=False):
3005 if IDsOfElements == []:
3006 IDsOfElements = self.GetElementsId()
3007 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3008 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3011 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
3012 PathShape, NodeStart, HasAngles,
3013 Angles, HasRefPoint, RefPoint)
3014 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
3015 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3017 ## Generate new elements by extrusion of the elements belong to object
3018 # A path of extrusion must be a meshed edge.
3019 # @param IDsOfElements is ids of elements
3020 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3021 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
3022 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
3023 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
3024 # @param Angles list of angles
3025 # @param HasRefPoint allows to use base point
3026 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
3027 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
3028 # @param MakeGroups to generate new groups from existing ones
3029 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
3030 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3031 HasAngles, Angles, HasRefPoint, RefPoint,
3032 MakeGroups=False, LinearVariation=False):
3033 if ( isinstance( theObject, Mesh )):
3034 theObject = theObject.GetMesh()
3035 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3036 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3038 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
3039 PathShape, NodeStart, HasAngles,
3040 Angles, HasRefPoint, RefPoint)
3041 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
3042 NodeStart, HasAngles, Angles, HasRefPoint,
3045 ## Symmetrical copy of mesh elements
3046 # @param IDsOfElements list of elements ids
3047 # @param Mirror is AxisStruct or geom object(point, line, plane)
3048 # @param theMirrorType is POINT, AXIS or PLANE
3049 # If the Mirror is geom object this parameter is unnecessary
3050 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3051 # @param MakeGroups to generate new groups from existing ones (if Copy)
3052 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3053 if IDsOfElements == []:
3054 IDsOfElements = self.GetElementsId()
3055 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3056 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3057 if Copy and MakeGroups:
3058 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3059 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3062 ## Create a new mesh by symmetrical copy of mesh elements
3063 # @param IDsOfElements list of elements ids
3064 # @param Mirror is AxisStruct or geom object(point, line, plane)
3065 # @param theMirrorType is POINT, AXIS or PLANE
3066 # If the Mirror is geom object this parameter is unnecessary
3067 # @param MakeGroups to generate new groups from existing ones
3068 # @param NewMeshName is a name of new mesh to create
3069 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3070 if IDsOfElements == []:
3071 IDsOfElements = self.GetElementsId()
3072 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3073 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3074 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3075 MakeGroups, NewMeshName)
3076 return Mesh(self.smeshpyD,self.geompyD,mesh)
3078 ## Symmetrical copy of object
3079 # @param theObject mesh, submesh or group
3080 # @param Mirror is AxisStruct or geom object(point, line, plane)
3081 # @param theMirrorType is POINT, AXIS or PLANE
3082 # If the Mirror is geom object this parameter is unnecessary
3083 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3084 # @param MakeGroups to generate new groups from existing ones (if Copy)
3085 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3086 if ( isinstance( theObject, Mesh )):
3087 theObject = theObject.GetMesh()
3088 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3089 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3090 if Copy and MakeGroups:
3091 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3092 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3095 ## Create a new mesh by symmetrical copy of object
3096 # @param theObject mesh, submesh or group
3097 # @param Mirror is AxisStruct or geom object(point, line, plane)
3098 # @param theMirrorType is POINT, AXIS or PLANE
3099 # If the Mirror is geom object this parameter is unnecessary
3100 # @param MakeGroups to generate new groups from existing ones
3101 # @param NewMeshName is a name of new mesh to create
3102 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3103 if ( isinstance( theObject, Mesh )):
3104 theObject = theObject.GetMesh()
3105 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3106 Mirror = GetAxisStruct(Mirror)
3107 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3108 MakeGroups, NewMeshName)
3109 return Mesh( self.smeshpyD,self.geompyD,mesh )
3111 ## Translates the elements
3112 # @param IDsOfElements list of elements ids
3113 # @param Vector direction of translation(DirStruct or vector)
3114 # @param Copy allows to copy the translated elements
3115 # @param MakeGroups to generate new groups from existing ones (if Copy)
3116 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3117 if IDsOfElements == []:
3118 IDsOfElements = self.GetElementsId()
3119 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3120 Vector = self.smeshpyD.GetDirStruct(Vector)
3121 if Copy and MakeGroups:
3122 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3123 self.editor.Translate(IDsOfElements, Vector, Copy)
3126 ## Create a new mesh of translated elements
3127 # @param IDsOfElements list of elements ids
3128 # @param Vector direction of translation(DirStruct or vector)
3129 # @param MakeGroups to generate new groups from existing ones
3130 # @param NewMeshName is a name of new mesh to create
3131 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3132 if IDsOfElements == []:
3133 IDsOfElements = self.GetElementsId()
3134 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3135 Vector = self.smeshpyD.GetDirStruct(Vector)
3136 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3137 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3139 ## Translates the object
3140 # @param theObject object to translate(mesh, submesh, or group)
3141 # @param Vector direction of translation(DirStruct or geom vector)
3142 # @param Copy allows to copy the translated elements
3143 # @param MakeGroups to generate new groups from existing ones (if Copy)
3144 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3145 if ( isinstance( theObject, Mesh )):
3146 theObject = theObject.GetMesh()
3147 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3148 Vector = self.smeshpyD.GetDirStruct(Vector)
3149 if Copy and MakeGroups:
3150 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3151 self.editor.TranslateObject(theObject, Vector, Copy)
3154 ## Create a new mesh from translated object
3155 # @param theObject object to translate(mesh, submesh, or group)
3156 # @param Vector direction of translation(DirStruct or geom vector)
3157 # @param MakeGroups to generate new groups from existing ones
3158 # @param NewMeshName is a name of new mesh to create
3159 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3160 if (isinstance(theObject, Mesh)):
3161 theObject = theObject.GetMesh()
3162 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3163 Vector = self.smeshpyD.GetDirStruct(Vector)
3164 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3165 return Mesh( self.smeshpyD, self.geompyD, mesh )
3167 ## Rotates the elements
3168 # @param IDsOfElements list of elements ids
3169 # @param Axis axis of rotation(AxisStruct or geom line)
3170 # @param AngleInRadians angle of rotation(in radians)
3171 # @param Copy allows to copy the rotated elements
3172 # @param MakeGroups to generate new groups from existing ones (if Copy)
3173 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3174 if IDsOfElements == []:
3175 IDsOfElements = self.GetElementsId()
3176 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3177 Axis = self.smeshpyD.GetAxisStruct(Axis)
3178 if Copy and MakeGroups:
3179 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3180 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3183 ## Create a new mesh of rotated elements
3184 # @param IDsOfElements list of element ids
3185 # @param Axis axis of rotation(AxisStruct or geom line)
3186 # @param AngleInRadians angle of rotation(in radians)
3187 # @param MakeGroups to generate new groups from existing ones
3188 # @param NewMeshName is a name of new mesh to create
3189 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3190 if IDsOfElements == []:
3191 IDsOfElements = self.GetElementsId()
3192 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3193 Axis = self.smeshpyD.GetAxisStruct(Axis)
3194 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3195 MakeGroups, NewMeshName)
3196 return Mesh( self.smeshpyD, self.geompyD, mesh )
3198 ## Rotates the object
3199 # @param theObject object to rotate(mesh, submesh, or group)
3200 # @param Axis axis of rotation(AxisStruct or geom line)
3201 # @param AngleInRadians angle of rotation(in radians)
3202 # @param Copy allows to copy the rotated elements
3203 # @param MakeGroups to generate new groups from existing ones (if Copy)
3204 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3205 if (isinstance(theObject, Mesh)):
3206 theObject = theObject.GetMesh()
3207 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3208 Axis = self.smeshpyD.GetAxisStruct(Axis)
3209 if Copy and MakeGroups:
3210 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3211 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3214 ## Create a new mesh from a rotated object
3215 # @param theObject object to rotate (mesh, submesh, or group)
3216 # @param Axis axis of rotation(AxisStruct or geom line)
3217 # @param AngleInRadians angle of rotation(in radians)
3218 # @param MakeGroups to generate new groups from existing ones
3219 # @param NewMeshName is a name of new mesh to create
3220 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3221 if (isinstance( theObject, Mesh )):
3222 theObject = theObject.GetMesh()
3223 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3224 Axis = self.smeshpyD.GetAxisStruct(Axis)
3225 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3226 MakeGroups, NewMeshName)
3227 return Mesh( self.smeshpyD, self.geompyD, mesh )
3229 ## Find group of nodes close to each other within Tolerance.
3230 # @param Tolerance tolerance value
3231 # @param list of group of nodes
3232 def FindCoincidentNodes (self, Tolerance):
3233 return self.editor.FindCoincidentNodes(Tolerance)
3235 ## Find group of nodes close to each other within Tolerance.
3236 # @param Tolerance tolerance value
3237 # @param SubMeshOrGroup SubMesh or Group
3238 # @param list of group of nodes
3239 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
3240 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
3243 # @param list of group of nodes
3244 def MergeNodes (self, GroupsOfNodes):
3245 self.editor.MergeNodes(GroupsOfNodes)
3247 ## Find elements built on the same nodes.
3248 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3249 # @return a list of groups of equal elements
3250 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3251 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3253 ## Merge elements in each given group.
3254 # @param GroupsOfElementsID groups of elements for merging
3255 def MergeElements(self, GroupsOfElementsID):
3256 self.editor.MergeElements(GroupsOfElementsID)
3258 ## Remove all but one of elements built on the same nodes.
3259 def MergeEqualElements(self):
3260 self.editor.MergeEqualElements()
3263 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3264 FirstNodeID2, SecondNodeID2, LastNodeID2,
3265 CreatePolygons, CreatePolyedrs):
3266 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3267 FirstNodeID2, SecondNodeID2, LastNodeID2,
3268 CreatePolygons, CreatePolyedrs)
3270 ## Sew conform free borders
3271 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3272 FirstNodeID2, SecondNodeID2):
3273 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3274 FirstNodeID2, SecondNodeID2)
3276 ## Sew border to side
3277 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3278 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3279 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3280 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3282 ## Sew two sides of a mesh. Nodes belonging to Side1 are
3283 # merged with nodes of elements of Side2.
3284 # Number of elements in theSide1 and in theSide2 must be
3285 # equal and they should have similar node connectivity.
3286 # The nodes to merge should belong to sides borders and
3287 # the first node should be linked to the second.
3288 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3289 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3290 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3291 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3292 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3293 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3295 ## Set new nodes for given element.
3296 # @param ide the element id
3297 # @param newIDs nodes ids
3298 # @return If number of nodes is not corresponded to type of element - returns false
3299 def ChangeElemNodes(self, ide, newIDs):
3300 return self.editor.ChangeElemNodes(ide, newIDs)
3302 ## If during last operation of MeshEditor some nodes were
3303 # created this method returns list of its IDs, \n
3304 # if new nodes not created - returns empty list
3305 def GetLastCreatedNodes(self):
3306 return self.editor.GetLastCreatedNodes()
3308 ## If during last operation of MeshEditor some elements were
3309 # created this method returns list of its IDs, \n
3310 # if new elements not creared - returns empty list
3311 def GetLastCreatedElems(self):
3312 return self.editor.GetLastCreatedElems()