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 # @param p precision, used for number of segments calculation.
628 # It must be pozitive, meaningfull values are in range [0,1].
629 # In general, number of segments is calculated with formula:
630 # nb = ceil((edge_length / l) - p)
631 # Function ceil rounds its argument to the higher integer.
632 # So, p=0 means rounding of (edge_length / l) to the higher integer,
633 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
634 # p=1 means rounding of (edge_length / l) to the lower integer.
635 # Default value is 1e-07.
636 def LocalLength(self, l, UseExisting=0, p=1e-07):
637 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
638 CompareMethod=self.CompareLocalLength)
643 ## Check if the given "LocalLength" hypothesis has the same parameters as given arguments
644 def CompareLocalLength(self, hyp, args):
645 if IsEqual(hyp.GetLength(), args[0]):
646 return IsEqual(hyp.GetPrecision(), args[1])
649 ## Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
650 # @param n for the number of segments that cut an edge
651 # @param s for the scale factor (optional)
652 # @param UseExisting if ==true - search existing hypothesis created with
653 # same parameters, else (default) - create new
654 def NumberOfSegments(self, n, s=[], UseExisting=0):
656 hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
657 CompareMethod=self.CompareNumberOfSegments)
659 hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
660 CompareMethod=self.CompareNumberOfSegments)
661 hyp.SetDistrType( 1 )
662 hyp.SetScaleFactor(s)
663 hyp.SetNumberOfSegments(n)
666 ## Check if the given "NumberOfSegments" hypothesis has the same parameters as given arguments
667 def CompareNumberOfSegments(self, hyp, args):
668 if hyp.GetNumberOfSegments() == args[0]:
672 if hyp.GetDistrType() == 1:
673 if IsEqual(hyp.GetScaleFactor(), args[1]):
677 ## Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
678 # @param start for the length of the first segment
679 # @param end for the length of the last segment
680 # @param UseExisting if ==true - search existing hypothesis created with
681 # same parameters, else (default) - create new
682 def Arithmetic1D(self, start, end, UseExisting=0):
683 hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
684 CompareMethod=self.CompareArithmetic1D)
685 hyp.SetLength(start, 1)
686 hyp.SetLength(end , 0)
689 ## Check if the given "Arithmetic1D" hypothesis has the same parameters as given arguments
690 def CompareArithmetic1D(self, hyp, args):
691 if IsEqual(hyp.GetLength(1), args[0]):
692 if IsEqual(hyp.GetLength(0), args[1]):
696 ## Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
697 # @param start for the length of the first segment
698 # @param end for the length of the last segment
699 # @param UseExisting if ==true - search existing hypothesis created with
700 # same parameters, else (default) - create new
701 def StartEndLength(self, start, end, UseExisting=0):
702 hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
703 CompareMethod=self.CompareStartEndLength)
704 hyp.SetLength(start, 1)
705 hyp.SetLength(end , 0)
708 ## Check if the given "StartEndLength" hypothesis has the same parameters as given arguments
709 def CompareStartEndLength(self, hyp, args):
710 if IsEqual(hyp.GetLength(1), args[0]):
711 if IsEqual(hyp.GetLength(0), args[1]):
715 ## Define "Deflection1D" hypothesis
716 # @param d for the deflection
717 # @param UseExisting if ==true - search existing hypothesis created with
718 # same parameters, else (default) - create new
719 def Deflection1D(self, d, UseExisting=0):
720 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
721 CompareMethod=self.CompareDeflection1D)
725 ## Check if the given "Deflection1D" hypothesis has the same parameters as given arguments
726 def CompareDeflection1D(self, hyp, args):
727 return IsEqual(hyp.GetDeflection(), args[0])
729 ## Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
730 # the opposite side in the case of quadrangular faces
731 def Propagation(self):
732 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
734 ## Define "AutomaticLength" hypothesis
735 # @param fineness for the fineness [0-1]
736 # @param UseExisting if ==true - search existing hypothesis created with
737 # same parameters, else (default) - create new
738 def AutomaticLength(self, fineness=0, UseExisting=0):
739 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
740 CompareMethod=self.CompareAutomaticLength)
741 hyp.SetFineness( fineness )
744 ## Check if the given "AutomaticLength" hypothesis has the same parameters as given arguments
745 def CompareAutomaticLength(self, hyp, args):
746 return IsEqual(hyp.GetFineness(), args[0])
748 ## Define "SegmentLengthAroundVertex" hypothesis
749 # @param length for the segment length
750 # @param vertex for the length localization: vertex index [0,1] | vertex object.
751 # Any other integer value means what hypo will be set on the
752 # whole 1D shape, where Mesh_Segment algorithm is assigned.
753 # @param UseExisting if ==true - search existing hypothesis created with
754 # same parameters, else (default) - create new
755 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
757 store_geom = self.geom
758 if type(vertex) is types.IntType:
759 if vertex == 0 or vertex == 1:
760 vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
768 if self.geom is None:
769 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
770 name = GetName(self.geom)
772 piece = self.mesh.geom
773 name = self.mesh.geompyD.SubShapeName(self.geom, piece)
774 self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
775 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
777 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
779 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
780 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
782 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
783 CompareMethod=self.CompareLengthNearVertex)
784 self.geom = store_geom
785 hyp.SetLength( length )
788 ## Check if the given "LengthNearVertex" hypothesis has the same parameters as given arguments
789 def CompareLengthNearVertex(self, hyp, args):
790 return IsEqual(hyp.GetLength(), args[0])
792 ## Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
793 # If the 2D mesher sees that all boundary edges are quadratic ones,
794 # it generates quadratic faces, else it generates linear faces using
795 # medium nodes as if they were vertex ones.
796 # The 3D mesher generates quadratic volumes only if all boundary faces
797 # are quadratic ones, else it fails.
798 def QuadraticMesh(self):
799 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
802 # Public class: Mesh_CompositeSegment
803 # --------------------------
805 ## Class to define a segment 1D algorithm for discretization
808 class Mesh_CompositeSegment(Mesh_Segment):
810 ## Private constructor.
811 def __init__(self, mesh, geom=0):
812 self.Create(mesh, geom, "CompositeSegment_1D")
815 # Public class: Mesh_Segment_Python
816 # ---------------------------------
818 ## Class to define a segment 1D algorithm for discretization with python function
821 class Mesh_Segment_Python(Mesh_Segment):
823 ## Private constructor.
824 def __init__(self, mesh, geom=0):
825 import Python1dPlugin
826 self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
828 ## Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
829 # @param n for the number of segments that cut an edge
830 # @param func for the python function that calculate the length of all segments
831 # @param UseExisting if ==true - search existing hypothesis created with
832 # same parameters, else (default) - create new
833 def PythonSplit1D(self, n, func, UseExisting=0):
834 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
835 UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
836 hyp.SetNumberOfSegments(n)
837 hyp.SetPythonLog10RatioFunction(func)
840 ## Check if the given "PythonSplit1D" hypothesis has the same parameters as given arguments
841 def ComparePythonSplit1D(self, hyp, args):
842 #if hyp.GetNumberOfSegments() == args[0]:
843 # if hyp.GetPythonLog10RatioFunction() == args[1]:
847 # Public class: Mesh_Triangle
848 # ---------------------------
850 ## Class to define a triangle 2D algorithm
853 class Mesh_Triangle(Mesh_Algorithm):
862 ## Private constructor.
863 def __init__(self, mesh, algoType, geom=0):
864 Mesh_Algorithm.__init__(self)
866 self.algoType = algoType
867 if algoType == MEFISTO:
868 self.Create(mesh, geom, "MEFISTO_2D")
870 elif algoType == BLSURF:
872 self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
873 self.SetPhysicalMesh()
874 elif algoType == NETGEN:
876 print "Warning: NETGENPlugin module unavailable"
878 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
880 elif algoType == NETGEN_2D:
882 print "Warning: NETGENPlugin module unavailable"
884 self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
887 ## Define "MaxElementArea" hypothesis to give the maximum area of each triangle
888 # @param area for the maximum area of each triangle
889 # @param UseExisting if ==true - search existing hypothesis created with
890 # same parameters, else (default) - create new
892 # Only for algoType == MEFISTO || NETGEN_2D
893 def MaxElementArea(self, area, UseExisting=0):
894 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
895 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
896 CompareMethod=self.CompareMaxElementArea)
897 hyp.SetMaxElementArea(area)
899 elif self.algoType == NETGEN:
900 print "Netgen 1D-2D algo doesn't support this hypothesis"
903 ## Check if the given "MaxElementArea" hypothesis has the same parameters as given arguments
904 def CompareMaxElementArea(self, hyp, args):
905 return IsEqual(hyp.GetMaxElementArea(), args[0])
907 ## Define "LengthFromEdges" hypothesis to build triangles
908 # based on the length of the edges taken from the wire
910 # Only for algoType == MEFISTO || NETGEN_2D
911 def LengthFromEdges(self):
912 if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
913 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
915 elif self.algoType == NETGEN:
916 print "Netgen 1D-2D algo doesn't support this hypothesis"
920 # @param thePhysicalMesh is:
921 # DefaultSize or Custom
922 def SetPhysicalMesh(self, thePhysicalMesh=1):
925 self.params.SetPhysicalMesh(thePhysicalMesh)
928 def SetPhySize(self, theVal):
931 self.params.SetPhySize(theVal)
934 # @param theGeometricMesh is:
935 # DefaultGeom or Custom
936 def SetGeometricMesh(self, theGeometricMesh=0):
939 if self.params.GetPhysicalMesh() == 0: theGeometricMesh = 1
940 self.params.SetGeometricMesh(theGeometricMesh)
942 ## Set AngleMeshS flag
943 def SetAngleMeshS(self, theVal=_angleMeshS):
946 if self.params.GetGeometricMesh() == 0: theVal = self._angleMeshS
947 self.params.SetAngleMeshS(theVal)
949 ## Set Gradation flag
950 def SetGradation(self, theVal=_gradation):
953 if self.params.GetGeometricMesh() == 0: theVal = self._gradation
954 self.params.SetGradation(theVal)
956 ## Set QuadAllowed flag
958 # Only for algoType == NETGEN || NETGEN_2D
959 def SetQuadAllowed(self, toAllow=True):
960 if self.algoType == NETGEN_2D:
961 if toAllow: # add QuadranglePreference
962 self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
963 else: # remove QuadranglePreference
964 for hyp in self.mesh.GetHypothesisList( self.geom ):
965 if hyp.GetName() == "QuadranglePreference":
966 self.mesh.RemoveHypothesis( self.geom, hyp )
974 self.params.SetQuadAllowed(toAllow)
977 ## Define "Netgen 2D Parameters" hypothesis
979 # Only for algoType == NETGEN
980 def Parameters(self):
981 if self.algoType == NETGEN:
982 self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
983 "libNETGENEngine.so", UseExisting=0)
985 elif self.algoType == MEFISTO:
986 print "Mefisto algo doesn't support NETGEN_Parameters_2D hypothesis"
988 elif self.algoType == NETGEN_2D:
989 print "NETGEN_2D_ONLY algo doesn't support 'NETGEN_Parameters_2D' hypothesis"
990 print "NETGEN_2D_ONLY uses 'MaxElementArea' and 'LengthFromEdges' ones"
992 elif self.algoType == BLSURF:
993 self.params = self.Hypothesis("BLSURF_Parameters", [],
994 "libBLSURFEngine.so", UseExisting=0)
1000 # Only for algoType == NETGEN
1001 def SetMaxSize(self, theSize):
1002 if self.params == 0:
1004 if self.params is not None:
1005 self.params.SetMaxSize(theSize)
1007 ## Set SecondOrder flag
1009 # Only for algoType == NETGEN
1010 def SetSecondOrder(self, theVal):
1011 if self.params == 0:
1013 if self.params is not None:
1014 self.params.SetSecondOrder(theVal)
1016 ## Set Optimize flag
1018 # Only for algoType == NETGEN
1019 def SetOptimize(self, theVal):
1020 if self.params == 0:
1022 if self.params is not None:
1023 self.params.SetOptimize(theVal)
1026 # @param theFineness is:
1027 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
1029 # Only for algoType == NETGEN
1030 def SetFineness(self, theFineness):
1031 if self.params == 0:
1033 if self.params is not None:
1034 self.params.SetFineness(theFineness)
1038 # Only for algoType == NETGEN
1039 def SetGrowthRate(self, theRate):
1040 if self.params == 0:
1042 if self.params is not None:
1043 self.params.SetGrowthRate(theRate)
1047 # Only for algoType == NETGEN
1048 def SetNbSegPerEdge(self, theVal):
1049 if self.params == 0:
1051 if self.params is not None:
1052 self.params.SetNbSegPerEdge(theVal)
1054 ## Set NbSegPerRadius
1056 # Only for algoType == NETGEN
1057 def SetNbSegPerRadius(self, theVal):
1058 if self.params == 0:
1060 if self.params is not None:
1061 self.params.SetNbSegPerRadius(theVal)
1063 ## Set Decimesh flag
1064 def SetDecimesh(self, toAllow=False):
1065 if self.params == 0:
1067 self.params.SetDecimesh(toAllow)
1072 # Public class: Mesh_Quadrangle
1073 # -----------------------------
1075 ## Class to define a quadrangle 2D algorithm
1078 class Mesh_Quadrangle(Mesh_Algorithm):
1080 ## Private constructor.
1081 def __init__(self, mesh, geom=0):
1082 Mesh_Algorithm.__init__(self)
1083 self.Create(mesh, geom, "Quadrangle_2D")
1085 ## Define "QuadranglePreference" hypothesis, forcing construction
1086 # of quadrangles if the number of nodes on opposite edges is not the same
1087 # in the case where the global number of nodes on edges is even
1088 def QuadranglePreference(self):
1089 hyp = self.Hypothesis("QuadranglePreference", UseExisting=1,
1090 CompareMethod=self.CompareEqualHyp)
1093 # Public class: Mesh_Tetrahedron
1094 # ------------------------------
1096 ## Class to define a tetrahedron 3D algorithm
1099 class Mesh_Tetrahedron(Mesh_Algorithm):
1104 ## Private constructor.
1105 def __init__(self, mesh, algoType, geom=0):
1106 Mesh_Algorithm.__init__(self)
1108 if algoType == NETGEN:
1109 self.Create(mesh, geom, "NETGEN_3D", "libNETGENEngine.so")
1112 elif algoType == GHS3D:
1114 self.Create(mesh, geom, "GHS3D_3D" , "libGHS3DEngine.so")
1117 elif algoType == FULL_NETGEN:
1119 print "Warning: NETGENPlugin module has not been imported."
1120 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1123 self.algoType = algoType
1125 ## Define "MaxElementVolume" hypothesis to give the maximun volume of each tetrahedral
1126 # @param vol for the maximum volume of each tetrahedral
1127 # @param UseExisting if ==true - search existing hypothesis created with
1128 # same parameters, else (default) - create new
1129 def MaxElementVolume(self, vol, UseExisting=0):
1130 hyp = self.Hypothesis("MaxElementVolume", [vol], UseExisting=UseExisting,
1131 CompareMethod=self.CompareMaxElementVolume)
1132 hyp.SetMaxElementVolume(vol)
1135 ## Check if the given "MaxElementVolume" hypothesis has the same parameters as given arguments
1136 def CompareMaxElementVolume(self, hyp, args):
1137 return IsEqual(hyp.GetMaxElementVolume(), args[0])
1139 ## Define "Netgen 3D Parameters" hypothesis
1140 def Parameters(self):
1141 if (self.algoType == FULL_NETGEN):
1142 self.params = self.Hypothesis("NETGEN_Parameters", [],
1143 "libNETGENEngine.so", UseExisting=0)
1146 print "Algo doesn't support this hypothesis"
1150 def SetMaxSize(self, theSize):
1151 if self.params == 0:
1153 self.params.SetMaxSize(theSize)
1155 ## Set SecondOrder flag
1156 def SetSecondOrder(self, theVal):
1157 if self.params == 0:
1159 self.params.SetSecondOrder(theVal)
1161 ## Set Optimize flag
1162 def SetOptimize(self, theVal):
1163 if self.params == 0:
1165 self.params.SetOptimize(theVal)
1168 # @param theFineness is:
1169 # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
1170 def SetFineness(self, theFineness):
1171 if self.params == 0:
1173 self.params.SetFineness(theFineness)
1176 def SetGrowthRate(self, theRate):
1177 if self.params == 0:
1179 self.params.SetGrowthRate(theRate)
1182 def SetNbSegPerEdge(self, theVal):
1183 if self.params == 0:
1185 self.params.SetNbSegPerEdge(theVal)
1187 ## Set NbSegPerRadius
1188 def SetNbSegPerRadius(self, theVal):
1189 if self.params == 0:
1191 self.params.SetNbSegPerRadius(theVal)
1193 # Public class: Mesh_Hexahedron
1194 # ------------------------------
1196 ## Class to define a hexahedron 3D algorithm
1199 class Mesh_Hexahedron(Mesh_Algorithm):
1204 ## Private constructor.
1205 def __init__(self, mesh, algoType=Hexa, geom=0):
1206 Mesh_Algorithm.__init__(self)
1208 self.algoType = algoType
1210 if algoType == Hexa:
1211 self.Create(mesh, geom, "Hexa_3D")
1214 elif algoType == Hexotic:
1215 import HexoticPlugin
1216 self.Create(mesh, geom, "Hexotic_3D", "libHexoticEngine.so")
1219 ## Define "MinMaxQuad" hypothesis to give the three hexotic parameters
1220 def MinMaxQuad(self, min=3, max=8, quad=True):
1221 self.params = self.Hypothesis("Hexotic_Parameters", [], "libHexoticEngine.so",
1223 self.params.SetHexesMinLevel(min)
1224 self.params.SetHexesMaxLevel(max)
1225 self.params.SetHexoticQuadrangles(quad)
1228 # Deprecated, only for compatibility!
1229 # Public class: Mesh_Netgen
1230 # ------------------------------
1232 ## Class to define a NETGEN-based 2D or 3D algorithm
1233 # that need no discrete boundary (i.e. independent)
1235 # This class is deprecated, only for compatibility!
1238 class Mesh_Netgen(Mesh_Algorithm):
1242 ## Private constructor.
1243 def __init__(self, mesh, is3D, geom=0):
1244 Mesh_Algorithm.__init__(self)
1247 print "Warning: NETGENPlugin module has not been imported."
1251 self.Create(mesh, geom, "NETGEN_2D3D", "libNETGENEngine.so")
1255 self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
1258 ## Define hypothesis containing parameters of the algorithm
1259 def Parameters(self):
1261 hyp = self.Hypothesis("NETGEN_Parameters", [],
1262 "libNETGENEngine.so", UseExisting=0)
1264 hyp = self.Hypothesis("NETGEN_Parameters_2D", [],
1265 "libNETGENEngine.so", UseExisting=0)
1268 # Public class: Mesh_Projection1D
1269 # ------------------------------
1271 ## Class to define a projection 1D algorithm
1274 class Mesh_Projection1D(Mesh_Algorithm):
1276 ## Private constructor.
1277 def __init__(self, mesh, geom=0):
1278 Mesh_Algorithm.__init__(self)
1279 self.Create(mesh, geom, "Projection_1D")
1281 ## Define "Source Edge" hypothesis, specifying a meshed edge to
1282 # take a mesh pattern from, and optionally association of vertices
1283 # between the source edge and a target one (where a hipothesis is assigned to)
1284 # @param edge to take nodes distribution from
1285 # @param mesh to take nodes distribution from (optional)
1286 # @param srcV is vertex of \a edge to associate with \a tgtV (optional)
1287 # @param tgtV is vertex of \a the edge where the algorithm is assigned,
1288 # to associate with \a srcV (optional)
1289 # @param UseExisting if ==true - search existing hypothesis created with
1290 # same parameters, else (default) - create new
1291 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
1292 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
1294 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
1295 hyp.SetSourceEdge( edge )
1296 if not mesh is None and isinstance(mesh, Mesh):
1297 mesh = mesh.GetMesh()
1298 hyp.SetSourceMesh( mesh )
1299 hyp.SetVertexAssociation( srcV, tgtV )
1302 ## Check if the given "SourceEdge" hypothesis has the same parameters as given arguments
1303 #def CompareSourceEdge(self, hyp, args):
1304 # # seems to be not really useful to reuse existing "SourceEdge" hypothesis
1308 # Public class: Mesh_Projection2D
1309 # ------------------------------
1311 ## Class to define a projection 2D algorithm
1314 class Mesh_Projection2D(Mesh_Algorithm):
1316 ## Private constructor.
1317 def __init__(self, mesh, geom=0):
1318 Mesh_Algorithm.__init__(self)
1319 self.Create(mesh, geom, "Projection_2D")
1321 ## Define "Source Face" hypothesis, specifying a meshed face to
1322 # take a mesh pattern from, and optionally association of vertices
1323 # between the source face and a target one (where a hipothesis is assigned to)
1324 # @param face to take mesh pattern from
1325 # @param mesh to take mesh pattern from (optional)
1326 # @param srcV1 is vertex of \a face to associate with \a tgtV1 (optional)
1327 # @param tgtV1 is vertex of \a the face where the algorithm is assigned,
1328 # to associate with \a srcV1 (optional)
1329 # @param srcV2 is vertex of \a face to associate with \a tgtV1 (optional)
1330 # @param tgtV2 is vertex of \a the face where the algorithm is assigned,
1331 # to associate with \a srcV2 (optional)
1332 # @param UseExisting if ==true - search existing hypothesis created with
1333 # same parameters, else (default) - create new
1335 # Note: association vertices must belong to one edge of a face
1336 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1337 srcV2=None, tgtV2=None, UseExisting=0):
1338 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1340 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1341 hyp.SetSourceFace( face )
1342 if not mesh is None and isinstance(mesh, Mesh):
1343 mesh = mesh.GetMesh()
1344 hyp.SetSourceMesh( mesh )
1345 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1348 ## Check if the given "SourceFace" hypothesis has the same parameters as given arguments
1349 #def CompareSourceFace(self, hyp, args):
1350 # # seems to be not really useful to reuse existing "SourceFace" hypothesis
1353 # Public class: Mesh_Projection3D
1354 # ------------------------------
1356 ## Class to define a projection 3D algorithm
1359 class Mesh_Projection3D(Mesh_Algorithm):
1361 ## Private constructor.
1362 def __init__(self, mesh, geom=0):
1363 Mesh_Algorithm.__init__(self)
1364 self.Create(mesh, geom, "Projection_3D")
1366 ## Define "Source Shape 3D" hypothesis, specifying a meshed solid to
1367 # take a mesh pattern from, and optionally association of vertices
1368 # between the source solid and a target one (where a hipothesis is assigned to)
1369 # @param solid to take mesh pattern from
1370 # @param mesh to take mesh pattern from (optional)
1371 # @param srcV1 is vertex of \a solid to associate with \a tgtV1 (optional)
1372 # @param tgtV1 is vertex of \a the solid where the algorithm is assigned,
1373 # to associate with \a srcV1 (optional)
1374 # @param srcV2 is vertex of \a solid to associate with \a tgtV1 (optional)
1375 # @param tgtV2 is vertex of \a the solid where the algorithm is assigned,
1376 # to associate with \a srcV2 (optional)
1377 # @param UseExisting - if ==true - search existing hypothesis created with
1378 # same parameters, else (default) - create new
1380 # Note: association vertices must belong to one edge of a solid
1381 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1382 srcV2=0, tgtV2=0, UseExisting=0):
1383 hyp = self.Hypothesis("ProjectionSource3D",
1384 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1386 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1387 hyp.SetSource3DShape( solid )
1388 if not mesh is None and isinstance(mesh, Mesh):
1389 mesh = mesh.GetMesh()
1390 hyp.SetSourceMesh( mesh )
1391 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1394 ## Check if the given "SourceShape3D" hypothesis has the same parameters as given arguments
1395 #def CompareSourceShape3D(self, hyp, args):
1396 # # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1400 # Public class: Mesh_Prism
1401 # ------------------------
1403 ## Class to define a 3D extrusion algorithm
1406 class Mesh_Prism3D(Mesh_Algorithm):
1408 ## Private constructor.
1409 def __init__(self, mesh, geom=0):
1410 Mesh_Algorithm.__init__(self)
1411 self.Create(mesh, geom, "Prism_3D")
1413 # Public class: Mesh_RadialPrism
1414 # -------------------------------
1416 ## Class to define a Radial Prism 3D algorithm
1419 class Mesh_RadialPrism3D(Mesh_Algorithm):
1421 ## Private constructor.
1422 def __init__(self, mesh, geom=0):
1423 Mesh_Algorithm.__init__(self)
1424 self.Create(mesh, geom, "RadialPrism_3D")
1426 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1427 self.nbLayers = None
1429 ## Return 3D hypothesis holding the 1D one
1430 def Get3DHypothesis(self):
1431 return self.distribHyp
1433 ## Private method creating 1D hypothes and storing it in the LayerDistribution
1434 # hypothes. Returns the created hypothes
1435 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1436 #print "OwnHypothesis",hypType
1437 if not self.nbLayers is None:
1438 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1439 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1440 study = self.mesh.smeshpyD.GetCurrentStudy() # prevent publishing of own 1D hypothesis
1441 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1442 self.mesh.smeshpyD.SetCurrentStudy( study ) # anable publishing
1443 self.distribHyp.SetLayerDistribution( hyp )
1446 ## Define "NumberOfLayers" hypothesis, specifying a number of layers of
1447 # prisms to build between the inner and outer shells
1448 # @param UseExisting if ==true - search existing hypothesis created with
1449 # same parameters, else (default) - create new
1450 def NumberOfLayers(self, n, UseExisting=0):
1451 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1452 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1453 CompareMethod=self.CompareNumberOfLayers)
1454 self.nbLayers.SetNumberOfLayers( n )
1455 return self.nbLayers
1457 ## Check if the given "NumberOfLayers" hypothesis has the same parameters as given arguments
1458 def CompareNumberOfLayers(self, hyp, args):
1459 return IsEqual(hyp.GetNumberOfLayers(), args[0])
1461 ## Define "LocalLength" hypothesis, specifying segment length
1462 # to build between the inner and outer shells
1463 # @param l for the length of segments
1464 # @param p for the precision of rounding
1465 def LocalLength(self, l, p=1e-07):
1466 hyp = self.OwnHypothesis("LocalLength", [l,p])
1471 ## Define "NumberOfSegments" hypothesis, specifying a number of layers of
1472 # prisms to build between the inner and outer shells
1473 # @param n for the number of segments
1474 # @param s for the scale factor (optional)
1475 def NumberOfSegments(self, n, s=[]):
1477 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1479 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1480 hyp.SetDistrType( 1 )
1481 hyp.SetScaleFactor(s)
1482 hyp.SetNumberOfSegments(n)
1485 ## Define "Arithmetic1D" hypothesis, specifying distribution of segments
1486 # to build between the inner and outer shells as arithmetic length increasing
1487 # @param start for the length of the first segment
1488 # @param end for the length of the last segment
1489 def Arithmetic1D(self, start, end ):
1490 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1491 hyp.SetLength(start, 1)
1492 hyp.SetLength(end , 0)
1495 ## Define "StartEndLength" hypothesis, specifying distribution of segments
1496 # to build between the inner and outer shells as geometric length increasing
1497 # @param start for the length of the first segment
1498 # @param end for the length of the last segment
1499 def StartEndLength(self, start, end):
1500 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1501 hyp.SetLength(start, 1)
1502 hyp.SetLength(end , 0)
1505 ## Define "AutomaticLength" hypothesis, specifying number of segments
1506 # to build between the inner and outer shells
1507 # @param fineness for the fineness [0-1]
1508 def AutomaticLength(self, fineness=0):
1509 hyp = self.OwnHypothesis("AutomaticLength")
1510 hyp.SetFineness( fineness )
1513 # Private class: Mesh_UseExisting
1514 # -------------------------------
1515 class Mesh_UseExisting(Mesh_Algorithm):
1517 def __init__(self, dim, mesh, geom=0):
1519 self.Create(mesh, geom, "UseExisting_1D")
1521 self.Create(mesh, geom, "UseExisting_2D")
1523 # Public class: Mesh
1524 # ==================
1526 ## Class to define a mesh
1528 # The class contains mesh shape, SMESH_Mesh, SMESH_MeshEditor
1538 # Creates mesh on the shape \a geom(or the empty mesh if geom equal to 0),
1539 # sets GUI name of this mesh to \a name.
1540 # @param obj Shape to be meshed or SMESH_Mesh object
1541 # @param name Study name of the mesh
1542 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1543 self.smeshpyD=smeshpyD
1544 self.geompyD=geompyD
1548 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1550 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1551 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1554 self.mesh = self.smeshpyD.CreateEmptyMesh()
1556 SetName(self.mesh, name)
1558 SetName(self.mesh, GetName(obj))
1560 self.editor = self.mesh.GetMeshEditor()
1562 ## Method that inits the Mesh object from SMESH_Mesh interface
1563 # @param theMesh is SMESH_Mesh object
1564 def SetMesh(self, theMesh):
1566 self.geom = self.mesh.GetShapeToMesh()
1568 ## Method that returns the mesh
1569 # @return SMESH_Mesh object
1575 name = GetName(self.GetMesh())
1579 def SetName(self, name):
1580 SetName(self.GetMesh(), name)
1582 ## Get the subMesh object associated to a subShape. The subMesh object
1583 # gives access to nodes and elements IDs.
1584 # \n SubMesh will be used instead of SubShape in a next idl version to
1585 # adress a specific subMesh...
1586 def GetSubMesh(self, theSubObject, name):
1587 submesh = self.mesh.GetSubMesh(theSubObject, name)
1590 ## Method that returns the shape associated to the mesh
1591 # @return GEOM_Object
1595 ## Method that associates given shape to the mesh(entails the mesh recreation)
1596 # @param geom shape to be meshed(GEOM_Object)
1597 def SetShape(self, geom):
1598 self.mesh = self.smeshpyD.CreateMesh(geom)
1600 ## Return true if hypotheses are defined well
1601 # @param theMesh is an instance of Mesh class
1602 # @param theSubObject subshape of a mesh shape
1603 def IsReadyToCompute(self, theSubObject):
1604 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1606 ## Return errors of hypotheses definintion
1607 # error list is empty if everything is OK
1608 # @param theMesh is an instance of Mesh class
1609 # @param theSubObject subshape of a mesh shape
1610 # @return a list of errors
1611 def GetAlgoState(self, theSubObject):
1612 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1614 ## Return geometrical object the given element is built on.
1615 # The returned geometrical object, if not nil, is either found in the
1616 # study or is published by this method with the given name
1617 # @param theMesh is an instance of Mesh class
1618 # @param theElementID an id of the mesh element
1619 # @param theGeomName user defined name of geometrical object
1620 # @return GEOM::GEOM_Object instance
1621 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1622 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1624 ## Returns mesh dimension depending on shape one
1625 def MeshDimension(self):
1626 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1627 if len( shells ) > 0 :
1629 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1631 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1637 ## Creates a segment discretization 1D algorithm.
1638 # If the optional \a algo parameter is not sets, this algorithm is REGULAR.
1639 # If the optional \a geom parameter is not sets, this algorithm is global.
1640 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1641 # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function
1642 # @param geom If defined, subshape to be meshed
1643 def Segment(self, algo=REGULAR, geom=0):
1644 ## if Segment(geom) is called by mistake
1645 if isinstance( algo, geompyDC.GEOM._objref_GEOM_Object):
1646 algo, geom = geom, algo
1647 if not algo: algo = REGULAR
1650 return Mesh_Segment(self, geom)
1651 elif algo == PYTHON:
1652 return Mesh_Segment_Python(self, geom)
1653 elif algo == COMPOSITE:
1654 return Mesh_CompositeSegment(self, geom)
1656 return Mesh_Segment(self, geom)
1658 ## Enable creation of nodes and segments usable by 2D algoritms.
1659 # Added nodes and segments must be bound to edges and vertices by
1660 # SetNodeOnVertex(), SetNodeOnEdge() and SetMeshElementOnShape()
1661 # If the optional \a geom parameter is not sets, this algorithm is global.
1662 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1663 # @param geom subshape to be manually meshed
1664 # @return StdMeshers_UseExisting_1D algorithm that generates nothing
1665 def UseExistingSegments(self, geom=0):
1666 algo = Mesh_UseExisting(1,self,geom)
1667 return algo.GetAlgorithm()
1669 ## Enable creation of nodes and faces usable by 3D algoritms.
1670 # Added nodes and faces must be bound to geom faces by SetNodeOnFace()
1671 # and SetMeshElementOnShape()
1672 # If the optional \a geom parameter is not sets, this algorithm is global.
1673 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1674 # @param geom subshape to be manually meshed
1675 # @return StdMeshers_UseExisting_2D algorithm that generates nothing
1676 def UseExistingFaces(self, geom=0):
1677 algo = Mesh_UseExisting(2,self,geom)
1678 return algo.GetAlgorithm()
1680 ## Creates a triangle 2D algorithm for faces.
1681 # If the optional \a geom parameter is not sets, this algorithm is global.
1682 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1683 # @param algo values are: smesh.MEFISTO || smesh.NETGEN_1D2D || smesh.NETGEN_2D
1684 # @param geom If defined, subshape to be meshed
1685 def Triangle(self, algo=MEFISTO, geom=0):
1686 ## if Triangle(geom) is called by mistake
1687 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1691 return Mesh_Triangle(self, algo, geom)
1693 ## Creates a quadrangle 2D algorithm for faces.
1694 # If the optional \a geom parameter is not sets, this algorithm is global.
1695 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1696 # @param geom If defined, subshape to be meshed
1697 def Quadrangle(self, geom=0):
1698 return Mesh_Quadrangle(self, geom)
1700 ## Creates a tetrahedron 3D algorithm for solids.
1701 # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D
1702 # If the optional \a geom parameter is not sets, this algorithm is global.
1703 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1704 # @param algo values are: smesh.NETGEN, smesh.GHS3D, smesh.FULL_NETGEN
1705 # @param geom If defined, subshape to be meshed
1706 def Tetrahedron(self, algo=NETGEN, geom=0):
1707 ## if Tetrahedron(geom) is called by mistake
1708 if ( isinstance( algo, geompyDC.GEOM._objref_GEOM_Object)):
1709 algo, geom = geom, algo
1710 if not algo: algo = NETGEN
1712 return Mesh_Tetrahedron(self, algo, geom)
1714 ## Creates a hexahedron 3D algorithm for solids.
1715 # If the optional \a geom parameter is not sets, this algorithm is global.
1716 # \n Otherwise, this algorithm define a submesh based on \a geom subshape.
1717 # @param geom If defined, subshape to be meshed
1718 ## def Hexahedron(self, geom=0):
1719 ## return Mesh_Hexahedron(self, geom)
1720 def Hexahedron(self, algo=Hexa, geom=0):
1721 ## if Hexahedron(geom, algo) or Hexahedron(geom) is called by mistake
1722 if ( isinstance(algo, geompyDC.GEOM._objref_GEOM_Object) ):
1723 if geom in [Hexa, Hexotic]: algo, geom = geom, algo
1724 elif geom == 0: algo, geom = Hexa, algo
1725 return Mesh_Hexahedron(self, algo, geom)
1727 ## Deprecated, only for compatibility!
1728 def Netgen(self, is3D, geom=0):
1729 return Mesh_Netgen(self, is3D, geom)
1731 ## Creates a projection 1D algorithm for edges.
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 Projection1D(self, geom=0):
1736 return Mesh_Projection1D(self, geom)
1738 ## Creates a projection 2D algorithm for faces.
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 Projection2D(self, geom=0):
1743 return Mesh_Projection2D(self, geom)
1745 ## Creates a projection 3D algorithm for solids.
1746 # If the optional \a geom parameter is not sets, this algorithm is global.
1747 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1748 # @param geom If defined, subshape to be meshed
1749 def Projection3D(self, geom=0):
1750 return Mesh_Projection3D(self, geom)
1752 ## Creates a 3D extrusion (Prism 3D) or RadialPrism 3D algorithm for solids.
1753 # If the optional \a geom parameter is not sets, this algorithm is global.
1754 # Otherwise, this algorithm define a submesh based on \a geom subshape.
1755 # @param geom If defined, subshape to be meshed
1756 def Prism(self, geom=0):
1760 nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] ))
1761 nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] ))
1762 if nbSolids == 0 or nbSolids == nbShells:
1763 return Mesh_Prism3D(self, geom)
1764 return Mesh_RadialPrism3D(self, geom)
1766 ## Compute the mesh and return the status of the computation
1767 def Compute(self, geom=0):
1768 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1770 print "Compute impossible: mesh is not constructed on geom shape."
1776 ok = self.smeshpyD.Compute(self.mesh, geom)
1777 except SALOME.SALOME_Exception, ex:
1778 print "Mesh computation failed, exception caught:"
1779 print " ", ex.details.text
1782 print "Mesh computation failed, exception caught:"
1783 traceback.print_exc()
1785 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1788 if err.isGlobalAlgo:
1796 reason = '%s %sD algorithm is missing' % (glob, dim)
1797 elif err.state == HYP_MISSING:
1798 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1799 % (glob, dim, name, dim))
1800 elif err.state == HYP_NOTCONFORM:
1801 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1802 elif err.state == HYP_BAD_PARAMETER:
1803 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1804 % ( glob, dim, name ))
1805 elif err.state == HYP_BAD_GEOMETRY:
1806 reason = ('%s %sD algorithm "%s" is assigned to geometry mismatching'
1807 'its expectation' % ( glob, dim, name ))
1809 reason = "For unknown reason."+\
1810 " Revise Mesh.Compute() implementation in smeshDC.py!"
1812 if allReasons != "":
1815 allReasons += reason
1817 if allReasons != "":
1818 print '"' + GetName(self.mesh) + '"',"has not been computed:"
1821 print '"' + GetName(self.mesh) + '"',"has not been computed."
1824 if salome.sg.hasDesktop():
1825 smeshgui = salome.ImportComponentGUI("SMESH")
1826 smeshgui.Init(salome.myStudyId)
1827 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1828 salome.sg.updateObjBrowser(1)
1832 ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1833 # The parameter \a fineness [0,-1] defines mesh fineness
1834 def AutomaticTetrahedralization(self, fineness=0):
1835 dim = self.MeshDimension()
1837 self.RemoveGlobalHypotheses()
1838 self.Segment().AutomaticLength(fineness)
1840 self.Triangle().LengthFromEdges()
1843 self.Tetrahedron(NETGEN)
1845 return self.Compute()
1847 ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1848 # The parameter \a fineness [0,-1] defines mesh fineness
1849 def AutomaticHexahedralization(self, fineness=0):
1850 dim = self.MeshDimension()
1852 self.RemoveGlobalHypotheses()
1853 self.Segment().AutomaticLength(fineness)
1860 return self.Compute()
1862 ## Assign hypothesis
1863 # @param hyp is a hypothesis to assign
1864 # @param geom is subhape of mesh geometry
1865 def AddHypothesis(self, hyp, geom=0):
1866 if isinstance( hyp, Mesh_Algorithm ):
1867 hyp = hyp.GetAlgorithm()
1872 status = self.mesh.AddHypothesis(geom, hyp)
1873 isAlgo = hyp._narrow( SMESH_Algo )
1874 TreatHypoStatus( status, GetName( hyp ), GetName( geom ), isAlgo )
1877 ## Unassign hypothesis
1878 # @param hyp is a hypothesis to unassign
1879 # @param geom is subhape of mesh geometry
1880 def RemoveHypothesis(self, hyp, geom=0):
1881 if isinstance( hyp, Mesh_Algorithm ):
1882 hyp = hyp.GetAlgorithm()
1887 status = self.mesh.RemoveHypothesis(geom, hyp)
1890 ## Get the list of hypothesis added on a geom
1891 # @param geom is subhape of mesh geometry
1892 def GetHypothesisList(self, geom):
1893 return self.mesh.GetHypothesisList( geom )
1895 ## Removes all global hypotheses
1896 def RemoveGlobalHypotheses(self):
1897 current_hyps = self.mesh.GetHypothesisList( self.geom )
1898 for hyp in current_hyps:
1899 self.mesh.RemoveHypothesis( self.geom, hyp )
1903 ## Create a mesh group based on geometric object \a grp
1904 # and give a \a name, \n if this parameter is not defined
1905 # the name is the same as the geometric group name \n
1906 # Note: Works like GroupOnGeom().
1907 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1908 # @param name is the name of the mesh group
1909 # @return SMESH_GroupOnGeom
1910 def Group(self, grp, name=""):
1911 return self.GroupOnGeom(grp, name)
1913 ## Deprecated, only for compatibility! Please, use ExportMED() method instead.
1914 # Export the mesh in a file with the MED format and choice the \a version of MED format
1915 # @param f is the file name
1916 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1917 def ExportToMED(self, f, version, opt=0):
1918 self.mesh.ExportToMED(f, opt, version)
1920 ## Export the mesh in a file with the MED format
1921 # @param f is the file name
1922 # @param auto_groups boolean parameter for creating/not creating
1923 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1924 # the typical use is auto_groups=false.
1925 # @param version MED format version(MED_V2_1 or MED_V2_2)
1926 def ExportMED(self, f, auto_groups=0, version=MED_V2_2):
1927 self.mesh.ExportToMED(f, auto_groups, version)
1929 ## Export the mesh in a file with the DAT format
1930 # @param f is the file name
1931 def ExportDAT(self, f):
1932 self.mesh.ExportDAT(f)
1934 ## Export the mesh in a file with the UNV format
1935 # @param f is the file name
1936 def ExportUNV(self, f):
1937 self.mesh.ExportUNV(f)
1939 ## Export the mesh in a file with the STL format
1940 # @param f is the file name
1941 # @param ascii defined the kind of file contents
1942 def ExportSTL(self, f, ascii=1):
1943 self.mesh.ExportSTL(f, ascii)
1946 # Operations with groups:
1947 # ----------------------
1949 ## Creates an empty mesh group
1950 # @param elementType is the type of elements in the group
1951 # @param name is the name of the mesh group
1952 # @return SMESH_Group
1953 def CreateEmptyGroup(self, elementType, name):
1954 return self.mesh.CreateGroup(elementType, name)
1956 ## Creates a mesh group based on geometric object \a grp
1957 # and give a \a name, \n if this parameter is not defined
1958 # the name is the same as the geometric group name
1959 # @param grp is a geometric group, a vertex, an edge, a face or a solid
1960 # @param name is the name of the mesh group
1961 # @return SMESH_GroupOnGeom
1962 def GroupOnGeom(self, grp, name="", typ=None):
1964 name = grp.GetName()
1967 tgeo = str(grp.GetShapeType())
1968 if tgeo == "VERTEX":
1970 elif tgeo == "EDGE":
1972 elif tgeo == "FACE":
1974 elif tgeo == "SOLID":
1976 elif tgeo == "SHELL":
1978 elif tgeo == "COMPOUND":
1979 if len( self.geompyD.GetObjectIDs( grp )) == 0:
1980 print "Mesh.Group: empty geometric group", GetName( grp )
1982 tgeo = self.geompyD.GetType(grp)
1983 if tgeo == geompyDC.ShapeType["VERTEX"]:
1985 elif tgeo == geompyDC.ShapeType["EDGE"]:
1987 elif tgeo == geompyDC.ShapeType["FACE"]:
1989 elif tgeo == geompyDC.ShapeType["SOLID"]:
1993 print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid"
1996 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1998 ## Create a mesh group by the given ids of elements
1999 # @param groupName is the name of the mesh group
2000 # @param elementType is the type of elements in the group
2001 # @param elemIDs is the list of ids
2002 # @return SMESH_Group
2003 def MakeGroupByIds(self, groupName, elementType, elemIDs):
2004 group = self.mesh.CreateGroup(elementType, groupName)
2008 ## Create a mesh group by the given conditions
2009 # @param groupName is the name of the mesh group
2010 # @param elementType is the type of elements in the group
2011 # @param CritType is type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
2012 # @param Compare belong to {FT_LessThan, FT_MoreThan, FT_EqualTo}
2013 # @param Treshold is threshold value (range of id ids as string, shape, numeric)
2014 # @param UnaryOp is FT_LogicalNOT or FT_Undefined
2015 # @return SMESH_Group
2019 CritType=FT_Undefined,
2022 UnaryOp=FT_Undefined):
2023 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Treshold, UnaryOp, FT_Undefined)
2024 group = self.MakeGroupByCriterion(groupName, aCriterion)
2027 ## Create a mesh group by the given criterion
2028 # @param groupName is the name of the mesh group
2029 # @param Criterion is the instance of Criterion class
2030 # @return SMESH_Group
2031 def MakeGroupByCriterion(self, groupName, Criterion):
2032 aFilterMgr = self.smeshpyD.CreateFilterManager()
2033 aFilter = aFilterMgr.CreateFilter()
2035 aCriteria.append(Criterion)
2036 aFilter.SetCriteria(aCriteria)
2037 group = self.MakeGroupByFilter(groupName, aFilter)
2040 ## Create a mesh group by the given criteria(list of criterions)
2041 # @param groupName is the name of the mesh group
2042 # @param Criteria is the list of criterions
2043 # @return SMESH_Group
2044 def MakeGroupByCriteria(self, groupName, theCriteria):
2045 aFilterMgr = self.smeshpyD.CreateFilterManager()
2046 aFilter = aFilterMgr.CreateFilter()
2047 aFilter.SetCriteria(theCriteria)
2048 group = self.MakeGroupByFilter(groupName, aFilter)
2051 ## Create a mesh group by the given filter
2052 # @param groupName is the name of the mesh group
2053 # @param Criterion is the instance of Filter class
2054 # @return SMESH_Group
2055 def MakeGroupByFilter(self, groupName, theFilter):
2056 anIds = theFilter.GetElementsId(self.mesh)
2057 anElemType = theFilter.GetElementType()
2058 group = self.MakeGroupByIds(groupName, anElemType, anIds)
2061 ## Pass mesh elements through the given filter and return ids
2062 # @param theFilter is SMESH_Filter
2063 # @return list of ids
2064 def GetIdsFromFilter(self, theFilter):
2065 return theFilter.GetElementsId(self.mesh)
2067 ## Verify whether 2D mesh element has free edges(edges connected to one face only)\n
2068 # Returns list of special structures(borders).
2069 # @return list of SMESH.FreeEdges.Border structure: edge id and two its nodes ids.
2070 def GetFreeBorders(self):
2071 aFilterMgr = self.smeshpyD.CreateFilterManager()
2072 aPredicate = aFilterMgr.CreateFreeEdges()
2073 aPredicate.SetMesh(self.mesh)
2074 aBorders = aPredicate.GetBorders()
2078 def RemoveGroup(self, group):
2079 self.mesh.RemoveGroup(group)
2081 ## Remove group with its contents
2082 def RemoveGroupWithContents(self, group):
2083 self.mesh.RemoveGroupWithContents(group)
2085 ## Get the list of groups existing in the mesh
2086 def GetGroups(self):
2087 return self.mesh.GetGroups()
2089 ## Get number of groups existing in the mesh
2091 return self.mesh.NbGroups()
2093 ## Get the list of names of groups existing in the mesh
2094 def GetGroupNames(self):
2095 groups = self.GetGroups()
2097 for group in groups:
2098 names.append(group.GetName())
2101 ## Union of two groups
2102 # New group is created. All mesh elements that are
2103 # present in initial groups are added to the new one
2104 def UnionGroups(self, group1, group2, name):
2105 return self.mesh.UnionGroups(group1, group2, name)
2107 ## Intersection of two groups
2108 # New group is created. All mesh elements that are
2109 # present in both initial groups are added to the new one.
2110 def IntersectGroups(self, group1, group2, name):
2111 return self.mesh.IntersectGroups(group1, group2, name)
2113 ## Cut of two groups
2114 # New group is created. All mesh elements that are present in
2115 # main group but do not present in tool group are added to the new one
2116 def CutGroups(self, mainGroup, toolGroup, name):
2117 return self.mesh.CutGroups(mainGroup, toolGroup, name)
2120 # Get some info about mesh:
2121 # ------------------------
2123 ## Get the log of nodes and elements added or removed since previous
2125 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
2126 # @return list of log_block structures:
2131 def GetLog(self, clearAfterGet):
2132 return self.mesh.GetLog(clearAfterGet)
2134 ## Clear the log of nodes and elements added or removed since previous
2135 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2137 self.mesh.ClearLog()
2139 def SetAutoColor(self, color):
2140 self.mesh.SetAutoColor(color)
2142 def GetAutoColor(self):
2143 return self.mesh.GetAutoColor()
2145 ## Get the internal Id
2147 return self.mesh.GetId()
2150 def GetStudyId(self):
2151 return self.mesh.GetStudyId()
2153 ## Check group names for duplications.
2154 # Consider maximum group name length stored in MED file.
2155 def HasDuplicatedGroupNamesMED(self):
2156 return self.mesh.HasDuplicatedGroupNamesMED()
2158 ## Obtain instance of SMESH_MeshEditor
2159 def GetMeshEditor(self):
2160 return self.mesh.GetMeshEditor()
2163 def GetMEDMesh(self):
2164 return self.mesh.GetMEDMesh()
2167 # Get informations about mesh contents:
2168 # ------------------------------------
2170 ## Returns number of nodes in mesh
2172 return self.mesh.NbNodes()
2174 ## Returns number of elements in mesh
2175 def NbElements(self):
2176 return self.mesh.NbElements()
2178 ## Returns number of edges in mesh
2180 return self.mesh.NbEdges()
2182 ## Returns number of edges with given order in mesh
2183 # @param elementOrder is order of elements:
2184 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2185 def NbEdgesOfOrder(self, elementOrder):
2186 return self.mesh.NbEdgesOfOrder(elementOrder)
2188 ## Returns number of faces in mesh
2190 return self.mesh.NbFaces()
2192 ## Returns number of faces with given order in mesh
2193 # @param elementOrder is order of elements:
2194 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2195 def NbFacesOfOrder(self, elementOrder):
2196 return self.mesh.NbFacesOfOrder(elementOrder)
2198 ## Returns number of triangles in mesh
2199 def NbTriangles(self):
2200 return self.mesh.NbTriangles()
2202 ## Returns number of triangles with given order in mesh
2203 # @param elementOrder is order of elements:
2204 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2205 def NbTrianglesOfOrder(self, elementOrder):
2206 return self.mesh.NbTrianglesOfOrder(elementOrder)
2208 ## Returns number of quadrangles in mesh
2209 def NbQuadrangles(self):
2210 return self.mesh.NbQuadrangles()
2212 ## Returns number of quadrangles with given order in mesh
2213 # @param elementOrder is order of elements:
2214 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2215 def NbQuadranglesOfOrder(self, elementOrder):
2216 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2218 ## Returns number of polygons in mesh
2219 def NbPolygons(self):
2220 return self.mesh.NbPolygons()
2222 ## Returns number of volumes in mesh
2223 def NbVolumes(self):
2224 return self.mesh.NbVolumes()
2226 ## Returns number of volumes with given order in mesh
2227 # @param elementOrder is order of elements:
2228 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2229 def NbVolumesOfOrder(self, elementOrder):
2230 return self.mesh.NbVolumesOfOrder(elementOrder)
2232 ## Returns number of tetrahedrons in mesh
2234 return self.mesh.NbTetras()
2236 ## Returns number of tetrahedrons with given order in mesh
2237 # @param elementOrder is order of elements:
2238 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2239 def NbTetrasOfOrder(self, elementOrder):
2240 return self.mesh.NbTetrasOfOrder(elementOrder)
2242 ## Returns number of hexahedrons in mesh
2244 return self.mesh.NbHexas()
2246 ## Returns number of hexahedrons with given order in mesh
2247 # @param elementOrder is order of elements:
2248 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2249 def NbHexasOfOrder(self, elementOrder):
2250 return self.mesh.NbHexasOfOrder(elementOrder)
2252 ## Returns number of pyramids in mesh
2253 def NbPyramids(self):
2254 return self.mesh.NbPyramids()
2256 ## Returns number of pyramids with given order in mesh
2257 # @param elementOrder is order of elements:
2258 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2259 def NbPyramidsOfOrder(self, elementOrder):
2260 return self.mesh.NbPyramidsOfOrder(elementOrder)
2262 ## Returns number of prisms in mesh
2264 return self.mesh.NbPrisms()
2266 ## Returns number of prisms with given order in mesh
2267 # @param elementOrder is order of elements:
2268 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2269 def NbPrismsOfOrder(self, elementOrder):
2270 return self.mesh.NbPrismsOfOrder(elementOrder)
2272 ## Returns number of polyhedrons in mesh
2273 def NbPolyhedrons(self):
2274 return self.mesh.NbPolyhedrons()
2276 ## Returns number of submeshes in mesh
2277 def NbSubMesh(self):
2278 return self.mesh.NbSubMesh()
2280 ## Returns list of mesh elements ids
2281 def GetElementsId(self):
2282 return self.mesh.GetElementsId()
2284 ## Returns list of ids of mesh elements with given type
2285 # @param elementType is required type of elements
2286 def GetElementsByType(self, elementType):
2287 return self.mesh.GetElementsByType(elementType)
2289 ## Returns list of mesh nodes ids
2290 def GetNodesId(self):
2291 return self.mesh.GetNodesId()
2293 # Get informations about mesh elements:
2294 # ------------------------------------
2296 ## Returns type of mesh element
2297 def GetElementType(self, id, iselem):
2298 return self.mesh.GetElementType(id, iselem)
2300 ## Returns list of submesh elements ids
2301 # @param Shape is geom object(subshape) IOR
2302 # Shape must be subshape of a ShapeToMesh()
2303 def GetSubMeshElementsId(self, Shape):
2304 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2305 ShapeID = Shape.GetSubShapeIndices()[0]
2308 return self.mesh.GetSubMeshElementsId(ShapeID)
2310 ## Returns list of submesh nodes ids
2311 # @param Shape is geom object(subshape) IOR
2312 # Shape must be subshape of a ShapeToMesh()
2313 def GetSubMeshNodesId(self, Shape, all):
2314 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2315 ShapeID = Shape.GetSubShapeIndices()[0]
2318 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2320 ## Returns list of ids of submesh elements with given type
2321 # @param Shape is geom object(subshape) IOR
2322 # Shape must be subshape of a ShapeToMesh()
2323 def GetSubMeshElementType(self, Shape):
2324 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2325 ShapeID = Shape.GetSubShapeIndices()[0]
2328 return self.mesh.GetSubMeshElementType(ShapeID)
2330 ## Get mesh description
2332 return self.mesh.Dump()
2335 # Get information about nodes and elements of mesh by its ids:
2336 # -----------------------------------------------------------
2338 ## Get XYZ coordinates of node as list of double
2339 # \n If there is not node for given ID - returns empty list
2340 def GetNodeXYZ(self, id):
2341 return self.mesh.GetNodeXYZ(id)
2343 ## For given node returns list of IDs of inverse elements
2344 # \n If there is not node for given ID - returns empty list
2345 def GetNodeInverseElements(self, id):
2346 return self.mesh.GetNodeInverseElements(id)
2348 ## @brief Return position of a node on shape
2349 # @return SMESH::NodePosition
2350 def GetNodePosition(self,NodeID):
2351 return self.mesh.GetNodePosition(NodeID)
2353 ## If given element is node returns IDs of shape from position
2354 # \n If there is not node for given ID - returns -1
2355 def GetShapeID(self, id):
2356 return self.mesh.GetShapeID(id)
2358 ## For given element returns ID of result shape after
2359 # FindShape() from SMESH_MeshEditor
2360 # \n If there is not element for given ID - returns -1
2361 def GetShapeIDForElem(self,id):
2362 return self.mesh.GetShapeIDForElem(id)
2364 ## Returns number of nodes for given element
2365 # \n If there is not element for given ID - returns -1
2366 def GetElemNbNodes(self, id):
2367 return self.mesh.GetElemNbNodes(id)
2369 ## Returns ID of node by given index for given element
2370 # \n If there is not element for given ID - returns -1
2371 # \n If there is not node for given index - returns -2
2372 def GetElemNode(self, id, index):
2373 return self.mesh.GetElemNode(id, index)
2375 ## Returns IDs of nodes of given element
2376 def GetElemNodes(self, id):
2377 return self.mesh.GetElemNodes(id)
2379 ## Returns true if given node is medium node
2380 # in given quadratic element
2381 def IsMediumNode(self, elementID, nodeID):
2382 return self.mesh.IsMediumNode(elementID, nodeID)
2384 ## Returns true if given node is medium node
2385 # in one of quadratic elements
2386 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2387 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2389 ## Returns number of edges for given element
2390 def ElemNbEdges(self, id):
2391 return self.mesh.ElemNbEdges(id)
2393 ## Returns number of faces for given element
2394 def ElemNbFaces(self, id):
2395 return self.mesh.ElemNbFaces(id)
2397 ## Returns true if given element is polygon
2398 def IsPoly(self, id):
2399 return self.mesh.IsPoly(id)
2401 ## Returns true if given element is quadratic
2402 def IsQuadratic(self, id):
2403 return self.mesh.IsQuadratic(id)
2405 ## Returns XYZ coordinates of bary center for given element
2407 # \n If there is not element for given ID - returns empty list
2408 def BaryCenter(self, id):
2409 return self.mesh.BaryCenter(id)
2412 # Mesh edition (SMESH_MeshEditor functionality):
2413 # ---------------------------------------------
2415 ## Removes elements from mesh by ids
2416 # @param IDsOfElements is list of ids of elements to remove
2417 def RemoveElements(self, IDsOfElements):
2418 return self.editor.RemoveElements(IDsOfElements)
2420 ## Removes nodes from mesh by ids
2421 # @param IDsOfNodes is list of ids of nodes to remove
2422 def RemoveNodes(self, IDsOfNodes):
2423 return self.editor.RemoveNodes(IDsOfNodes)
2425 ## Add node to mesh by coordinates
2426 def AddNode(self, x, y, z):
2427 return self.editor.AddNode( x, y, z)
2430 ## Create edge both similar and quadratic (this is determed
2431 # by number of given nodes).
2432 # @param IdsOfNodes List of node IDs for creation of element.
2433 # Needed order of nodes in this list corresponds to description
2434 # of MED. \n This description is located by the following link:
2435 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2436 def AddEdge(self, IDsOfNodes):
2437 return self.editor.AddEdge(IDsOfNodes)
2439 ## Create face both similar and quadratic (this is determed
2440 # by number of given nodes).
2441 # @param IdsOfNodes List of node IDs for creation of element.
2442 # Needed order of nodes in this list corresponds to description
2443 # of MED. \n This description is located by the following link:
2444 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2445 def AddFace(self, IDsOfNodes):
2446 return self.editor.AddFace(IDsOfNodes)
2448 ## Add polygonal face to mesh by list of nodes ids
2449 def AddPolygonalFace(self, IdsOfNodes):
2450 return self.editor.AddPolygonalFace(IdsOfNodes)
2452 ## Create volume both similar and quadratic (this is determed
2453 # by number of given nodes).
2454 # @param IdsOfNodes List of node IDs for creation of element.
2455 # Needed order of nodes in this list corresponds to description
2456 # of MED. \n This description is located by the following link:
2457 # http://www.salome-platform.org/salome2/web_med_internet/logiciels/medV2.2.2_doc_html/html/modele_de_donnees.html#3.
2458 def AddVolume(self, IDsOfNodes):
2459 return self.editor.AddVolume(IDsOfNodes)
2461 ## Create volume of many faces, giving nodes for each face.
2462 # @param IdsOfNodes List of node IDs for volume creation face by face.
2463 # @param Quantities List of integer values, Quantities[i]
2464 # gives quantity of nodes in face number i.
2465 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2466 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2468 ## Create volume of many faces, giving IDs of existing faces.
2469 # @param IdsOfFaces List of face IDs for volume creation.
2471 # Note: The created volume will refer only to nodes
2472 # of the given faces, not to the faces itself.
2473 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2474 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2477 ## @brief Bind a node to a vertex
2478 # @param NodeID - node ID
2479 # @param Vertex - vertex or vertex ID
2480 # @return True if succeed else raise an exception
2481 def SetNodeOnVertex(self, NodeID, Vertex):
2482 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2483 VertexID = Vertex.GetSubShapeIndices()[0]
2487 self.editor.SetNodeOnVertex(NodeID, VertexID)
2488 except SALOME.SALOME_Exception, inst:
2489 raise ValueError, inst.details.text
2493 ## @brief Store node position on an edge
2494 # @param NodeID - node ID
2495 # @param Edge - edge or edge ID
2496 # @param paramOnEdge - parameter on edge where the node is located
2497 # @return True if succeed else raise an exception
2498 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2499 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2500 EdgeID = Edge.GetSubShapeIndices()[0]
2504 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2505 except SALOME.SALOME_Exception, inst:
2506 raise ValueError, inst.details.text
2509 ## @brief Store node position on a face
2510 # @param NodeID - node ID
2511 # @param Face - face or face ID
2512 # @param u - U parameter on face where the node is located
2513 # @param v - V parameter on face where the node is located
2514 # @return True if succeed else raise an exception
2515 def SetNodeOnFace(self, NodeID, Face, u, v):
2516 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2517 FaceID = Face.GetSubShapeIndices()[0]
2521 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2522 except SALOME.SALOME_Exception, inst:
2523 raise ValueError, inst.details.text
2526 ## @brief Bind a node to a solid
2527 # @param NodeID - node ID
2528 # @param Solid - solid or solid ID
2529 # @return True if succeed else raise an exception
2530 def SetNodeInVolume(self, NodeID, Solid):
2531 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2532 SolidID = Solid.GetSubShapeIndices()[0]
2536 self.editor.SetNodeInVolume(NodeID, SolidID)
2537 except SALOME.SALOME_Exception, inst:
2538 raise ValueError, inst.details.text
2541 ## @brief Bind an element to a shape
2542 # @param ElementID - element ID
2543 # @param Shape - shape or shape ID
2544 # @return True if succeed else raise an exception
2545 def SetMeshElementOnShape(self, ElementID, Shape):
2546 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2547 ShapeID = Shape.GetSubShapeIndices()[0]
2551 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2552 except SALOME.SALOME_Exception, inst:
2553 raise ValueError, inst.details.text
2557 ## Move node with given id
2558 # @param NodeID id of the node
2559 # @param x new X coordinate
2560 # @param y new Y coordinate
2561 # @param z new Z coordinate
2562 def MoveNode(self, NodeID, x, y, z):
2563 return self.editor.MoveNode(NodeID, x, y, z)
2565 ## Find a node closest to a point
2566 # @param x X coordinate of a point
2567 # @param y Y coordinate of a point
2568 # @param z Z coordinate of a point
2569 # @return id of a node
2570 def FindNodeClosestTo(self, x, y, z):
2571 preview = self.mesh.GetMeshEditPreviewer()
2572 return preview.MoveClosestNodeToPoint(x, y, z, -1)
2574 ## Find a node closest to a point and move it to a point location
2575 # @param x X coordinate of a point
2576 # @param y Y coordinate of a point
2577 # @param z Z coordinate of a point
2578 # @return id of a moved node
2579 def MeshToPassThroughAPoint(self, x, y, z):
2580 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2582 ## Replace two neighbour triangles sharing Node1-Node2 link
2583 # with ones built on the same 4 nodes but having other common link.
2584 # @param NodeID1 first node id
2585 # @param NodeID2 second node id
2586 # @return false if proper faces not found
2587 def InverseDiag(self, NodeID1, NodeID2):
2588 return self.editor.InverseDiag(NodeID1, NodeID2)
2590 ## Replace two neighbour triangles sharing Node1-Node2 link
2591 # with a quadrangle built on the same 4 nodes.
2592 # @param NodeID1 first node id
2593 # @param NodeID2 second node id
2594 # @return false if proper faces not found
2595 def DeleteDiag(self, NodeID1, NodeID2):
2596 return self.editor.DeleteDiag(NodeID1, NodeID2)
2598 ## Reorient elements by ids
2599 # @param IDsOfElements if undefined reorient all mesh elements
2600 def Reorient(self, IDsOfElements=None):
2601 if IDsOfElements == None:
2602 IDsOfElements = self.GetElementsId()
2603 return self.editor.Reorient(IDsOfElements)
2605 ## Reorient all elements of the object
2606 # @param theObject is mesh, submesh or group
2607 def ReorientObject(self, theObject):
2608 if ( isinstance( theObject, Mesh )):
2609 theObject = theObject.GetMesh()
2610 return self.editor.ReorientObject(theObject)
2612 ## Fuse neighbour triangles into quadrangles.
2613 # @param IDsOfElements The triangles to be fused,
2614 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2615 # @param MaxAngle is a max angle between element normals at which fusion
2616 # is still performed; theMaxAngle is mesured in radians.
2617 # @return TRUE in case of success, FALSE otherwise.
2618 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2619 if IDsOfElements == []:
2620 IDsOfElements = self.GetElementsId()
2621 return self.editor.TriToQuad(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2623 ## Fuse neighbour triangles of the object into quadrangles
2624 # @param theObject is mesh, submesh or group
2625 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2626 # @param MaxAngle is a max angle between element normals at which fusion
2627 # is still performed; theMaxAngle is mesured in radians.
2628 # @return TRUE in case of success, FALSE otherwise.
2629 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2630 if ( isinstance( theObject, Mesh )):
2631 theObject = theObject.GetMesh()
2632 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2634 ## Split quadrangles into triangles.
2635 # @param IDsOfElements the faces to be splitted.
2636 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2637 # @return TRUE in case of success, FALSE otherwise.
2638 def QuadToTri (self, IDsOfElements, theCriterion):
2639 if IDsOfElements == []:
2640 IDsOfElements = self.GetElementsId()
2641 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2643 ## Split quadrangles into triangles.
2644 # @param theObject object to taking list of elements from, is mesh, submesh or group
2645 # @param theCriterion is FT_...; used to choose a diagonal for splitting.
2646 def QuadToTriObject (self, theObject, theCriterion):
2647 if ( isinstance( theObject, Mesh )):
2648 theObject = theObject.GetMesh()
2649 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2651 ## Split quadrangles into triangles.
2652 # @param theElems The faces to be splitted
2653 # @param the13Diag is used to choose a diagonal for splitting.
2654 # @return TRUE in case of success, FALSE otherwise.
2655 def SplitQuad (self, IDsOfElements, Diag13):
2656 if IDsOfElements == []:
2657 IDsOfElements = self.GetElementsId()
2658 return self.editor.SplitQuad(IDsOfElements, Diag13)
2660 ## Split quadrangles into triangles.
2661 # @param theObject is object to taking list of elements from, is mesh, submesh or group
2662 def SplitQuadObject (self, theObject, Diag13):
2663 if ( isinstance( theObject, Mesh )):
2664 theObject = theObject.GetMesh()
2665 return self.editor.SplitQuadObject(theObject, Diag13)
2667 ## Find better splitting of the given quadrangle.
2668 # @param IDOfQuad ID of the quadrangle to be splitted.
2669 # @param theCriterion is FT_...; a criterion to choose a diagonal for splitting.
2670 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2671 # diagonal is better, 0 if error occurs.
2672 def BestSplit (self, IDOfQuad, theCriterion):
2673 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2675 ## Split quafrangle faces near triangular facets of volumes
2677 def SplitQuadsNearTriangularFacets(self):
2678 faces_array = self.GetElementsByType(SMESH.FACE)
2679 for face_id in faces_array:
2680 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2681 quad_nodes = self.mesh.GetElemNodes(face_id)
2682 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2683 isVolumeFound = False
2684 for node1_elem in node1_elems:
2685 if not isVolumeFound:
2686 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2687 nb_nodes = self.GetElemNbNodes(node1_elem)
2688 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2689 volume_elem = node1_elem
2690 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2691 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2692 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2693 isVolumeFound = True
2694 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2695 self.SplitQuad([face_id], False) # diagonal 2-4
2696 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2697 isVolumeFound = True
2698 self.SplitQuad([face_id], True) # diagonal 1-3
2699 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2700 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2701 isVolumeFound = True
2702 self.SplitQuad([face_id], True) # diagonal 1-3
2704 ## @brief Split hexahedrons into tetrahedrons.
2706 # Use pattern mapping functionality for splitting.
2707 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2708 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2709 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2710 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2711 # key-point will be mapped into <theNode001>-th node of each volume.
2712 # The (0,0,0) key-point of used pattern corresponds to not split corner.
2713 # @return TRUE in case of success, FALSE otherwise.
2714 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2715 # Pattern: 5.---------.6
2720 # (0,0,1) 4.---------.7 * |
2727 # (0,0,0) 0.---------.3
2728 pattern_tetra = "!!! Nb of points: \n 8 \n\
2738 !!! Indices of points of 6 tetras: \n\
2746 pattern = self.smeshpyD.GetPattern()
2747 isDone = pattern.LoadFromFile(pattern_tetra)
2749 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2752 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2753 isDone = pattern.MakeMesh(self.mesh, False, False)
2754 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2756 # split quafrangle faces near triangular facets of volumes
2757 self.SplitQuadsNearTriangularFacets()
2761 ## @brief Split hexahedrons into prisms.
2763 # Use pattern mapping functionality for splitting.
2764 # @param theObject object to take list of hexahedrons from; is mesh, submesh or group.
2765 # @param theNode000,theNode001 is in range [0,7]; give an orientation of the
2766 # pattern relatively each hexahedron: the (0,0,0) key-point of pattern
2767 # will be mapped into <theNode000>-th node of each volume, the (0,0,1)
2768 # key-point will be mapped into <theNode001>-th node of each volume.
2769 # The edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2770 # @return TRUE in case of success, FALSE otherwise.
2771 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2772 # Pattern: 5.---------.6
2777 # (0,0,1) 4.---------.7 |
2784 # (0,0,0) 0.---------.3
2785 pattern_prism = "!!! Nb of points: \n 8 \n\
2795 !!! Indices of points of 2 prisms: \n\
2799 pattern = self.smeshpyD.GetPattern()
2800 isDone = pattern.LoadFromFile(pattern_prism)
2802 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2805 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2806 isDone = pattern.MakeMesh(self.mesh, False, False)
2807 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2809 # split quafrangle faces near triangular facets of volumes
2810 self.SplitQuadsNearTriangularFacets()
2815 # @param IDsOfElements list if ids of elements 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 Smooth(self, IDsOfElements, IDsOfFixedNodes,
2822 MaxNbOfIterations, MaxAspectRatio, Method):
2823 if IDsOfElements == []:
2824 IDsOfElements = self.GetElementsId()
2825 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2826 MaxNbOfIterations, MaxAspectRatio, Method)
2828 ## Smooth elements belong to given object
2829 # @param theObject object 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 SmoothObject(self, theObject, IDsOfFixedNodes,
2836 MaxNbOfIterations, MaxxAspectRatio, Method):
2837 if ( isinstance( theObject, Mesh )):
2838 theObject = theObject.GetMesh()
2839 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2840 MaxNbOfIterations, MaxxAspectRatio, Method)
2842 ## Parametric smooth the given elements
2843 # @param IDsOfElements list if ids of elements 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 SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2850 MaxNbOfIterations, MaxAspectRatio, Method):
2851 if IDsOfElements == []:
2852 IDsOfElements = self.GetElementsId()
2853 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2854 MaxNbOfIterations, MaxAspectRatio, Method)
2856 ## Parametric smooth elements belong to given object
2857 # @param theObject object to smooth
2858 # @param IDsOfFixedNodes list of ids of fixed nodes.
2859 # Note that nodes built on edges and boundary nodes are always fixed.
2860 # @param MaxNbOfIterations maximum number of iterations
2861 # @param MaxAspectRatio varies in range [1.0, inf]
2862 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2863 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2864 MaxNbOfIterations, MaxAspectRatio, Method):
2865 if ( isinstance( theObject, Mesh )):
2866 theObject = theObject.GetMesh()
2867 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2868 MaxNbOfIterations, MaxAspectRatio, Method)
2870 ## Converts all mesh to quadratic one, deletes old elements, replacing
2871 # them with quadratic ones with the same id.
2872 def ConvertToQuadratic(self, theForce3d):
2873 self.editor.ConvertToQuadratic(theForce3d)
2875 ## Converts all mesh from quadratic to ordinary ones,
2876 # deletes old quadratic elements, \n replacing
2877 # them with ordinary mesh elements with the same id.
2878 def ConvertFromQuadratic(self):
2879 return self.editor.ConvertFromQuadratic()
2881 ## Renumber mesh nodes
2882 def RenumberNodes(self):
2883 self.editor.RenumberNodes()
2885 ## Renumber mesh elements
2886 def RenumberElements(self):
2887 self.editor.RenumberElements()
2889 ## Generate new elements by rotation of the elements around the axis
2890 # @param IDsOfElements list of ids of elements to sweep
2891 # @param Axix axis of rotation, AxisStruct or line(geom object)
2892 # @param AngleInRadians angle of Rotation
2893 # @param NbOfSteps number of steps
2894 # @param Tolerance tolerance
2895 # @param MakeGroups to generate new groups from existing ones
2896 def RotationSweep(self, IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2897 if IDsOfElements == []:
2898 IDsOfElements = self.GetElementsId()
2899 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2900 Axix = self.smeshpyD.GetAxisStruct(Axix)
2902 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axix,
2903 AngleInRadians, NbOfSteps, Tolerance)
2904 self.editor.RotationSweep(IDsOfElements, Axix, AngleInRadians, NbOfSteps, Tolerance)
2907 ## Generate new elements by rotation of the elements of object around the axis
2908 # @param theObject object wich elements should be sweeped
2909 # @param Axix axis of rotation, AxisStruct or line(geom object)
2910 # @param AngleInRadians angle of Rotation
2911 # @param NbOfSteps number of steps
2912 # @param Tolerance tolerance
2913 # @param MakeGroups to generate new groups from existing ones
2914 def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False):
2915 if ( isinstance( theObject, Mesh )):
2916 theObject = theObject.GetMesh()
2917 if ( isinstance( Axix, geompyDC.GEOM._objref_GEOM_Object)):
2918 Axix = self.smeshpyD.GetAxisStruct(Axix)
2920 return self.editor.RotationSweepObjectMakeGroups(theObject, Axix, AngleInRadians,
2921 NbOfSteps, Tolerance)
2922 self.editor.RotationSweepObject(theObject, Axix, AngleInRadians, NbOfSteps, Tolerance)
2925 ## Generate new elements by extrusion of the elements with given ids
2926 # @param IDsOfElements list of elements ids for extrusion
2927 # @param StepVector vector, defining the direction and value of extrusion
2928 # @param NbOfSteps the number of steps
2929 # @param MakeGroups to generate new groups from existing ones
2930 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False):
2931 if IDsOfElements == []:
2932 IDsOfElements = self.GetElementsId()
2933 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2934 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2936 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
2937 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
2940 ## Generate new elements by extrusion of the elements with given ids
2941 # @param IDsOfElements is ids of elements
2942 # @param StepVector vector, defining the direction and value of extrusion
2943 # @param NbOfSteps the number of steps
2944 # @param ExtrFlags set flags for performing extrusion
2945 # @param SewTolerance uses for comparing locations of nodes if flag
2946 # EXTRUSION_FLAG_SEW is set
2947 # @param MakeGroups to generate new groups from existing ones
2948 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps, ExtrFlags, SewTolerance, MakeGroups=False):
2949 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2950 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2952 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
2953 ExtrFlags, SewTolerance)
2954 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
2955 ExtrFlags, SewTolerance)
2958 ## Generate new elements by extrusion of the elements belong to object
2959 # @param theObject object wich elements should be processed
2960 # @param StepVector vector, defining the direction and value of extrusion
2961 # @param NbOfSteps the number of steps
2962 # @param MakeGroups to generate new groups from existing ones
2963 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2964 if ( isinstance( theObject, Mesh )):
2965 theObject = theObject.GetMesh()
2966 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2967 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2969 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
2970 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
2973 ## Generate new elements by extrusion of the elements belong to object
2974 # @param theObject object wich elements should be processed
2975 # @param StepVector vector, defining the direction and value of extrusion
2976 # @param NbOfSteps the number of steps
2977 # @param MakeGroups to generate new groups from existing ones
2978 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2979 if ( isinstance( theObject, Mesh )):
2980 theObject = theObject.GetMesh()
2981 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2982 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2984 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
2985 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
2988 ## Generate new elements by extrusion of the elements belong to object
2989 # @param theObject object wich elements should be processed
2990 # @param StepVector vector, defining the direction and value of extrusion
2991 # @param NbOfSteps the number of steps
2992 # @param MakeGroups to generate new groups from existing ones
2993 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
2994 if ( isinstance( theObject, Mesh )):
2995 theObject = theObject.GetMesh()
2996 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
2997 StepVector = self.smeshpyD.GetDirStruct(StepVector)
2999 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3000 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3003 ## Generate new elements by extrusion of the given elements
3004 # A path of extrusion must be a meshed edge.
3005 # @param IDsOfElements is ids of elements
3006 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3007 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
3008 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
3009 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
3010 # @param Angles list of angles
3011 # @param HasRefPoint allows to use base point
3012 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
3013 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
3014 # @param MakeGroups to generate new groups from existing ones
3015 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
3016 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3017 HasAngles, Angles, HasRefPoint, RefPoint,
3018 MakeGroups=False, LinearVariation=False):
3019 if IDsOfElements == []:
3020 IDsOfElements = self.GetElementsId()
3021 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3022 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3025 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh.GetMesh(),
3026 PathShape, NodeStart, HasAngles,
3027 Angles, HasRefPoint, RefPoint)
3028 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh.GetMesh(), PathShape,
3029 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3031 ## Generate new elements by extrusion of the elements belong to object
3032 # A path of extrusion must be a meshed edge.
3033 # @param IDsOfElements is ids of elements
3034 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3035 # @param PathShape is shape(edge); as the mesh can be complex, the edge is used to define the sub-mesh for the path
3036 # @param NodeStart the first or the last node on the edge. It is used to define the direction of extrusion
3037 # @param HasAngles allows the shape to be rotated around the path to get the resulting mesh in a helical fashion
3038 # @param Angles list of angles
3039 # @param HasRefPoint allows to use base point
3040 # @param RefPoint point around which the shape is rotated(the mass center of the shape by default).
3041 # User can specify any point as the Base Point and the shape will be rotated with respect to this point.
3042 # @param MakeGroups to generate new groups from existing ones
3043 # @param LinearVariation makes compute rotation angles as linear variation of given Angles along path steps
3044 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3045 HasAngles, Angles, HasRefPoint, RefPoint,
3046 MakeGroups=False, LinearVariation=False):
3047 if ( isinstance( theObject, Mesh )):
3048 theObject = theObject.GetMesh()
3049 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3050 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3052 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh.GetMesh(),
3053 PathShape, NodeStart, HasAngles,
3054 Angles, HasRefPoint, RefPoint)
3055 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh.GetMesh(), PathShape,
3056 NodeStart, HasAngles, Angles, HasRefPoint,
3059 ## Symmetrical copy of mesh elements
3060 # @param IDsOfElements list of elements ids
3061 # @param Mirror is AxisStruct or geom object(point, line, plane)
3062 # @param theMirrorType is POINT, AXIS or PLANE
3063 # If the Mirror is geom object this parameter is unnecessary
3064 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3065 # @param MakeGroups to generate new groups from existing ones (if Copy)
3066 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3067 if IDsOfElements == []:
3068 IDsOfElements = self.GetElementsId()
3069 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3070 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3071 if Copy and MakeGroups:
3072 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3073 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3076 ## Create a new mesh by symmetrical copy of mesh elements
3077 # @param IDsOfElements list of elements ids
3078 # @param Mirror is AxisStruct or geom object(point, line, plane)
3079 # @param theMirrorType is POINT, AXIS or PLANE
3080 # If the Mirror is geom object this parameter is unnecessary
3081 # @param MakeGroups to generate new groups from existing ones
3082 # @param NewMeshName is a name of new mesh to create
3083 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3084 if IDsOfElements == []:
3085 IDsOfElements = self.GetElementsId()
3086 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3087 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3088 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3089 MakeGroups, NewMeshName)
3090 return Mesh(self.smeshpyD,self.geompyD,mesh)
3092 ## Symmetrical copy of object
3093 # @param theObject mesh, submesh or group
3094 # @param Mirror is AxisStruct or geom object(point, line, plane)
3095 # @param theMirrorType is POINT, AXIS or PLANE
3096 # If the Mirror is geom object this parameter is unnecessary
3097 # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0)
3098 # @param MakeGroups to generate new groups from existing ones (if Copy)
3099 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3100 if ( isinstance( theObject, Mesh )):
3101 theObject = theObject.GetMesh()
3102 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3103 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3104 if Copy and MakeGroups:
3105 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3106 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3109 ## Create a new mesh by symmetrical copy of object
3110 # @param theObject mesh, submesh or group
3111 # @param Mirror is AxisStruct or geom object(point, line, plane)
3112 # @param theMirrorType is POINT, AXIS or PLANE
3113 # If the Mirror is geom object this parameter is unnecessary
3114 # @param MakeGroups to generate new groups from existing ones
3115 # @param NewMeshName is a name of new mesh to create
3116 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3117 if ( isinstance( theObject, Mesh )):
3118 theObject = theObject.GetMesh()
3119 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3120 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3121 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3122 MakeGroups, NewMeshName)
3123 return Mesh( self.smeshpyD,self.geompyD,mesh )
3125 ## Translates the elements
3126 # @param IDsOfElements list of elements ids
3127 # @param Vector direction of translation(DirStruct or vector)
3128 # @param Copy allows to copy the translated elements
3129 # @param MakeGroups to generate new groups from existing ones (if Copy)
3130 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3131 if IDsOfElements == []:
3132 IDsOfElements = self.GetElementsId()
3133 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3134 Vector = self.smeshpyD.GetDirStruct(Vector)
3135 if Copy and MakeGroups:
3136 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3137 self.editor.Translate(IDsOfElements, Vector, Copy)
3140 ## Create a new mesh of translated elements
3141 # @param IDsOfElements list of elements ids
3142 # @param Vector direction of translation(DirStruct or vector)
3143 # @param MakeGroups to generate new groups from existing ones
3144 # @param NewMeshName is a name of new mesh to create
3145 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3146 if IDsOfElements == []:
3147 IDsOfElements = self.GetElementsId()
3148 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3149 Vector = self.smeshpyD.GetDirStruct(Vector)
3150 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3151 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3153 ## Translates the object
3154 # @param theObject object to translate(mesh, submesh, or group)
3155 # @param Vector direction of translation(DirStruct or geom vector)
3156 # @param Copy allows to copy the translated elements
3157 # @param MakeGroups to generate new groups from existing ones (if Copy)
3158 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3159 if ( isinstance( theObject, Mesh )):
3160 theObject = theObject.GetMesh()
3161 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3162 Vector = self.smeshpyD.GetDirStruct(Vector)
3163 if Copy and MakeGroups:
3164 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3165 self.editor.TranslateObject(theObject, Vector, Copy)
3168 ## Create a new mesh from translated object
3169 # @param theObject object to translate(mesh, submesh, or group)
3170 # @param Vector direction of translation(DirStruct or geom vector)
3171 # @param MakeGroups to generate new groups from existing ones
3172 # @param NewMeshName is a name of new mesh to create
3173 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3174 if (isinstance(theObject, Mesh)):
3175 theObject = theObject.GetMesh()
3176 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3177 Vector = self.smeshpyD.GetDirStruct(Vector)
3178 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3179 return Mesh( self.smeshpyD, self.geompyD, mesh )
3181 ## Rotates the elements
3182 # @param IDsOfElements list of elements ids
3183 # @param Axis axis of rotation(AxisStruct or geom line)
3184 # @param AngleInRadians angle of rotation(in radians)
3185 # @param Copy allows to copy the rotated elements
3186 # @param MakeGroups to generate new groups from existing ones (if Copy)
3187 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3188 if IDsOfElements == []:
3189 IDsOfElements = self.GetElementsId()
3190 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3191 Axis = self.smeshpyD.GetAxisStruct(Axis)
3192 if Copy and MakeGroups:
3193 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3194 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3197 ## Create a new mesh of rotated elements
3198 # @param IDsOfElements list of element ids
3199 # @param Axis axis of rotation(AxisStruct or geom line)
3200 # @param AngleInRadians angle of rotation(in radians)
3201 # @param MakeGroups to generate new groups from existing ones
3202 # @param NewMeshName is a name of new mesh to create
3203 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3204 if IDsOfElements == []:
3205 IDsOfElements = self.GetElementsId()
3206 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3207 Axis = self.smeshpyD.GetAxisStruct(Axis)
3208 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3209 MakeGroups, NewMeshName)
3210 return Mesh( self.smeshpyD, self.geompyD, mesh )
3212 ## Rotates the object
3213 # @param theObject object to rotate(mesh, submesh, or group)
3214 # @param Axis axis of rotation(AxisStruct or geom line)
3215 # @param AngleInRadians angle of rotation(in radians)
3216 # @param Copy allows to copy the rotated elements
3217 # @param MakeGroups to generate new groups from existing ones (if Copy)
3218 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3219 if (isinstance(theObject, Mesh)):
3220 theObject = theObject.GetMesh()
3221 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3222 Axis = self.smeshpyD.GetAxisStruct(Axis)
3223 if Copy and MakeGroups:
3224 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3225 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3228 ## Create a new mesh from a rotated object
3229 # @param theObject object to rotate (mesh, submesh, or group)
3230 # @param Axis axis of rotation(AxisStruct or geom line)
3231 # @param AngleInRadians angle of rotation(in radians)
3232 # @param MakeGroups to generate new groups from existing ones
3233 # @param NewMeshName is a name of new mesh to create
3234 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3235 if (isinstance( theObject, Mesh )):
3236 theObject = theObject.GetMesh()
3237 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3238 Axis = self.smeshpyD.GetAxisStruct(Axis)
3239 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3240 MakeGroups, NewMeshName)
3241 return Mesh( self.smeshpyD, self.geompyD, mesh )
3243 ## Find group of nodes close to each other within Tolerance.
3244 # @param Tolerance tolerance value
3245 # @param list of group of nodes
3246 def FindCoincidentNodes (self, Tolerance):
3247 return self.editor.FindCoincidentNodes(Tolerance)
3249 ## Find group of nodes close to each other within Tolerance.
3250 # @param Tolerance tolerance value
3251 # @param SubMeshOrGroup SubMesh or Group
3252 # @param list of group of nodes
3253 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance):
3254 return self.editor.FindCoincidentNodesOnPart(SubMeshOrGroup, Tolerance)
3257 # @param list of group of nodes
3258 def MergeNodes (self, GroupsOfNodes):
3259 self.editor.MergeNodes(GroupsOfNodes)
3261 ## Find elements built on the same nodes.
3262 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3263 # @return a list of groups of equal elements
3264 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3265 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3267 ## Merge elements in each given group.
3268 # @param GroupsOfElementsID groups of elements for merging
3269 def MergeElements(self, GroupsOfElementsID):
3270 self.editor.MergeElements(GroupsOfElementsID)
3272 ## Remove all but one of elements built on the same nodes.
3273 def MergeEqualElements(self):
3274 self.editor.MergeEqualElements()
3277 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3278 FirstNodeID2, SecondNodeID2, LastNodeID2,
3279 CreatePolygons, CreatePolyedrs):
3280 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3281 FirstNodeID2, SecondNodeID2, LastNodeID2,
3282 CreatePolygons, CreatePolyedrs)
3284 ## Sew conform free borders
3285 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3286 FirstNodeID2, SecondNodeID2):
3287 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3288 FirstNodeID2, SecondNodeID2)
3290 ## Sew border to side
3291 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3292 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3293 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3294 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3296 ## Sew two sides of a mesh. Nodes belonging to Side1 are
3297 # merged with nodes of elements of Side2.
3298 # Number of elements in theSide1 and in theSide2 must be
3299 # equal and they should have similar node connectivity.
3300 # The nodes to merge should belong to sides borders and
3301 # the first node should be linked to the second.
3302 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3303 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3304 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3305 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3306 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3307 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3309 ## Set new nodes for given element.
3310 # @param ide the element id
3311 # @param newIDs nodes ids
3312 # @return If number of nodes is not corresponded to type of element - returns false
3313 def ChangeElemNodes(self, ide, newIDs):
3314 return self.editor.ChangeElemNodes(ide, newIDs)
3316 ## If during last operation of MeshEditor some nodes were
3317 # created this method returns list of its IDs, \n
3318 # if new nodes not created - returns empty list
3319 def GetLastCreatedNodes(self):
3320 return self.editor.GetLastCreatedNodes()
3322 ## If during last operation of MeshEditor some elements were
3323 # created this method returns list of its IDs, \n
3324 # if new elements not creared - returns empty list
3325 def GetLastCreatedElems(self):
3326 return self.editor.GetLastCreatedElems()