1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Partition du bloc defaut par generatrice, tore et plan fissure"""
26 from .geomsmesh import geompy
27 from .geomsmesh import geomPublish
28 from .geomsmesh import geomPublishInFather
32 def partitionBlocDefaut(volDefaut, facesDefaut, gener, pipe,
35 Partition du bloc defaut par la generatrice de l'ellipse,
36 le tore elliptique, la face plane de fissure
37 @param volDefaut : le bloc defaut
38 @param gener : la generatrice de l'ellipse, positionnée dans l'espace
39 @param pipe : le tore partitionné par le plan de fissure, positionné
41 @param facefis : la face plane de la fissure, positionnée dans l'espace
42 @return (volDefautPart, blocp, tore, faceFissure), le bloc partitionné,
43 les sous shapes issues de la partition
44 (le bloc moins le tore, la generatrice, le tore, la face de fissure)
48 volDefautPart = geompy.MakePartition([volDefaut], [pipe, facefis, ellipsoide], [], [], geompy.ShapeType["SOLID"], 0, [], 1)
49 blocp = geompy.GetInPlaceByHistory(volDefautPart, volDefaut)
50 #gencnt = geompy.GetInPlaceByHistory(volDefautPart, gener)
51 tore = geompy.GetInPlaceByHistory(volDefautPart, pipe)
52 faceFissure = geompy.GetInPlaceByHistory(volDefautPart, facefis)
53 #ellipsoidep =geompy.GetInPlaceByHistory(volDefautPart, ellipsoide)
55 geomPublish(initLog.debug, volDefautPart, 'volDefautPart' )
56 geomPublishInFather(initLog.debug, volDefautPart, tore, 'tore' )
57 geomPublishInFather(initLog.debug, volDefautPart, faceFissure, 'FACE1' )
58 #geomPublishInFather(initLog.debug, volDefautPart, gencnt, 'generatrice' )
60 solids = geompy.ExtractShapes(blocp, geompy.ShapeType["SOLID"], True)
63 props = geompy.BasicProperties(solid)
66 imaxvol = vols.index(maxvol)
67 blocp = solids[imaxvol]
70 imaxvol = vols.index(maxvol)
71 ellipsoidep = solids[imaxvol]
73 geomPublishInFather(initLog.debug, volDefautPart, blocp, 'bloc' )
74 geomPublishInFather(initLog.debug, volDefautPart, ellipsoidep, 'ellipsoide' )
76 sharedFaces = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["FACE"])
77 for i_aux, face in enumerate(sharedFaces):
78 name = "faceCommuneEllipsoideBloc_{}".format(i_aux)
79 geomPublishInFather(initLog.debug,blocp, face, name)
81 #sharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"])
82 allSharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"])
84 for face in allSharedEdges:
85 if geompy.NbShapes(face, geompy.ShapeType["VERTEX"]) > 1: # edge non degeneree
86 sharedEdges.append(face)
87 for i_aux, edge in enumerate(sharedEdges):
88 name = "edgeCommuneEllipsoideBloc_{}".format(i_aux)
89 geomPublishInFather(initLog.debug,blocp, edge, name)
91 facesExternes = list()
94 faces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True)
97 for i_aux, face in enumerate(faces):
98 faceExt = geompy.GetInPlace(ellipsoidep, face)
99 if faceExt is not None:
100 name = "faceExterne_e{}".format(i_aux)
101 geomPublishInFather(initLog.debug,ellipsoidep, faceExt, name)
102 facesExternes.append(faceExt)
103 facesExtElli.append(faceExt)
105 faceExt = geompy.GetInPlace(blocp, face)
106 if faceExt is not None:
107 name = "faceExterne_b{}".format(i_aux)
108 geomPublishInFather(initLog.debug,blocp, faceExt, name)
109 facesExternes.append(faceExt)
110 facesExtBloc.append(faceExt)
112 logging.info(" recherche faces externes par GetShapesOnShape")
113 vertex = geompy.MakeVertexOnSurface(face, 0.5, 0.5)
114 normal = geompy.GetNormal(face, vertex)
115 extrusionFace = geompy.MakePrismVecH(face, normal, 1)
116 #extrusionFace = geompy.MakePrismVecH2Ways(face, normal, 0.1)
117 #extrusionFace = geompy.MakeScaleTransform(extrusionFace, vertex, 1.01)
118 name = "extrusionFace_b{}".format(i_aux)
119 geomPublishInFather(initLog.debug,blocp, extrusionFace, name)
120 #facesExt = geompy.GetShapesOnShape(extrusionFace, blocp, geompy.ShapeType["FACE"], GEOM.ST_ONIN)
121 facesExt = geompy.GetShapesOnShape(extrusionFace, blocp, geompy.ShapeType["FACE"], GEOM.ST_ON)
122 for j_aux, face_ext in enumerate(facesExt):
123 name = "faceExterne_b{}_{}".format(i_aux,j_aux)
124 geomPublishInFather(initLog.debug,blocp, face_ext, name)
125 facesExternes.append(face_ext)
126 facesExtBloc.append(face_ext)
128 if len(facesExtBloc) < len(faces): # toutes les faces externes du bloc n'ont pas été trouvées. TODO eliminer les detections multiples
129 logging.info(" recherche faces externes par aretes partagees avec faces externes ellipsoide")
130 facesBloc = geompy.ExtractShapes(blocp, geompy.ShapeType["FACE"], True)
131 for i_aux, face in enumerate(facesBloc):
132 notOnEllipsoide = True
133 for j_aux, sharedface in enumerate(sharedFaces): # eliminer les faces communes avec l'ellipsoide
134 if face.IsSame(sharedface):
135 notOnEllipsoide = False
138 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
139 allSharedEdges = list()
141 allSharedEdges += geompy.GetSharedShapesMulti([face, face_ext_elli], geompy.ShapeType["EDGE"])
145 name = "faceExterne_b{}_{}".format(i_aux,j_aux)
146 geomPublishInFather(initLog.debug,blocp, face, name)
147 facesExternes.append(face)
148 facesExtBloc.append(face)
150 aretesInternes = list()
151 for i_aux, face_ext_i in enumerate(facesExternes):
152 for j_aux, face_ext_j in enumerate(facesExternes[i_aux+1:]):
155 shared += geompy.GetSharedShapesMulti([face_ext_i, face_ext_j], geompy.ShapeType["EDGE"])
157 texte = "no shared edges in {},{}".format(i_aux,j_aux)
160 aretesInternes += shared
161 for i_aux, edge in enumerate(aretesInternes):
162 name = "aretesInternes_{}".format(i_aux)
163 geomPublishInFather(initLog.debug,blocp, edge, name)
165 l_edgesBords = list()
166 for faceExtB in facesExtBloc:
167 edges = geompy.ExtractShapes(faceExtB, geompy.ShapeType["EDGE"], True)
168 for i_aux, edge in enumerate(edges):
170 for arete in aretesInternes:
171 if edge.IsSame(arete):
175 l_edgesBords.append(edge)
176 name = "edgeBord{}".format(i_aux)
177 geomPublishInFather(initLog.debug,blocp,edge , name)
179 edgesBords = geompy.CreateGroup(blocp, geompy.ShapeType["EDGE"])
180 geompy.UnionList(edgesBords, l_edgesBords)
184 return volDefautPart, blocp, tore, faceFissure, facesExternes, facesExtBloc, facesExtElli, aretesInternes, ellipsoidep, sharedFaces, sharedEdges, edgesBords