X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshBuilder.py;h=2334321177669e32885a2b1b4334b88ece8a9dff;hb=1d429d8caf426206a25d847a599a654aa34fa718;hp=1b5f9ecfc739e314b7d9f64fb96640990e992d96;hpb=a1920ff31054e2c882bd94d4f3c04abe53980ce0;p=modules%2Fsmesh.git diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 1b5f9ecfc..233432117 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -189,13 +189,8 @@ def GetName(obj): except: ior = None if ior: - # CORBA object - studies = salome.myStudyManager.GetOpenStudies() - for sname in studies: - s = salome.myStudyManager.GetStudyByName(sname) - if not s: continue - sobj = s.FindObjectIOR(ior) - if not sobj: continue + sobj = salome.myStudy.FindObjectIOR(ior) + if sobj: return sobj.GetName() if hasattr(obj, "GetName"): # unknown CORBA object, having GetName() method @@ -266,12 +261,7 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh): def AssureGeomPublished(mesh, geom, name=''): if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ): return - if not geom.GetStudyEntry() and \ - mesh.smeshpyD.GetCurrentStudy(): - ## set the study - studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId() - if studyID != mesh.geompyD.myStudyId: - mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy()) + if not geom.GetStudyEntry(): ## get a name if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND: # for all groups SubShapeName() return "Compound_-1" @@ -380,8 +370,8 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): ## Dump component to the Python script # This method overrides IDL function to allow default values for the parameters. # @ingroup l1_auxiliary - def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True): - return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile) + def DumpPython(self, theIsPublished=True, theIsMultiFile=True): + return SMESH._objref_SMESH_Gen.DumpPython(self, theIsPublished, theIsMultiFile) ## Set mode of DumpPython(), \a historical or \a snapshot. # In the \a historical mode, the Python Dump script includes all commands @@ -394,14 +384,14 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): else: val = "false" SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val) - ## Set the current study and Geometry component + ## Set Geometry component # @ingroup l1_auxiliary - def init_smesh(self,theStudy,geompyD = None): + def init_smesh(self,isPublished = True,geompyD = None): #print "init_smesh" - self.SetCurrentStudy(theStudy,geompyD) - if theStudy: + self.UpdateStudy(geompyD) + if isPublished: global notebook - notebook.myStudy = theStudy + notebook.myStudy = salome.myStudy ## Create a mesh. This can be either an empty mesh, possibly having an underlying geometry, # or a mesh wrapping a CORBA mesh given as a parameter. @@ -523,34 +513,32 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): # @ingroup l1_auxiliary def IsEmbeddedMode(self): return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self) - - ## Set the current study. Calling SetCurrentStudy( None ) allows to - # switch OFF automatic pubilishing in the Study of mesh objects. + + ## Update the current study. Calling UpdateStudy() allows to + # update meshes at switching GEOM->SMESH # @ingroup l1_auxiliary - def SetCurrentStudy( self, theStudy, geompyD = None ): + def UpdateStudy( self, geompyD = None ): + #self.UpdateStudy() if not geompyD: from salome.geom import geomBuilder geompyD = geomBuilder.geom pass self.geompyD=geompyD self.SetGeomEngine(geompyD) - SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy) - global notebook - if theStudy: - notebook = salome_notebook.NoteBook( theStudy ) - else: - notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() ) - if theStudy: - sb = theStudy.NewBuilder() - sc = theStudy.FindComponent("SMESH") - if sc: sb.LoadWith(sc, self) - pass + SMESH._objref_SMESH_Gen.UpdateStudy(self) + sb = salome.myStudy.NewBuilder() + sc = salome.myStudy.FindComponent("SMESH") + if sc: sb.LoadWith(sc, self) pass - - ## Get the current study + + ## Sets enable publishing in the study. Calling SetEnablePublish( false ) allows to + # switch OFF publishing in the Study of mesh objects. # @ingroup l1_auxiliary - def GetCurrentStudy(self): - return SMESH._objref_SMESH_Gen.GetCurrentStudy(self) + def SetEnablePublish( self, theIsEnablePublish ): + #self.SetEnablePublish(theIsEnablePublish) + SMESH._objref_SMESH_Gen.SetEnablePublish(self,theIsEnablePublish) + global notebook + notebook = salome_notebook.NoteBook( theIsEnablePublish ) ## Create a Mesh object importing data from the given UNV file # @return an instance of Mesh class @@ -760,7 +748,7 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): raise ValueError, "Group type mismatches Element type" aCriterion.ThresholdStr = aThreshold.GetName() aCriterion.ThresholdID = salome.orb.object_to_string( aThreshold ) - study = self.GetCurrentStudy() + study = salome.myStudy if study: so = study.FindObjectIOR( aCriterion.ThresholdID ) if so: @@ -1167,13 +1155,13 @@ omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder) # import salome # salome.salome_init() # from salome.smesh import smeshBuilder -# smesh = smeshBuilder.New(salome.myStudy) +# smesh = smeshBuilder.New() # \endcode -# @param study SALOME study, generally obtained by salome.myStudy. +# @param isPublished If False, the notebool will not be used. # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used. # @return smeshBuilder instance -def New( study, instance=None): +def New( isPublished = True, instance=None): """ Create a new smeshBuilder instance.The smeshBuilder class provides the Python interface to create or load meshes. @@ -1182,10 +1170,10 @@ def New( study, instance=None): import salome salome.salome_init() from salome.smesh import smeshBuilder - smesh = smeshBuilder.New(salome.myStudy) + smesh = smeshBuilder.New() Parameters: - study SALOME study, generally obtained by salome.myStudy. + isPublished If False, the notebool will not be used. instance CORBA proxy of SMESH Engine. If None, the default Engine is used. Returns: smeshBuilder instance @@ -1198,7 +1186,7 @@ def New( study, instance=None): doLcc = True smeshInst = smeshBuilder() assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__ - smeshInst.init_smesh(study) + smeshInst.init_smesh(isPublished) return smeshInst @@ -1237,12 +1225,9 @@ class Mesh: self.geom = obj objHasName = True # publish geom of mesh (issue 0021122) - if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy(): + if not self.geom.GetStudyEntry(): objHasName = False - studyID = smeshpyD.GetCurrentStudy()._get_StudyId() - if studyID != geompyD.myStudyId: - geompyD.init_geom( smeshpyD.GetCurrentStudy()) - pass + geompyD.init_geom() if name: geo_name = name + " shape" else: @@ -1469,7 +1454,7 @@ class Mesh: errText = "code %s" % -err.code if errText: errText += ". " errText += err.comment - if allReasons != "":allReasons += "\n" + if allReasons: allReasons += "\n" if ok: allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText) else: @@ -1507,7 +1492,7 @@ class Mesh: reason = ("For unknown reason. " "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!") pass - if allReasons != "":allReasons += "\n" + if allReasons: allReasons += "\n" allReasons += "- " + reason pass if not ok or allReasons != "": @@ -1519,12 +1504,12 @@ class Mesh: print msg print allReasons pass - if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: + if salome.sg.hasDesktop(): if not isinstance( refresh, list): # not a call from subMesh.Compute() smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.Init() smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) ) - if refresh: salome.sg.updateObjBrowser(True) + if refresh: salome.sg.updateObjBrowser() return ok @@ -1549,11 +1534,9 @@ class Mesh: try: shapeText = "" mainIOR = salome.orb.object_to_string( self.GetShape() ) - for sname in salome.myStudyManager.GetOpenStudies(): - s = salome.myStudyManager.GetStudyByName(sname) - if not s: continue - mainSO = s.FindObjectIOR(mainIOR) - if not mainSO: continue + s = salome.myStudy + mainSO = s.FindObjectIOR(mainIOR) + if mainSO: if subShapeID == 1: shapeText = '"%s"' % mainSO.GetName() subIt = s.NewChildIterator(mainSO) @@ -1570,7 +1553,6 @@ class Mesh: continue if ids == subShapeID: shapeText = '"%s"' % subSO.GetName() - break if not shapeText: shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID]) if shape: @@ -1630,7 +1612,7 @@ class Mesh: def GetMeshOrder(self): return self.mesh.GetMeshOrder() - ## Set order in which concurrent sub-meshes sould be meshed + ## Set order in which concurrent sub-meshes should be meshed # @param submeshes list of lists of sub-meshes # @ingroup l2_construct def SetMeshOrder(self, submeshes): @@ -1641,12 +1623,11 @@ class Mesh: # @ingroup l2_construct def Clear(self, refresh=False): self.mesh.Clear() - if ( salome.sg.hasDesktop() and - salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ): + if ( salome.sg.hasDesktop() ): smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.Init() smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(True) + if refresh: salome.sg.updateObjBrowser() ## Remove all nodes and elements of indicated shape # @param refresh if @c True, Object browser is automatically updated (when running in GUI) @@ -1656,9 +1637,9 @@ class Mesh: self.mesh.ClearSubMesh(geomId) if salome.sg.hasDesktop(): smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.Init() smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(True) + if refresh: salome.sg.updateObjBrowser() ## Compute a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron # @param fineness [0.0,1.0] defines mesh fineness @@ -1787,27 +1768,29 @@ class Mesh: pass pass - ## Export the mesh in a file in MED format and chooses the \a version of MED format + ## Export the mesh in a file in 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 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ; - # the typical use is auto_groups=false. - # @param version MED format version(MED_V2_1 or MED_V2_2) + # the typical use is auto_groups=False. + # @param version MED format version (MED_V2_1 or MED_V2_2, + # the latter meaning any current version). The parameter is + # obsolete since MED_V2_1 is no longer supported. # @param overwrite boolean parameter for overwriting/not overwriting the file # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh - # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either + # @param autoDimension if @c True (default), a space dimension of a MED mesh can be either # - 1D if all mesh nodes lie on OX coordinate axis, or # - 2D if all mesh nodes lie on XOY coordinate plane, or - # - 3D in the rest cases. + # - 3D in the rest cases.
# If @a autoDimension is @c False, the space dimension is always 3. - # @param fields : list of GEOM fields defined on the shape to mesh. - # @param geomAssocFields : each character of this string means a need to export a + # @param fields list of GEOM fields defined on the shape to mesh. + # @param geomAssocFields each character of this string means a need to export a # corresponding field; correspondence between fields and characters is following: - # - 'v' stands for _vertices_ field; - # - 'e' stands for _edges_ field; - # - 'f' stands for _faces_ field; - # - 's' stands for _solids_ field. + # - 'v' stands for "_vertices _" field; + # - 'e' stands for "_edges _" field; + # - 'f' stands for "_faces _" field; + # - 's' stands for "_solids _" field. # @ingroup l2_impexp def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''): @@ -1906,22 +1889,23 @@ class Mesh: meshPart = self.mesh self.mesh.ExportGMF(meshPart, f, True) - ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead. - # Export 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 + ## Deprecated, used only for compatibility! Please, use ExportMED() method instead. + # Export the mesh in a file in 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 version MED format version (MED_V2_1 or MED_V2_2, + # the latter meaning any current version). The parameter is + # obsolete since MED_V2_1 is no longer supported. # @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 - # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either + # @param autoDimension if @c True (default), a space dimension of a MED mesh can be either # - 1D if all mesh nodes lie on OX coordinate axis, or # - 2D if all mesh nodes lie on XOY coordinate plane, or - # - 3D in the rest cases. - # + # - 3D in the rest cases.
# If @a autoDimension is @c False, the space dimension is always 3. # @ingroup l2_impexp - def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True): + def ExportToMED(self, f, version=MED_V2_2, opt=0, overwrite=1, autoDimension=True): self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension) # Operations with groups: @@ -2256,12 +2240,6 @@ class Mesh: def GetId(self): return self.mesh.GetId() - ## Get the study Id - # @return integer value, which is the study Id of the mesh - # @ingroup l1_auxiliary - def GetStudyId(self): - return self.mesh.GetStudyId() - ## Check the group names for duplications. # Consider the maximum group name length stored in MED file. # @return True or False @@ -2684,9 +2662,14 @@ class Mesh: ## Return an element based on all given nodes. # @ingroup l1_meshinfo - def FindElementByNodes(self,nodes): + def FindElementByNodes(self, nodes): return self.mesh.FindElementByNodes(nodes) + ## Return elements including all given nodes. + # @ingroup l1_meshinfo + def GetElementsByNodes(self, nodes, elemType=SMESH.ALL): + return self.mesh.GetElementsByNodes( nodes, elemType ) + ## Return true if the given element is a polygon # @ingroup l1_meshinfo def IsPoly(self, id): @@ -4563,10 +4546,12 @@ class Mesh: # @param NodesToKeep nodes to keep in the mesh: a list of groups, sub-meshes or node IDs. # If @a NodesToKeep does not include a node to keep for some group to merge, # then the first node in the group is kept. + # @param AvoidMakingHoles prevent merging nodes which cause removal of elements becoming + # invalid # @ingroup l2_modif_trsf - def MergeNodes (self, GroupsOfNodes, NodesToKeep=[]): + def MergeNodes (self, GroupsOfNodes, NodesToKeep=[], AvoidMakingHoles=False): # NodesToKeep are converted to SMESH_IDSource in meshEditor.MergeNodes() - self.editor.MergeNodes(GroupsOfNodes,NodesToKeep) + self.editor.MergeNodes( GroupsOfNodes, NodesToKeep, AvoidMakingHoles ) ## Find the elements built on the same nodes. # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching @@ -5084,11 +5069,11 @@ class submeshProxy(SMESH._objref_SMESH_subMesh): ok = self.mesh.Compute( self.GetSubShape(),refresh=[] ) - if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: + if salome.sg.hasDesktop(): smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.Init() smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) ) - if refresh: salome.sg.updateObjBrowser(True) + if refresh: salome.sg.updateObjBrowser() pass return ok @@ -5122,17 +5107,18 @@ class meshEditor(SMESH._objref_SMESH_MeshEditor): def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes) if len( args ) == 2: args += False, return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args ) - def MergeNodes(self,*args): # a 2nd arg added (NodesToKeep) + def MergeNodes(self,*args): # 2 args added (NodesToKeep,AvoidMakingHoles) if len( args ) == 1: - return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [] ) + return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [], False ) NodesToKeep = args[1] + AvoidMakingHoles = args[2] if len( args ) == 3 else False unRegister = genObjUnRegister() if NodesToKeep: if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ): NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE ) if not isinstance( NodesToKeep, list ): NodesToKeep = [ NodesToKeep ] - return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep ) + return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep, AvoidMakingHoles ) pass omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor) @@ -5171,10 +5157,11 @@ omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern) ## Private class used to bind methods creating algorithms to the class Mesh # class algoCreator: - def __init__(self): + def __init__(self, method): self.mesh = None self.defaultAlgoType = "" self.algoTypeToClass = {} + self.method = method # Store a python class of algorithm def add(self, algoClass): @@ -5188,25 +5175,48 @@ class algoCreator: # Create a copy of self and assign mesh to the copy def copy(self, mesh): - other = algoCreator() + other = algoCreator( self.method ) other.defaultAlgoType = self.defaultAlgoType - other.algoTypeToClass = self.algoTypeToClass + other.algoTypeToClass = self.algoTypeToClass other.mesh = mesh return other # Create an instance of algorithm def __call__(self,algo="",geom=0,*args): - algoType = self.defaultAlgoType - for arg in args + (algo,geom): - if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ): - geom = arg - if isinstance( arg, str ) and arg: + algoType = "" + shape = 0 + if isinstance( algo, str ): + algoType = algo + elif ( isinstance( algo, geomBuilder.GEOM._objref_GEOM_Object ) and \ + not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object )): + shape = algo + elif algo: + args += (algo,) + + if isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ): + shape = geom + elif not algoType and isinstance( geom, str ): + algoType = geom + elif geom: + args += (geom,) + for arg in args: + if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ) and not shape: + shape = arg + elif isinstance( arg, str ) and not algoType: algoType = arg + else: + import traceback, sys + msg = "Warning. Unexpected argument in mesh.%s() ---> %s" % ( self.method, arg ) + sys.stderr.write( msg + '\n' ) + tb = traceback.extract_stack(None,2) + traceback.print_list( [tb[0]] ) + if not algoType: + algoType = self.defaultAlgoType if not algoType and self.algoTypeToClass: algoType = self.algoTypeToClass.keys()[0] if self.algoTypeToClass.has_key( algoType ): #print "Create algo",algoType - return self.algoTypeToClass[ algoType ]( self.mesh, geom ) + return self.algoTypeToClass[ algoType ]( self.mesh, shape ) raise RuntimeError, "No class found for algo type %s" % algoType return None @@ -5288,7 +5298,7 @@ for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ): if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ): #print " meshMethod:" , str(algo.meshMethod) if not hasattr( Mesh, algo.meshMethod ): - setattr( Mesh, algo.meshMethod, algoCreator() ) + setattr( Mesh, algo.meshMethod, algoCreator( algo.meshMethod )) pass getattr( Mesh, algo.meshMethod ).add( algo ) pass