Salome HOME
simplification
[modules/smesh.git] / src / Tools / blocFissure / gmu / partitionBlocDefaut.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Partition du bloc defaut par generatrice, tore et plan fissure"""
21
22 import logging
23
24 import GEOM
25
26 from .geomsmesh import geompy
27 from .geomsmesh import geomPublish
28 from .geomsmesh import geomPublishInFather
29
30 from . import initLog
31
32 def partitionBlocDefaut(volDefaut, facesDefaut, gener, pipe,
33                         facefis, ellipsoide):
34   """
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é
40   dans l'espace
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)
45   """
46   logging.info("start")
47
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)
54
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' )
59
60   solids = geompy.ExtractShapes(blocp, geompy.ShapeType["SOLID"], True)
61   vols = list()
62   for solid in solids:
63     props = geompy.BasicProperties(solid)
64     vols.append(props[2])
65   maxvol = max(vols)
66   imaxvol = vols.index(maxvol)
67   blocp = solids[imaxvol]
68   vols[imaxvol] = 0
69   maxvol = max(vols)
70   imaxvol = vols.index(maxvol)
71   ellipsoidep = solids[imaxvol]
72
73   geomPublishInFather(initLog.debug, volDefautPart, blocp, 'bloc' )
74   geomPublishInFather(initLog.debug, volDefautPart, ellipsoidep, 'ellipsoide' )
75
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)
80
81   #sharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"])
82   allSharedEdges = geompy.GetSharedShapesMulti([blocp, ellipsoidep], geompy.ShapeType["EDGE"])
83   sharedEdges = list()
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)
90
91   facesExternes = list()
92   facesExtBloc = list()
93   facesExtElli = list()
94   faces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True)
95   if not faces:
96     faces = [facesDefaut]
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)
104
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)
111     else:
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)
127
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
136           break
137       if notOnEllipsoide:
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()
140           try:
141             allSharedEdges += geompy.GetSharedShapesMulti([face, face_ext_elli], geompy.ShapeType["EDGE"])
142           except:
143             pass
144           if allSharedEdges:
145             name = "faceExterne_b{}_{}".format(i_aux,j_aux)
146             geomPublishInFather(initLog.debug,blocp, face, name)
147             facesExternes.append(face)
148             facesExtBloc.append(face)
149
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:]):
153       shared = list()
154       try:
155         shared += geompy.GetSharedShapesMulti([face_ext_i, face_ext_j], geompy.ShapeType["EDGE"])
156       except:
157         texte = "no shared edges in {},{}".format(i_aux,j_aux)
158         logging.info(texte)
159       else:
160         aretesInternes += shared
161   for i_aux, edge in enumerate(aretesInternes):
162     name = "aretesInternes_{}".format(i_aux)
163     geomPublishInFather(initLog.debug,blocp, edge, name)
164
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):
169       isInterne = False
170       for arete in aretesInternes:
171         if edge.IsSame(arete):
172           isInterne = True
173           break
174       if not isInterne:
175         l_edgesBords.append(edge)
176         name = "edgeBord{}".format(i_aux)
177         geomPublishInFather(initLog.debug,blocp,edge , name)
178   if l_edgesBords:
179     edgesBords = geompy.CreateGroup(blocp, geompy.ShapeType["EDGE"])
180     geompy.UnionList(edgesBords, l_edgesBords)
181   else:
182     edgesBords = None
183
184   return volDefautPart, blocp, tore, faceFissure, facesExternes, facesExtBloc, facesExtElli, aretesInternes, ellipsoidep, sharedFaces, sharedEdges, edgesBords