X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshDC.py;h=381d765f8c4cc16fe804ff1a74955a02d8ed8f4a;hp=18614b8e9ace78ef43c34fdd082fd28806436751;hb=7446d65dcb323bdf4ccd6b19522276925dcd2807;hpb=c28b4480afaecf7d55f8166e0019df8ef14eec92 diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index 18614b8e9..381d765f8 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -20,10 +20,8 @@ # Author : Francis KLOSS, OCC # Module : SMESH -""" - \namespace smesh - \brief Module smesh -""" +## @package smesh +# Python API for SALOME %Mesh module ## @defgroup l1_auxiliary Auxiliary methods and structures ## @defgroup l1_creating Creating meshes @@ -89,6 +87,7 @@ import geompyDC import SMESH # This is necessary for back compatibility from SMESH import * +from smesh_algorithm import Mesh_Algorithm import SALOME import SALOMEDS @@ -630,10 +629,12 @@ class smeshDC(SMESH._objref_SMESH_Gen): if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface, FT_BelongToCylinder, FT_LyingOnGeom]: - # Checks the Threshold + # Checks that Threshold is GEOM object if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object): aCriterion.ThresholdStr = GetName(aThreshold) - aCriterion.ThresholdID = salome.ObjectToID(aThreshold) + aCriterion.ThresholdID = aThreshold.GetStudyEntry() + if not aCriterion.ThresholdID: + raise RuntimeError, "Threshold shape must be published" else: print "Error: The Threshold should be a shape." return None @@ -642,7 +643,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): UnaryOp = FT_Undefined pass elif CritType == FT_RangeOfIds: - # Checks the Threshold + # Checks that Threshold is string if isinstance(aThreshold, str): aCriterion.ThresholdStr = aThreshold else: @@ -651,7 +652,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): elif CritType == FT_CoplanarFaces: # Checks the Threshold if isinstance(aThreshold, int): - aCriterion.ThresholdID = "%s"%aThreshold + aCriterion.ThresholdID = str(aThreshold) elif isinstance(aThreshold, str): ID = int(aThreshold) if ID < 1: @@ -1167,15 +1168,18 @@ class Mesh: except: shapeText = " on subshape #%s" % (err.subShapeID) errText = "" - stdErrors = ["OK", #COMPERR_OK - "Invalid input mesh", #COMPERR_BAD_INPUT_MESH - "std::exception", #COMPERR_STD_EXCEPTION - "OCC exception", #COMPERR_OCC_EXCEPTION - "SALOME exception", #COMPERR_SLM_EXCEPTION - "Unknown exception", #COMPERR_EXCEPTION + stdErrors = ["OK", #COMPERR_OK + "Invalid input mesh", #COMPERR_BAD_INPUT_MESH + "std::exception", #COMPERR_STD_EXCEPTION + "OCC exception", #COMPERR_OCC_EXCEPTION + "SALOME exception", #COMPERR_SLM_EXCEPTION + "Unknown exception", #COMPERR_EXCEPTION "Memory allocation problem", #COMPERR_MEMORY_PB - "Algorithm failed", #COMPERR_ALGO_FAILED - "Unexpected geometry"]#COMPERR_BAD_SHAPE + "Algorithm failed", #COMPERR_ALGO_FAILED + "Unexpected geometry", #COMPERR_BAD_SHAPE + "Warning", #COMPERR_WARNING + "Computation cancelled",#COMPERR_CANCELED + "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE if err.code > 0: if err.code < len(stdErrors): errText = stdErrors[err.code] else: @@ -1372,19 +1376,7 @@ class Mesh: pass pass - ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead. - # Exports the mesh in a file in MED format and chooses the \a version of MED format - ## allowing to overwrite the file if it exists or add the exported data to its contents - # @param f the file name - # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2 - # @param opt boolean parameter for creating/not creating - # the groups Group_On_All_Nodes, Group_On_All_Faces, ... - # @param overwrite boolean parameter for overwriting/not overwriting the file - # @ingroup l2_impexp - def ExportToMED(self, f, version, opt=0, overwrite=1): - self.mesh.ExportToMEDX(f, opt, version, overwrite) - - ## Exports the mesh in a file in MED format and chooses the \a version of MED format + ## Exports the mesh in a file in MED format and chooses the \a version of MED format ## allowing to overwrite the file if it exists or add the exported data to its contents # @param f is the file name # @param auto_groups boolean parameter for creating/not creating @@ -1462,6 +1454,18 @@ class Mesh: meshPart = self.mesh self.mesh.ExportCGNS(meshPart, f, overwrite) + ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead. + # Exports the mesh in a file in MED format and chooses the \a version of MED format + ## allowing to overwrite the file if it exists or add the exported data to its contents + # @param f the file name + # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2 + # @param opt boolean parameter for creating/not creating + # the groups Group_On_All_Nodes, Group_On_All_Faces, ... + # @param overwrite boolean parameter for overwriting/not overwriting the file + # @ingroup l2_impexp + def ExportToMED(self, f, version, opt=0, overwrite=1): + self.mesh.ExportToMEDX(f, opt, version, overwrite) + # Operations with groups: # ---------------------- @@ -1606,26 +1610,6 @@ class Mesh: group.AddFrom( theFilter ) return group - ## Passes mesh elements through the given filter and return IDs of fitting elements - # @param theFilter SMESH_Filter - # @return a list of ids - # @ingroup l1_controls - def GetIdsFromFilter(self, theFilter): - theFilter.SetMesh( self.mesh ) - return theFilter.GetIDs() - - ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n - # Returns a list of special structures (borders). - # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes. - # @ingroup l1_controls - def GetFreeBorders(self): - aFilterMgr = self.smeshpyD.CreateFilterManager() - aPredicate = aFilterMgr.CreateFreeEdges() - aPredicate.SetMesh(self.mesh) - aBorders = aPredicate.GetBorders() - aFilterMgr.UnRegister() - return aBorders - ## Removes a group # @ingroup l2_grps_delete def RemoveGroup(self, group): @@ -1821,6 +1805,12 @@ class Mesh: def Nb0DElements(self): return self.mesh.Nb0DElements() + ## Returns the number of ball discrete elements in the mesh + # @return an integer value + # @ingroup l1_meshinfo + def NbBalls(self): + return self.mesh.NbBalls() + ## Returns the number of edges in the mesh # @return an integer value # @ingroup l1_meshinfo @@ -2037,7 +2027,7 @@ class Mesh: # @ingroup l1_meshinfo def GetSubMeshNodesId(self, Shape, all): if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)): - ShapeID = Shape.GetSubShapeIndices()[0] + ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape ) else: ShapeID = Shape return self.mesh.GetSubMeshNodesId(ShapeID, all) @@ -2160,6 +2150,11 @@ class Mesh: def IsQuadratic(self, id): return self.mesh.IsQuadratic(id) + ## Returns diameter of a ball discrete element or zero in case of an invalid \a id + # @ingroup l1_meshinfo + def GetBallDiameter(self, id): + return self.mesh.GetBallDiameter(id) + ## Returns XYZ coordinates of the barycenter of the given element # \n If there is no element for the given ID - returns an empty list # @return a list of three double values @@ -2167,6 +2162,26 @@ class Mesh: def BaryCenter(self, id): return self.mesh.BaryCenter(id) + ## Passes mesh elements through the given filter and return IDs of fitting elements + # @param theFilter SMESH_Filter + # @return a list of ids + # @ingroup l1_controls + def GetIdsFromFilter(self, theFilter): + theFilter.SetMesh( self.mesh ) + return theFilter.GetIDs() + + ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n + # Returns a list of special structures (borders). + # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes. + # @ingroup l1_controls + def GetFreeBorders(self): + aFilterMgr = self.smeshpyD.CreateFilterManager() + aPredicate = aFilterMgr.CreateFreeEdges() + aPredicate.SetMesh(self.mesh) + aBorders = aPredicate.GetBorders() + aFilterMgr.UnRegister() + return aBorders + # Get mesh measurements information: # ------------------------------------ @@ -2295,6 +2310,14 @@ class Mesh: def Add0DElement(self, IDOfNode): return self.editor.Add0DElement(IDOfNode) + ## Creates a ball element on a node with given ID. + # @param IDOfNode the ID of node for creation of the element. + # @param diameter the bal diameter. + # @return the Id of the new ball element + # @ingroup l2_modif_add + def AddBall(self, IDOfNode, diameter): + return self.editor.AddBall( IDOfNode, diameter ) + ## Creates a linear or quadratic edge (this is determined # by the number of given nodes). # @param IDsOfNodes the list of node IDs for creation of the element. @@ -2481,7 +2504,7 @@ class Mesh: # @param y the Y coordinate of a point # @param z the Z coordinate of a point # @param elementType type of elements to find (SMESH.ALL type - # means elements of any type excluding nodes and 0D elements) + # means elements of any type excluding nodes, discrete and 0D elements) # @param meshPart a part of mesh (group, sub-mesh) to search within # @return list of IDs of found elements # @ingroup l2_modif_throughp @@ -2491,7 +2514,8 @@ class Mesh: else: return self.editor.FindElementsByPoint(x, y, z, elementType) - # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration. + # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration: + # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails. def GetPointState(self, x, y, z): @@ -3952,6 +3976,18 @@ class Mesh: def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape): return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape) + ## Identify the elements that will be affected by node duplication (actual duplication is not performed. + # This method is the first step of DoubleNodeElemGroupsInRegion. + # @param theElems - list of groups of elements (edges or faces) to be replicated + # @param theNodesNot - list of groups of nodes not to replicated + # @param theShape - shape to detect affected elements (element which geometric center + # located on or inside shape). + # The replicated nodes should be associated to affected elements. + # @return groups of affected elements + # @ingroup l2_modif_edit + def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape): + return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape) + ## Double nodes on shared faces between groups of volumes and create flat elements on demand. # The list of groups must describe a partition of the mesh volumes. # The nodes of the internal faces at the boundaries of the groups are doubled. @@ -3972,6 +4008,11 @@ class Mesh: # @return TRUE if operation has been completed successfully, FALSE otherwise def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ): return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces ) + + ## identify all the elements around a geom shape, get the faces delimiting the hole + # + def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords): + return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords ) def _valueFromFunctor(self, funcType, elemId): fn = self.smeshpyD.GetFunctor(funcType) @@ -4053,283 +4094,10 @@ class Mesh: def GetSkew(self, elemId): return self._valueFromFunctor(SMESH.FT_Skew, elemId) -## The mother class to define algorithm, it is not recommended to use it directly. + pass # end of Mesh class + +## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class # -# For each meshing algorithm, a python class inheriting from class Mesh_Algorithm -# should be defined. This descendant class sould have two attributes defining the way -# it is created by class Mesh (see e.g. class StdMeshersDC_Segment in StdMeshersDC.py). -# - meshMethod attribute defines name of method of class Mesh by calling which the -# python class of algorithm is created. E.g. if in class MyPlugin_Algorithm -# meshMethod = "MyAlgorithm", then an instance of MyPlugin_Algorithm is created -# by the following code: my_algo = mesh.MyAlgorithm() -# - algoType defines name of algorithm type and is used mostly to discriminate -# algorithms that are created by the same method of class Mesh. E.g. if -# MyPlugin_Algorithm.algoType = "MyPLUGIN" then it's creation code can be: -# my_algo = mesh.MyAlgorithm(algo="MyPLUGIN") -# @ingroup l2_algorithms -class Mesh_Algorithm: - # @class Mesh_Algorithm - # @brief Class Mesh_Algorithm - - #def __init__(self,smesh): - # self.smesh=smesh - def __init__(self): - self.mesh = None - self.geom = None - self.subm = None - self.algo = None - - ## Finds a hypothesis in the study by its type name and parameters. - # Finds only the hypotheses created in smeshpyD engine. - # @return SMESH.SMESH_Hypothesis - def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD): - study = smeshpyD.GetCurrentStudy() - #to do: find component by smeshpyD object, not by its data type - scomp = study.FindComponent(smeshpyD.ComponentDataType()) - if scomp is not None: - res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot) - # Check if the root label of the hypotheses exists - if res and hypRoot is not None: - iter = study.NewChildIterator(hypRoot) - # Check all published hypotheses - while iter.More(): - hypo_so_i = iter.Value() - attr = hypo_so_i.FindAttribute("AttributeIOR")[1] - if attr is not None: - anIOR = attr.Value() - hypo_o_i = salome.orb.string_to_object(anIOR) - if hypo_o_i is not None: - # Check if this is a hypothesis - hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis) - if hypo_i is not None: - # Check if the hypothesis belongs to current engine - if smeshpyD.GetObjectId(hypo_i) > 0: - # Check if this is the required hypothesis - if hypo_i.GetName() == hypname: - # Check arguments - if CompareMethod(hypo_i, args): - # found!!! - return hypo_i - pass - pass - pass - pass - pass - iter.Next() - pass - pass - pass - return None - - ## Finds the algorithm in the study by its type name. - # Finds only the algorithms, which have been created in smeshpyD engine. - # @return SMESH.SMESH_Algo - def FindAlgorithm (self, algoname, smeshpyD): - study = smeshpyD.GetCurrentStudy() - if not study: return None - #to do: find component by smeshpyD object, not by its data type - scomp = study.FindComponent(smeshpyD.ComponentDataType()) - if scomp is not None: - res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot) - # Check if the root label of the algorithms exists - if res and hypRoot is not None: - iter = study.NewChildIterator(hypRoot) - # Check all published algorithms - while iter.More(): - algo_so_i = iter.Value() - attr = algo_so_i.FindAttribute("AttributeIOR")[1] - if attr is not None: - anIOR = attr.Value() - algo_o_i = salome.orb.string_to_object(anIOR) - if algo_o_i is not None: - # Check if this is an algorithm - algo_i = algo_o_i._narrow(SMESH.SMESH_Algo) - if algo_i is not None: - # Checks if the algorithm belongs to the current engine - if smeshpyD.GetObjectId(algo_i) > 0: - # Check if this is the required algorithm - if algo_i.GetName() == algoname: - # found!!! - return algo_i - pass - pass - pass - pass - iter.Next() - pass - pass - pass - return None - - ## If the algorithm is global, returns 0; \n - # else returns the submesh associated to this algorithm. - def GetSubMesh(self): - return self.subm - - ## Returns the wrapped mesher. - def GetAlgorithm(self): - return self.algo - - ## Gets the list of hypothesis that can be used with this algorithm - def GetCompatibleHypothesis(self): - mylist = [] - if self.algo: - mylist = self.algo.GetCompatibleHypothesis() - return mylist - - ## Gets the name of the algorithm - def GetName(self): - GetName(self.algo) - - ## Sets the name to the algorithm - def SetName(self, name): - self.mesh.smeshpyD.SetName(self.algo, name) - - ## Gets the id of the algorithm - def GetId(self): - return self.algo.GetId() - - ## Private method. - def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"): - if geom is None: - raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape" - algo = self.FindAlgorithm(hypo, mesh.smeshpyD) - if algo is None: - algo = mesh.smeshpyD.CreateHypothesis(hypo, so) - pass - self.Assign(algo, mesh, geom) - return self.algo - - ## Private method - def Assign(self, algo, mesh, geom): - if geom is None: - raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape" - self.mesh = mesh - name = "" - if not geom: - self.geom = mesh.geom - else: - self.geom = geom - AssureGeomPublished( mesh, geom ) - try: - name = GetName(geom) - pass - except: - pass - self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName()) - self.algo = algo - status = mesh.mesh.AddHypothesis(self.geom, self.algo) - TreatHypoStatus( status, algo.GetName(), name, True ) - return - - def CompareHyp (self, hyp, args): - print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName() - return False - - def CompareEqualHyp (self, hyp, args): - return True - - ## Private method - def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so", - UseExisting=0, CompareMethod=""): - hypo = None - if UseExisting: - if CompareMethod == "": CompareMethod = self.CompareHyp - hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD) - pass - if hypo is None: - hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so) - a = "" - s = "=" - for arg in args: - argStr = str(arg) - if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ): - argStr = arg.GetStudyEntry() - if not argStr: argStr = "GEOM_Obj_%s", arg.GetEntry() - if len( argStr ) > 10: - argStr = argStr[:7]+"..." - if argStr[0] == '[': argStr += ']' - a = a + s + argStr - s = "," - pass - if len(a) > 50: - a = a[:47]+"..." - self.mesh.smeshpyD.SetName(hypo, hyp + a) - pass - geomName="" - if self.geom: - geomName = GetName(self.geom) - status = self.mesh.mesh.AddHypothesis(self.geom, hypo) - TreatHypoStatus( status, GetName(hypo), geomName, 0 ) - return hypo - - ## Returns entry of the shape to mesh in the study - def MainShapeEntry(self): - if not self.mesh or not self.mesh.GetMesh(): return "" - if not self.mesh.GetMesh().HasShapeToMesh(): return "" - shape = self.mesh.GetShape() - return shape.GetStudyEntry() - - ## Defines "ViscousLayers" hypothesis to give parameters of layers of prisms to build - # near mesh boundary. This hypothesis can be used by several 3D algorithms: - # NETGEN 3D, GHS3D, Hexahedron(i,j,k) - # @param thickness total thickness of layers of prisms - # @param numberOfLayers number of layers of prisms - # @param stretchFactor factor (>1.0) of growth of layer thickness towards inside of mesh - # @param ignoreFaces list of geometrical faces (or their ids) not to generate layers on - # @ingroup l3_hypos_additi - def ViscousLayers(self, thickness, numberOfLayers, stretchFactor, ignoreFaces=[]): - if not isinstance(self.algo, SMESH._objref_SMESH_3D_Algo): - raise TypeError, "ViscousLayers are supported by 3D algorithms only" - if not "ViscousLayers" in self.GetCompatibleHypothesis(): - raise TypeError, "ViscousLayers are not supported by %s"%self.algo.GetName() - if ignoreFaces and isinstance( ignoreFaces[0], geompyDC.GEOM._objref_GEOM_Object ): - ignoreFaces = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f) for f in ignoreFaces ] - hyp = self.Hypothesis("ViscousLayers", - [thickness, numberOfLayers, stretchFactor, ignoreFaces]) - hyp.SetTotalThickness(thickness) - hyp.SetNumberLayers(numberOfLayers) - hyp.SetStretchFactor(stretchFactor) - hyp.SetIgnoreFaces(ignoreFaces) - return hyp - - ## Transform a list of ether edges or tuples (edge 1st_vertex_of_edge) - # into a list acceptable to SetReversedEdges() of some 1D hypotheses - # @ingroup l3_hypos_1dhyps - def ReversedEdgeIndices(self, reverseList): - resList = [] - geompy = self.mesh.geompyD - for i in reverseList: - if isinstance( i, int ): - s = geompy.SubShapes(self.mesh.geom, [i])[0] - if s.GetShapeType() != geompyDC.GEOM.EDGE: - raise TypeError, "Not EDGE index given" - resList.append( i ) - elif isinstance( i, geompyDC.GEOM._objref_GEOM_Object ): - if i.GetShapeType() != geompyDC.GEOM.EDGE: - raise TypeError, "Not an EDGE given" - resList.append( geompy.GetSubShapeID(self.mesh.geom, i )) - elif len( i ) > 1: - e = i[0] - v = i[1] - if not isinstance( e, geompyDC.GEOM._objref_GEOM_Object ) or \ - not isinstance( v, geompyDC.GEOM._objref_GEOM_Object ): - raise TypeError, "A list item must be a tuple (edge 1st_vertex_of_edge)" - if v.GetShapeType() == geompyDC.GEOM.EDGE and \ - e.GetShapeType() == geompyDC.GEOM.VERTEX: - v,e = e,v - if e.GetShapeType() != geompyDC.GEOM.EDGE or \ - v.GetShapeType() != geompyDC.GEOM.VERTEX: - raise TypeError, "A list item must be a tuple (edge 1st_vertex_of_edge)" - vFirst = FirstVertexOnCurve( e ) - tol = geompy.Tolerance( vFirst )[-1] - if geompy.MinDistance( v, vFirst ) > 1.5*tol: - resList.append( geompy.GetSubShapeID(self.mesh.geom, e )) - else: - raise TypeError, "Item must be either an edge or tuple (edge 1st_vertex_of_edge)" - return resList - - class Pattern(SMESH._objref_SMESH_Pattern): def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse): @@ -4344,13 +4112,9 @@ class Pattern(SMESH._objref_SMESH_Pattern): theMesh.SetParameters(Parameters) return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index ) -#Registering the new proxy for Pattern +# Registering the new proxy for Pattern omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern) - - - - ## Private class used to bind methods creating algorithms to the class Mesh # class algoCreator: @@ -4394,6 +4158,7 @@ class algoCreator: return None # Private class used to substitute and store variable parameters of hypotheses. +# class hypMethodWrapper: def __init__(self, hyp, method): self.hyp = hyp