X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshBuilder.py;h=9a7b7611bfe17201619e1c9793822d2acfabc382;hp=6e39264b1a79aa8ea6eae2288d84950d09c69212;hb=831b40eb011a5f2ad1738518e86fdc6d924f891d;hpb=a1a6d5ddc111fa237d1164fda37ff823a3fac764 diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 6e39264b1..9a7b7611b 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -512,20 +512,17 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): ## Sets the current mode # @ingroup l1_auxiliary def SetEmbeddedMode( self,theMode ): - #self.SetEmbeddedMode(theMode) SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode) ## Gets the current mode # @ingroup l1_auxiliary def IsEmbeddedMode(self): - #return self.IsEmbeddedMode() return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self) ## Sets the current study. Calling SetCurrentStudy( None ) allows to # switch OFF automatic pubilishing in the Study of mesh objects. # @ingroup l1_auxiliary def SetCurrentStudy( self, theStudy, geompyD = None ): - #self.SetCurrentStudy(theStudy) if not geompyD: from salome.geom import geomBuilder geompyD = geomBuilder.geom @@ -548,7 +545,6 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): ## Gets the current study # @ingroup l1_auxiliary def GetCurrentStudy(self): - #return self.GetCurrentStudy() return SMESH._objref_SMESH_Gen.GetCurrentStudy(self) ## Creates a Mesh object importing data from the given UNV file @@ -964,6 +960,10 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen): functor = aFilterMgr.CreateLength() elif theCriterion == FT_Length2D: functor = aFilterMgr.CreateLength2D() + elif theCriterion == FT_NodeConnectivityNumber: + functor = aFilterMgr.CreateNodeConnectivityNumber() + elif theCriterion == FT_BallDiameter: + functor = aFilterMgr.CreateBallDiameter() else: print "Error: given parameter is not numerical functor type." aFilterMgr.UnRegister() @@ -1497,13 +1497,20 @@ class Mesh: print allReasons pass if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: - smeshgui = salome.ImportComponentGUI("SMESH") - smeshgui.Init(self.mesh.GetStudyId()) - smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) ) - if refresh: salome.sg.updateObjBrowser(1) - pass + if not isinstance( refresh, list): # not a call from subMesh.Compute() + smeshgui = salome.ImportComponentGUI("SMESH") + smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) ) + if refresh: salome.sg.updateObjBrowser(True) + return ok + ## Return a list of error messages (SMESH.ComputeError) of the last Compute() + def GetComputeErrors(self, shape=0 ): + if shape == 0: + shape = self.mesh.GetShapeToMesh() + return self.smeshpyD.GetComputeErrors( self.mesh, shape ) + ## Return a name of a sub-shape by its ID # @param subShapeID a unique ID of a sub-shape # @return a string describing the sub-shape; possible variants: @@ -1592,13 +1599,13 @@ class Mesh: return groups ## Return sub-mesh objects list in meshing order - # @return list of list of sub-meshes + # @return list of lists of sub-meshes # @ingroup l2_construct def GetMeshOrder(self): return self.mesh.GetMeshOrder() ## Set order in which concurrent sub-meshes sould be meshed - # @param submeshes list of sub-meshes + # @param submeshes list of lists of sub-meshes # @ingroup l2_construct def SetMeshOrder(self, submeshes): return self.mesh.SetMeshOrder(submeshes) @@ -1613,7 +1620,7 @@ class Mesh: smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(self.mesh.GetStudyId()) smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(1) + if refresh: salome.sg.updateObjBrowser(True) ## Removes all nodes and elements of indicated shape # @param refresh if @c True, Object browser is automatically updated (when running in GUI) @@ -1625,7 +1632,7 @@ class Mesh: smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(self.mesh.GetStudyId()) smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True ) - if refresh: salome.sg.updateObjBrowser(1) + if refresh: salome.sg.updateObjBrowser(True) ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron # @param fineness [0.0,1.0] defines mesh fineness @@ -2253,6 +2260,8 @@ class Mesh: # idSrc.UnRegister() # @ingroup l1_auxiliary def GetIDSource(self, ids, elemType = SMESH.ALL): + if isinstance( ids, int ): + ids = [ids] return self.editor.MakeIDSource(ids, elemType) @@ -2505,7 +2514,7 @@ class Mesh: return self.mesh.GetElementShape(id) ## Returns the list of submesh elements IDs - # @param Shape a geom object(sub-shape) IOR + # @param Shape a geom object(sub-shape) # Shape must be the sub-shape of a ShapeToMesh() # @return the list of integer values # @ingroup l1_meshinfo @@ -2517,7 +2526,7 @@ class Mesh: return self.mesh.GetSubMeshElementsId(ShapeID) ## Returns the list of submesh nodes IDs - # @param Shape a geom object(sub-shape) IOR + # @param Shape a geom object(sub-shape) # Shape must be the sub-shape of a ShapeToMesh() # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes # @return the list of integer values @@ -2530,7 +2539,7 @@ class Mesh: return self.mesh.GetSubMeshNodesId(ShapeID, all) ## Returns type of elements on given shape - # @param Shape a geom object(sub-shape) IOR + # @param Shape a geom object(sub-shape) # Shape must be a sub-shape of a ShapeToMesh() # @return element type # @ingroup l1_meshinfo @@ -2817,10 +2826,11 @@ class Mesh: ## Creates a 0D element on a node with given number. # @param IDOfNode the ID of node for creation of the element. + # @param DuplicateElements to add one more 0D element to a node or not # @return the Id of the new 0D element # @ingroup l2_modif_add - def Add0DElement(self, IDOfNode): - return self.editor.Add0DElement(IDOfNode) + def Add0DElement( self, IDOfNode, DuplicateElements=True ): + return self.editor.Add0DElement( IDOfNode, DuplicateElements ) ## Create 0D elements on all nodes of the given elements except those # nodes on which a 0D element already exists. @@ -2829,18 +2839,19 @@ class Mesh: # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE ) # @param theGroupName optional name of a group to add 0D elements created # and/or found on nodes of \a theObject. + # @param DuplicateElements to add one more 0D element to a node or not # @return an object (a new group or a temporary SMESH_IDSource) holding # IDs of new and/or found 0D elements. IDs of 0D elements # can be retrieved from the returned object by calling GetIDs() # @ingroup l2_modif_add - def Add0DElementsToAllNodes(self, theObject, theGroupName=""): + def Add0DElementsToAllNodes(self, theObject, theGroupName="", DuplicateElements=False): unRegister = genObjUnRegister() if isinstance( theObject, Mesh ): theObject = theObject.GetMesh() - if isinstance( theObject, list ): + elif isinstance( theObject, list ): theObject = self.GetIDSource( theObject, SMESH.ALL ) unRegister.set( theObject ) - return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName ) + return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName, DuplicateElements ) ## Creates a ball element on a node with given ID. # @param IDOfNode the ID of node for creation of the element. @@ -3595,6 +3606,7 @@ class Mesh: # 1 - the medium node lies at the middle of the line segments connecting two nodes of a mesh element # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal # @param theToBiQuad If True, converts the mesh to bi-quadratic + # @return SMESH.ComputeError which can hold a warning # @ingroup l2_modif_tofromqu def ConvertToQuadratic(self, theForce3d=False, theSubMesh=None, theToBiQuad=False): if isinstance( theSubMesh, Mesh ): @@ -3609,6 +3621,7 @@ class Mesh: error = self.editor.GetLastError() if error and error.comment: print error.comment + return error ## Converts the mesh from quadratic to ordinary, # deletes old quadratic elements, \n replacing @@ -3814,17 +3827,27 @@ class Mesh: NbOfSteps, Tolerance, MakeGroups, TotalAngle) ## Generates new elements by extrusion of the given elements and nodes - # @param nodes - nodes to extrude: a list including ids, groups, sub-meshes or a mesh - # @param edges - edges to extrude: a list including ids, groups, sub-meshes or a mesh - # @param faces - faces to extrude: a list including ids, groups, sub-meshes or a mesh + # @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh + # @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh + # @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh # @param StepVector vector or DirStruct or 3 vector components, defining # the direction and value of extrusion for one step (the total extrusion # length will be NbOfSteps * ||StepVector||) # @param NbOfSteps the number of steps # @param MakeGroups forces the generation of new groups from existing ones + # @param scaleFactors optional scale factors to apply during extrusion + # @param linearVariation if @c True, scaleFactors are spread over all @a scaleFactors, + # else scaleFactors[i] is applied to nodes at the i-th extrusion step + # @param basePoint optional scaling center; if not provided, a gravity center of + # nodes and elements being extruded is used as the scaling center. + # It can be either + # - a list of tree components of the point or + # - a node ID or + # - a GEOM point # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise # @ingroup l2_modif_extrurev - def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False): + def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False, + scaleFactors=[], linearVariation=False, basePoint=[] ): unRegister = genObjUnRegister() nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister ) edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister ) @@ -3835,12 +3858,22 @@ class Mesh: if isinstance( StepVector, list ): StepVector = self.smeshpyD.MakeDirStruct(*StepVector) + if isinstance( basePoint, int): + xyz = self.GetNodeXYZ( basePoint ) + if not xyz: + raise RuntimeError, "Invalid node ID: %s" % basePoint + basePoint = xyz + if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ): + basePoint = self.geompyD.PointCoordinates( basePoint ) + NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps) Parameters = StepVector.PS.parameters + var_separator + Parameters self.mesh.SetParameters(Parameters) return self.editor.ExtrusionSweepObjects( nodes, edges, faces, - StepVector, NbOfSteps, MakeGroups) + StepVector, NbOfSteps, + scaleFactors, linearVariation, basePoint, + MakeGroups) ## Generates new elements by extrusion of the elements with given ids @@ -4470,7 +4503,7 @@ class Mesh: ## Finds groups of ajacent nodes within Tolerance. # @param Tolerance the value of tolerance - # @param SubMeshOrGroup SubMesh or Group + # @param SubMeshOrGroup SubMesh, Group or Filter # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search # @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts # corner and medium nodes in separate groups thus preventing @@ -4975,7 +5008,7 @@ class Mesh: pass # end of Mesh class -## class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility +## Class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility # with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh # class meshProxy(SMESH._objref_SMESH_Mesh): @@ -4991,7 +5024,40 @@ class meshProxy(SMESH._objref_SMESH_Mesh): pass omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy) -## class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility + +## Class wrapping SMESH_SubMesh in order to add Compute() +# +class submeshProxy(SMESH._objref_SMESH_subMesh): + def __init__(self): + SMESH._objref_SMESH_subMesh.__init__(self) + self.mesh = None + def __deepcopy__(self, memo=None): + new = self.__class__() + return new + + ## Computes the sub-mesh and returns the status of the computation + # @param refresh if @c True, Object browser is automatically updated (when running in GUI) + # @return True or False + # @ingroup l2_construct + def Compute(self,refresh=False): + if not self.mesh: + self.mesh = Mesh( smeshBuilder(), None, self.GetMesh()) + + ok = self.mesh.Compute( self.GetSubShape(),refresh=[] ) + + if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0: + smeshgui = salome.ImportComponentGUI("SMESH") + smeshgui.Init(self.mesh.GetStudyId()) + smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) ) + if refresh: salome.sg.updateObjBrowser(True) + pass + + return ok + pass +omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy) + + +## Class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility # with old dump scripts which call SMESH_MeshEditor directly and not via smeshBuilder.Mesh # class meshEditor(SMESH._objref_SMESH_MeshEditor): @@ -5103,7 +5169,7 @@ class algoCreator: raise RuntimeError, "No class found for algo type %s" % algoType return None -# Private class used to substitute and store variable parameters of hypotheses. +## Private class used to substitute and store variable parameters of hypotheses. # class hypMethodWrapper: def __init__(self, hyp, method): @@ -5134,7 +5200,8 @@ class hypMethodWrapper: return result pass -# A helper class that call UnRegister() of SALOME.GenericObj'es stored in it +## A helper class that call UnRegister() of SALOME.GenericObj'es stored in it +# class genObjUnRegister: def __init__(self, genObj=None): @@ -5155,6 +5222,9 @@ class genObjUnRegister: if genObj and hasattr( genObj, "UnRegister" ): genObj.UnRegister() + +## Bind methods creating mesher plug-ins to the Mesh class +# for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ): # #print "pluginName: ", pluginName