X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_SWIG%2FsmeshDC.py;h=c13932a4f911fadddc8aba4d572b61698ea32726;hb=2d50f1341e527455310e1eea4e861bb93053d55d;hp=eb1f505730d0266d52b35b0f50034319b5d8629c;hpb=e30e3628ce1c7687b6e462e793c9e402684811e1;p=modules%2Fsmesh.git diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index eb1f50573..c13932a4f 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -1,4 +1,3 @@ -# -*- coding: iso-8859-1 -*- # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE # # This library is free software; you can redistribute it and/or @@ -569,7 +568,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): # @return SMESH.AxisStruct # @ingroup l1_auxiliary def GetAxisStruct(self,theObj): - edges = self.geompyD.ExtractShapes( theObj, geompyDC.ShapeType["EDGE"] ) + edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] ) if len(edges) > 1: vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] ) vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] ) @@ -787,6 +786,10 @@ class smeshDC(SMESH._objref_SMESH_Gen): else: print "Error: The treshold should be a shape." return None + if isinstance(UnaryOp,float): + aCriterion.Tolerance = UnaryOp + UnaryOp = FT_Undefined + pass elif CritType == FT_RangeOfIds: # Checks the treshold if isinstance(aTreshold, str): @@ -880,7 +883,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): aCriteria = [] aCriteria.append(aCriterion) aFilter.SetCriteria(aCriteria) - aFilterMgr.Destroy() + aFilterMgr.UnRegister() return aFilter ## Creates a numerical functor by its type @@ -1005,7 +1008,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): pass aMeasurements = self.CreateMeasurements() result = aMeasurements.MinDistance(src1, src2) - aMeasurements.Destroy() + aMeasurements.UnRegister() return result ## Get bounding box of the specified object(s) @@ -1042,7 +1045,7 @@ class smeshDC(SMESH._objref_SMESH_Gen): pass aMeasurements = self.CreateMeasurements() result = aMeasurements.BoundingBox(srclist) - aMeasurements.Destroy() + aMeasurements.UnRegister() return result import omniORB @@ -1081,7 +1084,16 @@ class Mesh: if obj != 0: if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object): self.geom = obj + # publish geom of mesh (issue 0021122) + if not self.geom.GetStudyEntry(): + studyID = smeshpyD.GetCurrentStudy()._get_StudyId() + if studyID != geompyD.myStudyId: + geompyD.init_geom( smeshpyD.GetCurrentStudy()) + pass + geo_name = "%s_%s"%(self.geom.GetShapeType(), id(self.geom)%100) + geompyD.addToStudy( self.geom, geo_name ) self.mesh = self.smeshpyD.CreateMesh(self.geom) + elif isinstance(obj, SMESH._objref_SMESH_Mesh): self.SetMesh(obj) else: @@ -1352,8 +1364,8 @@ class Mesh: shape = geom if shape==0: shape = self.geom - nbSolids = len( self.geompyD.ExtractShapes( shape, geompyDC.ShapeType["SOLID"] )) - nbShells = len( self.geompyD.ExtractShapes( shape, geompyDC.ShapeType["SHELL"] )) + nbSolids = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SOLID"] )) + nbShells = len( self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHELL"] )) if nbSolids == 0 or nbSolids == nbShells: return Mesh_Prism3D(self, geom) return Mesh_RadialPrism3D(self, geom) @@ -1794,7 +1806,7 @@ class Mesh: aCriteria.append(Criterion) aFilter.SetCriteria(aCriteria) group = self.MakeGroupByFilter(groupName, aFilter) - aFilterMgr.Destroy() + aFilterMgr.UnRegister() return group ## Creates a mesh group by the given criteria (list of criteria) @@ -1807,7 +1819,7 @@ class Mesh: aFilter = aFilterMgr.CreateFilter() aFilter.SetCriteria(theCriteria) group = self.MakeGroupByFilter(groupName, aFilter) - aFilterMgr.Destroy() + aFilterMgr.UnRegister() return group ## Creates a mesh group by the given filter @@ -1838,7 +1850,7 @@ class Mesh: aPredicate = aFilterMgr.CreateFreeEdges() aPredicate.SetMesh(self.mesh) aBorders = aPredicate.GetBorders() - aFilterMgr.Destroy() + aFilterMgr.UnRegister() return aBorders ## Removes a group @@ -1921,10 +1933,10 @@ class Mesh: def CutListOfGroups(self, main_groups, tool_groups, name): return self.mesh.CutListOfGroups(main_groups, tool_groups, name) - ## Produces a group of elements with specified element type using list of existing groups + ## Produces a group of elements of specified type using list of existing groups # A new group is created. System - # 1) extract all nodes on which groups elements are built - # 2) combine all elements of specified dimension laying on these nodes + # 1) extracts all nodes on which groups elements are built + # 2) combines all elements of specified dimension laying on these nodes # @return an instance of SMESH_Group # @ingroup l2_grps_operon def CreateDimGroup(self, groups, elem_type, name): @@ -2402,7 +2414,7 @@ class Mesh: aMeasurements = self.smeshpyD.CreateMeasurements() aMeasure = aMeasurements.MinDistance(id1, id2) - aMeasurements.Destroy() + aMeasurements.UnRegister() return aMeasure ## Get bounding box of the specified object(s) @@ -2451,7 +2463,7 @@ class Mesh: pass aMeasurements = self.smeshpyD.CreateMeasurements() aMeasure = aMeasurements.BoundingBox(srclist) - aMeasurements.Destroy() + aMeasurements.UnRegister() return aMeasure # Mesh edition (SMESH_MeshEditor functionality): @@ -3046,19 +3058,26 @@ class Mesh: ## Converts the mesh to quadratic, deletes old elements, replacing # them with quadratic with the same id. # @param theForce3d new node creation method: - # 0 - the medium node lies at the geometrical edge from which the mesh element is built + # 0 - the medium node lies at the geometrical entity from which the mesh element is built # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element + # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal # @ingroup l2_modif_tofromqu - def ConvertToQuadratic(self, theForce3d): - self.editor.ConvertToQuadratic(theForce3d) + def ConvertToQuadratic(self, theForce3d, theSubMesh=None): + if theSubMesh: + self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh) + else: + self.editor.ConvertToQuadratic(theForce3d) ## Converts the mesh from quadratic to ordinary, # deletes old quadratic elements, \n replacing # them with ordinary mesh elements with the same id. - # @return TRUE in case of success, FALSE otherwise. + # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal # @ingroup l2_modif_tofromqu - def ConvertFromQuadratic(self): - return self.editor.ConvertFromQuadratic() + def ConvertFromQuadratic(self, theSubMesh=None): + if theSubMesh: + self.editor.ConvertFromQuadraticObject(theSubMesh) + else: + return self.editor.ConvertFromQuadratic() ## Creates 2D mesh as skin on boundary faces of a 3D mesh # @return TRUE if operation has been completed successfully, FALSE otherwise @@ -3069,15 +3088,18 @@ class Mesh: ## Creates missing boundary elements # @param elements - elements whose boundary is to be checked: # mesh, group, sub-mesh or list of elements + # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called # @param dimension - defines type of boundary elements to create: # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D + # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells # @param groupName - a name of group to store created boundary elements in, # "" means not to create the group # @param meshName - a name of new mesh to store created boundary elements in, # "" means not to create the new mesh - # @param toCopyElements - if true, the checked elements will be copied into the new mesh + # @param toCopyElements - if true, the checked elements will be copied into + # the new mesh else only boundary elements will be copied into the new mesh # @param toCopyExistingBondary - if true, not only new but also pre-existing - # boundary elements will be copied into the new mesh + # boundary elements will be copied into the new mesh # @return tuple (mesh, group) where bondary elements were added to # @ingroup l2_modif_edit def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="", @@ -3093,6 +3115,29 @@ class Mesh: if mesh: mesh = self.smeshpyD.Mesh(mesh) return mesh, group + ## + # @brief Creates missing boundary elements around either the whole mesh or + # groups of 2D elements + # @param dimension - defines type of boundary elements to create + # @param groupName - a name of group to store all boundary elements in, + # "" means not to create the group + # @param meshName - a name of a new mesh, which is a copy of the initial + # mesh + created boundary elements; "" means not to create the new mesh + # @param toCopyAll - if true, the whole initial mesh will be copied into + # the new mesh else only boundary elements will be copied into the new mesh + # @param groups - groups of 2D elements to make boundary around + # @retval tuple( long, mesh, groups ) + # long - number of added boundary elements + # mesh - the mesh where elements were added to + # group - the group of boundary elements or None + # + def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="", + toCopyAll=False, groups=[]): + nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName, + toCopyAll,groups) + if mesh: mesh = self.smeshpyD.Mesh(mesh) + return nb, mesh, group + ## Renumber mesh nodes # @ingroup l2_modif_renumber def RenumberNodes(self): @@ -3248,7 +3293,7 @@ class Mesh: ## Generates new elements by extrusion of the elements with given ids # @param IDsOfElements the list of elements ids for extrusion - # @param StepVector vector or DirStruct, defining the direction and value of extrusion + # @param StepVector vector or DirStruct, 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 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise @@ -3291,7 +3336,7 @@ class Mesh: ## Generates new elements by extrusion of the elements which belong to the object # @param theObject the object which elements should be processed. # It can be a mesh, a sub mesh or a group. - # @param StepVector vector, defining the direction and value of extrusion + # @param StepVector vector, 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 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise @@ -3313,7 +3358,7 @@ class Mesh: ## Generates new elements by extrusion of the elements which belong to the object # @param theObject object which elements should be processed. # It can be a mesh, a sub mesh or a group. - # @param StepVector vector, defining the direction and value of extrusion + # @param StepVector vector, 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 to generate new groups from existing ones # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise @@ -3335,7 +3380,7 @@ class Mesh: ## Generates new elements by extrusion of the elements which belong to the object # @param theObject object which elements should be processed. # It can be a mesh, a sub mesh or a group. - # @param StepVector vector, defining the direction and value of extrusion + # @param StepVector vector, 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 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise @@ -4123,6 +4168,16 @@ class Mesh: def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ): return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems ) + ## Double nodes on some external faces and create flat elements. + # Flat elements are mainly used by some types of mechanic calculations. + # + # Each group of the list must be constituted of faces. + # Triangles are transformed in prisms, and quadrangles in hexahedrons. + # @param theGroupsOfFaces - list of groups of faces + # @return TRUE if operation has been completed successfully, FALSE otherwise + def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ): + return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces ) + def _valueFromFunctor(self, funcType, elemId): fn = self.smeshpyD.GetFunctor(funcType) fn.SetMesh(self.mesh) @@ -4354,12 +4409,20 @@ class Mesh_Algorithm: name = GetName(geom) pass except: + pass + if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND: + # for all groups SubShapeName() returns "Compound_-1" name = mesh.geompyD.SubShapeName(geom, piece) - if not name: - name = "%s_%s"%(geom.GetShapeType(), id(geom%1000)) + if not name: + name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000) + # publish geom of sub-mesh (issue 0021122) + if not self.geom.IsSame( self.mesh.geom ) and not self.geom.GetStudyEntry(): + studyID = self.mesh.smeshpyD.GetCurrentStudy()._get_StudyId() + if studyID != self.mesh.geompyD.myStudyId: + self.mesh.geompyD.init_geom( self.mesh.smeshpyD.GetCurrentStudy()) + self.mesh.geompyD.addToStudyInFather( self.mesh.geom, self.geom, name ) 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 ) @@ -5260,7 +5323,7 @@ class Mesh_Tetrahedron(Mesh_Algorithm): self.params = self.Hypothesis("NETGEN_Parameters", [], "libNETGENEngine.so", UseExisting=0) - if self.algoType == NETGEN: + elif self.algoType == NETGEN: self.params = self.Hypothesis("NETGEN_Parameters_3D", [], "libNETGENEngine.so", UseExisting=0) @@ -5272,7 +5335,7 @@ class Mesh_Tetrahedron(Mesh_Algorithm): self.params = self.Hypothesis("GHS3DPRL_Parameters", [], "libGHS3DPRLEngine.so", UseExisting=0) else: - print "Algo supports no multi-parameter hypothesis" + print "Warning: %s supports no multi-parameter hypothesis"%self.algo.GetName() return self.params