X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FTools%2FblocFissure%2Fgmu%2FpartitionBlocDefaut.py;h=6c59c713ab2ae3cef85fb84e6948676d36fbdc12;hb=95de5fabdc238bcf1dbc3399e79d3b5c5ff41a5e;hp=4016c9a5bee28044b386f1522eb92d66203b3501;hpb=5d68554076bbca0e1e95fb0db215a6c2b84b6c54;p=modules%2Fsmesh.git diff --git a/src/Tools/blocFissure/gmu/partitionBlocDefaut.py b/src/Tools/blocFissure/gmu/partitionBlocDefaut.py index 4016c9a5b..6c59c713a 100644 --- a/src/Tools/blocFissure/gmu/partitionBlocDefaut.py +++ b/src/Tools/blocFissure/gmu/partitionBlocDefaut.py @@ -1,10 +1,33 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2014-2021 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +"""Partition du bloc defaut par generatrice, tore et plan fissure""" import logging -from geomsmesh import geompy -# ----------------------------------------------------------------------------- -# --- partition du bloc defaut par generatrice, tore et plan fissure +import GEOM + +from .geomsmesh import geompy +from .geomsmesh import geomPublish +from .geomsmesh import geomPublishInFather + +from . import initLog def partitionBlocDefaut(volDefaut, facesDefaut, gener, pipe, facefis, ellipsoide): @@ -29,15 +52,15 @@ def partitionBlocDefaut(volDefaut, facesDefaut, gener, pipe, faceFissure = geompy.GetInPlaceByHistory(volDefautPart, facefis) #ellipsoidep =geompy.GetInPlaceByHistory(volDefautPart, ellipsoide) - geompy.addToStudy( volDefautPart, 'volDefautPart' ) - geompy.addToStudyInFather( volDefautPart, tore, 'tore' ) - geompy.addToStudyInFather( volDefautPart, faceFissure, 'FACE1' ) - #geompy.addToStudyInFather( volDefautPart, gencnt, 'generatrice' ) + geomPublish(initLog.debug, volDefautPart, 'volDefautPart' ) + geomPublishInFather(initLog.debug, volDefautPart, tore, 'tore' ) + geomPublishInFather(initLog.debug, volDefautPart, faceFissure, 'FACE1' ) + #geomPublishInFather(initLog.debug, volDefautPart, gencnt, 'generatrice' ) solids = geompy.ExtractShapes(blocp, geompy.ShapeType["SOLID"], True) - vols = [] - for i in range(len(solids)): - props = geompy.BasicProperties(solids[i]) + vols = list() + for solid in solids: + props = geompy.BasicProperties(solid) vols.append(props[2]) maxvol = max(vols) imaxvol = vols.index(maxvol) @@ -47,114 +70,115 @@ def partitionBlocDefaut(volDefaut, facesDefaut, gener, pipe, imaxvol = vols.index(maxvol) ellipsoidep = solids[imaxvol] - geompy.addToStudyInFather( volDefautPart, blocp, 'bloc' ) - geompy.addToStudyInFather( volDefautPart, ellipsoidep, 'ellipsoide' ) + geomPublishInFather(initLog.debug, volDefautPart, blocp, 'bloc' ) + geomPublishInFather(initLog.debug, volDefautPart, ellipsoidep, 'ellipsoide' ) sharedFaces = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["FACE"]) - for i in range(len(sharedFaces)): - name = "faceCommuneEllipsoideBloc_%d"%i - geompy.addToStudyInFather(blocp, sharedFaces[i], name) + for i_aux, face in enumerate(sharedFaces): + name = "faceCommuneEllipsoideBloc_{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp, face, name) #sharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"]) allSharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"]) - sharedEdges = [] - for i in range(len(allSharedEdges)): - if geompy.NbShapes(allSharedEdges[i], geompy.ShapeType["VERTEX"]) > 1: # edge non degeneree - sharedEdges.append(allSharedEdges[i]) - for i in range(len(sharedEdges)): - name = "edgeCommuneEllipsoideBloc_%d"%i - geompy.addToStudyInFather(blocp, sharedEdges[i], name) - - facesExternes = [] - facesExtBloc = [] - facesExtElli = [] + sharedEdges = list() + for face in allSharedEdges: + if geompy.NbShapes(face, geompy.ShapeType["VERTEX"]) > 1: # edge non degeneree + sharedEdges.append(face) + for i_aux, edge in enumerate(sharedEdges): + name = "edgeCommuneEllipsoideBloc_{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp, edge, name) + + facesExternes = list() + facesExtBloc = list() + facesExtElli = list() faces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True) - if len(faces) == 0: + if not faces: faces = [facesDefaut] - for i in range(len(faces)): - faceExt = geompy.GetInPlace(ellipsoidep, faces[i]) + for i_aux, face in enumerate(faces): + faceExt = geompy.GetInPlace(ellipsoidep, face) if faceExt is not None: - name = "faceExterne_e%d"%i - geompy.addToStudyInFather(ellipsoidep, faceExt, name) + name = "faceExterne_e{}".format(i_aux) + geomPublishInFather(initLog.debug,ellipsoidep, faceExt, name) facesExternes.append(faceExt) facesExtElli.append(faceExt) - faceExt = geompy.GetInPlace(blocp, faces[i]) + faceExt = geompy.GetInPlace(blocp, face) if faceExt is not None: - name = "faceExterne_b%d"%i - geompy.addToStudyInFather(blocp, faceExt, name) + name = "faceExterne_b{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp, faceExt, name) facesExternes.append(faceExt) facesExtBloc.append(faceExt) else: logging.info(" recherche faces externes par GetShapesOnShape") - vertex = geompy.MakeVertexOnSurface(faces[i], 0.5, 0.5) - normal = geompy.GetNormal(faces[i], vertex) - extrusionFace = geompy.MakePrismVecH(faces[i], normal, 1) - #extrusionFace = geompy.MakePrismVecH2Ways(faces[i], normal, 0.1) + vertex = geompy.MakeVertexOnSurface(face, 0.5, 0.5) + normal = geompy.GetNormal(face, vertex) + extrusionFace = geompy.MakePrismVecH(face, normal, 1) + #extrusionFace = geompy.MakePrismVecH2Ways(face, normal, 0.1) #extrusionFace = geompy.MakeScaleTransform(extrusionFace, vertex, 1.01) - name = "extrusionFace_b%d"%i - geompy.addToStudyInFather(blocp, extrusionFace, name) + name = "extrusionFace_b{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp, extrusionFace, name) #facesExt = geompy.GetShapesOnShape(extrusionFace, blocp, geompy.ShapeType["FACE"], GEOM.ST_ONIN) facesExt = geompy.GetShapesOnShape(extrusionFace, blocp, geompy.ShapeType["FACE"], GEOM.ST_ON) - for j in range(len(facesExt)): - name = "faceExterne_b%d_%d"%(i,j) - geompy.addToStudyInFather(blocp, facesExt[j], name) - facesExternes.append(facesExt[j]) - facesExtBloc.append(facesExt[j]) + for j_aux, face_ext in enumerate(facesExt): + name = "faceExterne_b{}_{}".format(i_aux,j_aux) + geomPublishInFather(initLog.debug,blocp, face_ext, name) + facesExternes.append(face_ext) + facesExtBloc.append(face_ext) if len(facesExtBloc) < len(faces): # toutes les faces externes du bloc n'ont pas été trouvées. TODO eliminer les detections multiples logging.info(" recherche faces externes par aretes partagees avec faces externes ellipsoide") facesBloc = geompy.ExtractShapes(blocp, geompy.ShapeType["FACE"], True) - for i in range(len(facesBloc)): + for i_aux, face in enumerate(facesBloc): notOnEllipsoide = True - for j in range(len(sharedFaces)): # eliminer les faces communes avec l'ellipsoide - if facesBloc[i].IsSame(sharedFaces[j]): + for j_aux, sharedface in enumerate(sharedFaces): # eliminer les faces communes avec l'ellipsoide + if face.IsSame(sharedface): notOnEllipsoide = False break if notOnEllipsoide: - for j in range(len(facesExtElli)): # les faces recherchees ont une ou plusieurs edge communes avec la ou les faces externes de l'ellipsoide - allSharedEdges = [] + for j_aux, face_ext_elli in enumerate(facesExtElli): # les faces recherchees ont une ou plusieurs edge communes avec la ou les faces externes de l'ellipsoide + allSharedEdges = list() try: - allSharedEdges += geompy.GetSharedShapesMulti([facesBloc[i], facesExtElli[j]], geompy.ShapeType["EDGE"]) + allSharedEdges += geompy.GetSharedShapesMulti([face, face_ext_elli], geompy.ShapeType["EDGE"]) except: pass - if len(allSharedEdges) > 0: - name = "faceExterne_b%d_%d"%(i,j) - geompy.addToStudyInFather(blocp, facesBloc[i], name) - facesExternes.append(facesBloc[i]) - facesExtBloc.append(facesBloc[i]) - - aretesInternes = [] - for i in range(len(facesExternes)): - for j in range(i+1,len(facesExternes)): - shared = [] + if allSharedEdges: + name = "faceExterne_b{}_{}".format(i_aux,j_aux) + geomPublishInFather(initLog.debug,blocp, face, name) + facesExternes.append(face) + facesExtBloc.append(face) + + aretesInternes = list() + for i_aux, face_ext_i in enumerate(facesExternes): + for j_aux, face_ext_j in enumerate(facesExternes[i_aux+1:]): + shared = list() try: - shared += geompy.GetSharedShapesMulti([facesExternes[i], facesExternes[j]], geompy.ShapeType["EDGE"]) + shared += geompy.GetSharedShapesMulti([face_ext_i, face_ext_j], geompy.ShapeType["EDGE"]) except: - logging.info("no shared edges in %s,%s",i,j) + texte = "no shared edges in {},{}".format(i_aux,j_aux) + logging.info(texte) else: aretesInternes += shared - for i in range(len(aretesInternes)): - name = "aretesInternes_%d"%i - geompy.addToStudyInFather(blocp, aretesInternes[i], name) + for i_aux, edge in enumerate(aretesInternes): + name = "aretesInternes_{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp, edge, name) - edgesBords = [] + l_edgesBords = list() for faceExtB in facesExtBloc: edges = geompy.ExtractShapes(faceExtB, geompy.ShapeType["EDGE"], True) - for i in range(len(edges)): + for i_aux, edge in enumerate(edges): isInterne = False - for j in range(len(aretesInternes)): - if edges[i].IsSame(aretesInternes[j]): + for arete in aretesInternes: + if edge.IsSame(arete): isInterne = True break if not isInterne: - edgesBords.append(edges[i]) - name = "edgeBord%d"%i - geompy.addToStudyInFather(blocp,edges[i] , name) - group = None - if len(edgesBords) > 0: - group = geompy.CreateGroup(blocp, geompy.ShapeType["EDGE"]) - geompy.UnionList(group, edgesBords) - edgesBords = group + l_edgesBords.append(edge) + name = "edgeBord{}".format(i_aux) + geomPublishInFather(initLog.debug,blocp,edge , name) + if l_edgesBords: + edgesBords = geompy.CreateGroup(blocp, geompy.ShapeType["EDGE"]) + geompy.UnionList(edgesBords, l_edgesBords) + else: + edgesBords = None return volDefautPart, blocp, tore, faceFissure, facesExternes, facesExtBloc, facesExtElli, aretesInternes, ellipsoidep, sharedFaces, sharedEdges, edgesBords