X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSMESH_SWIG%2Fsmesh.py;fp=src%2FSMESH_SWIG%2Fsmesh.py;h=c8cadff0f262b05980b072990d93d075340a2665;hb=79b1ac2b6df9117f16f11d444b1f165d477a1813;hp=82d0750e5a50b38dc407788a3055f43af67eacf4;hpb=984c4ffdd7df62aeaedc544cd0b8e64ff8f53f1a;p=modules%2Fsmesh.git diff --git a/src/SMESH_SWIG/smesh.py b/src/SMESH_SWIG/smesh.py index 82d0750e5..c8cadff0f 100644 --- a/src/SMESH_SWIG/smesh.py +++ b/src/SMESH_SWIG/smesh.py @@ -21,590 +21,23 @@ # Author : Francis KLOSS, OCC # Module : SMESH -""" - \namespace smesh +"""@package smesh \brief Module smesh """ import salome -import geompy -import StdMeshers -import SMESH - +from salome import * -REGULAR = 1 -PYTHON = 2 - -NETGEN = 3 -GHS3D = 4 +import geompy +import smeshDC +from smeshDC import * smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH") -smesh.SetCurrentStudy(salome.myStudy) - - -NO_NAME = "NoName" - -def GetName(obj): - ior = salome.orb.object_to_string(obj) - sobj = salome.myStudy.FindObjectIOR(ior) - if sobj is None: - return NO_NAME - else: - attr = sobj.FindAttribute("AttributeName")[1] - return attr.Value() - -def SetName(obj, name): - ior = salome.orb.object_to_string(obj) - sobj = salome.myStudy.FindObjectIOR(ior) - if not sobj is None: - attr = sobj.FindAttribute("AttributeName")[1] - attr.SetValue(name) - -## Mother class to define algorithm, recommended to don't use directly. -# -# More details. -class Mesh_Algorithm: - # @class Mesh_Algorithm - # @brief Class Mesh_Algorithm - - mesh = 0 - geom = 0 - subm = 0 - algo = 0 - - ## If the algorithm is global, return 0 - # \fn else return the submesh associated to this algorithm. - # - # More details. - def GetSubMesh(self): - return self.subm - - ## Return the wrapped mesher. - def GetAlgorithm(self): - return self.algo - - ## Private method. Print error message if a hypothesis was not assigned. - def TreatHypoStatus(self, status, hypName, geomName, isAlgo): - if isAlgo: - hypType = "algorithm" - else: - hypType = "hypothesis" - if status == SMESH.HYP_UNKNOWN_FATAL : - reason = "for unknown reason" - elif status == SMESH.HYP_INCOMPATIBLE : - reason = "this hypothesis mismatches algorithm" - elif status == SMESH.HYP_NOTCONFORM : - reason = "not conform mesh would be built" - elif status == SMESH.HYP_ALREADY_EXIST : - reason = hypType + " of the same dimension already assigned to this shape" - elif status == SMESH.HYP_BAD_DIM : - reason = hypType + " mismatches shape" - elif status == SMESH.HYP_CONCURENT : - reason = "there are concurrent hypotheses on sub-shapes" - elif status == SMESH.HYP_BAD_SUBSHAPE : - reason = "shape is neither the main one, nor its subshape, nor a valid group" - else: - return - hypName = '"' + hypName + '"' - geomName= '"' + geomName+ '"' - if status < SMESH.HYP_UNKNOWN_FATAL: - print hypName, "was assigned to", geomName,"but", reason - else: - print hypName, "was not assigned to",geomName,":", reason - pass - - ## 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" - self.mesh = mesh - piece = mesh.geom - if geom==0: - self.geom = piece - name = GetName(piece) - else: - self.geom = geom - name = GetName(geom) - if name==NO_NAME: - name = geompy.SubShapeName(geom, piece) - geompy.addToStudyInFather(piece, geom, name) - self.subm = mesh.mesh.GetSubMesh(geom, hypo) - - self.algo = smesh.CreateHypothesis(hypo, so) - SetName(self.algo, name + "/" + hypo) - status = mesh.mesh.AddHypothesis(self.geom, self.algo) - self.TreatHypoStatus( status, hypo, name, 1 ) - - ## Private method - def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"): - hypo = smesh.CreateHypothesis(hyp, so) - a = "" - s = "=" - i = 0 - n = len(args) - while i 0 : - return 3 - elif geompy.NumberOfFaces( self.geom ) > 0 : - return 2 - elif geompy.NumberOfEdges( self.geom ) > 0 : - return 1 - else: - return 0; - pass - - ## Creates a segment discretization 1D algorithm. - # If the optional \a algo parameter is not sets, this algorithm is REGULAR. - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm define a submesh based on \a geom subshape. - # @param algo values are smesh.REGULAR or smesh.PYTHON for discretization via python function - # @param geom If defined, subshape to be meshed - def Segment(self, algo=REGULAR, geom=0): - ## if Segment(geom) is called by mistake - if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)): - algo, geom = geom, algo - pass - if algo == REGULAR: - return Mesh_Segment(self, geom) - elif algo == PYTHON: - return Mesh_Segment_Python(self, geom) - else: - return Mesh_Segment(self, geom) - - ## Creates a triangle 2D algorithm for faces. - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm define a submesh based on \a geom subshape. - # @param geom If defined, subshape to be meshed - def Triangle(self, geom=0): - return Mesh_Triangle(self, geom) - - ## Creates a quadrangle 2D algorithm for faces. - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm define a submesh based on \a geom subshape. - # @param geom If defined, subshape to be meshed - def Quadrangle(self, geom=0): - return Mesh_Quadrangle(self, geom) - - ## Creates a tetrahedron 3D algorithm for solids. - # The parameter \a algo permits to choice the algorithm: NETGEN or GHS3D - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm define a submesh based on \a geom subshape. - # @param algo values are: smesh.NETGEN, smesh.GHS3D - # @param geom If defined, subshape to be meshed - def Tetrahedron(self, algo, geom=0): - ## if Tetrahedron(geom) is called by mistake - if ( isinstance( algo, geompy.GEOM._objref_GEOM_Object)): - algo, geom = geom, algo - pass - return Mesh_Tetrahedron(self, algo, geom) - - ## Creates a hexahedron 3D algorithm for solids. - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm define a submesh based on \a geom subshape. - # @param geom If defined, subshape to be meshed - def Hexahedron(self, geom=0): - return Mesh_Hexahedron(self, geom) - - ## Creates a NETGEN-based 2D or 3D independent algorithm (i.e. needs no - # discrete boundary). - # If the optional \a geom parameter is not sets, this algorithm is global. - # Otherwise, this algorithm defines a submesh based on \a geom subshape. - # @param is3D If 0 then algorithm is 2D, otherwise 3D - # @param geom If defined, subshape to be meshed - def Netgen(self, is3D, geom=0): - return Mesh_Netgen(self, is3D, geom) - - ## Compute the mesh and return the status of the computation - def Compute(self): - ok = smesh.Compute(self.mesh, self.geom) - if not ok: - errors = smesh.GetAlgoState( self.mesh, self.geom ) - allReasons = "" - for err in errors: - if err.isGlobalAlgo: - glob = " global " - else: - glob = " local " - pass - dim = str(err.algoDim) - if err.name == SMESH.MISSING_ALGO: - reason = glob + dim + "D algorithm is missing" - elif err.name == SMESH.MISSING_HYPO: - name = '"' + err.algoName + '"' - reason = glob + dim + "D algorithm " + name + " misses " + dim + "D hypothesis" - else: - reason = "Global \"Not Conform mesh allowed\" hypothesis is missing" - pass - if allReasons != "": - allReasons += "\n" - pass - allReasons += reason - pass - if allReasons != "": - print '"' + GetName(self.mesh) + '"',"not computed:" - print allReasons - pass - pass - if salome.sg.hasDesktop(): - smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(salome.myStudyId) - smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok ) - salome.sg.updateObjBrowser(1) - pass - return ok - - ## Compute tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN - # The parameter \a fineness [0.-1.] defines mesh fineness - def AutomaticTetrahedralization(self, fineness=0): - dim = self.MeshDimension() - # assign hypotheses - self.RemoveGlobalHypotheses() - self.Segment().AutomaticLength(fineness) - if dim > 1 : - self.Triangle().LengthFromEdges() - pass - if dim > 2 : - self.Tetrahedron(NETGEN) - pass - return self.Compute() - - ## Compute hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron - # The parameter \a fineness [0.-1.] defines mesh fineness - def AutomaticHexahedralization(self, fineness=0): - dim = self.MeshDimension() - # assign hypotheses - self.RemoveGlobalHypotheses() - self.Segment().AutomaticLength(fineness) - if dim > 1 : - self.Quadrangle() - pass - if dim > 2 : - self.Hexahedron() - pass - return self.Compute() - - ## Removes all global hypotheses - def RemoveGlobalHypotheses(self): - current_hyps = self.mesh.GetHypothesisList( self.geom ) - for hyp in current_hyps: - self.mesh.RemoveHypothesis( self.geom, hyp ) - pass - pass - - ## Create a mesh group based on geometric object \a grp - # and give a \a name, if this parameter is not defined - # the name is the same as the geometric group name - # @param grp is a geometric group, a vertex, an edge, a face or a solid - # @param name is the name of the mesh group - def Group(self, grp, name=""): - if name == "": - name = grp.GetName() - - type = [] - tgeo = str(grp.GetShapeType()) - if tgeo == "VERTEX": - type = SMESH.NODE - elif tgeo == "EDGE": - type = SMESH.EDGE - elif tgeo == "FACE": - type = SMESH.FACE - elif tgeo == "SOLID": - type = SMESH.VOLUME - elif tgeo == "SHELL": - type = SMESH.VOLUME - elif tgeo == "COMPOUND": - if len( geompy.GetObjectIDs( grp )) == 0: - print "Mesh.Group: empty geometric group", GetName( grp ) - return 0 - tgeo = geompy.GetType(grp) - if tgeo == geompy.ShapeType["VERTEX"]: - type = SMESH.NODE - elif tgeo == geompy.ShapeType["EDGE"]: - type = SMESH.EDGE - elif tgeo == geompy.ShapeType["FACE"]: - type = SMESH.FACE - elif tgeo == geompy.ShapeType["SOLID"]: - type = SMESH.VOLUME - - if type == []: - print "Mesh.Group: bad first argument: expected a group, a vertex, an edge, a face or a solid" - return 0 - else: - return self.mesh.CreateGroupFromGEOM(type, name, grp) - - ## Export the mesh in a file with the MED format and choice the \a version of MED format - # @param f is the file name - # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2 - def ExportToMED(self, f, version, opt=0): - self.mesh.ExportToMED(f, opt, version) - - ## Export the mesh in a file with the MED format - # @param f is the file name - def ExportMED(self, f, opt=0): - self.mesh.ExportMED(f, opt) - - ## Export the mesh in a file with the DAT format - # @param f is the file name - def ExportDAT(self, f): - self.mesh.ExportDAT(f) +smesh.init_smesh(salome.myStudy,geompy.geom) - ## Export the mesh in a file with the UNV format - # @param f is the file name - def ExportUNV(self, f): - self.mesh.ExportUNV(f) +# Export the methods of smeshD +for k in dir(smesh): + if k[0] == '_':continue + globals()[k]=getattr(smesh,k) +del k - ## Export the mesh in a file with the STL format - # @param f is the file name - # @param ascii defined the kind of file contents - def ExportSTL(self, f, ascii=1): - self.mesh.ExportSTL(f, ascii)