Salome HOME
simplification
[modules/smesh.git] / src / Tools / blocFissure / gmu / identifieFacesPeau.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 """Inventaire des faces de peau"""
21
22 import logging
23
24 from . import initLog
25
26 from .geomsmesh import geompy
27 from .geomsmesh import geomPublish
28
29 from .sortFaces import sortFaces
30 from .extractionOrientee import extractionOrientee
31
32 def identifieFacesPeau(ifil, verticesPipePeau, facesOnside, wireFondFiss, \
33                        verticesEdgesFondIn, pipexts, cercles, \
34                        fillingFaceExterne, centreFondFiss, \
35                        nro_cas=None):
36   """Inventaire des faces de peau : face de peau percée du pipe, extrémités du pipe
37
38   La partition avec le pipe peut créer un vertex (et un edge) de trop sur le cercle projeté,
39   quand le cercle est très proche de la face.
40   dans ce cas, la projection du cercle sur la face suivie d'une partition permet
41   d'éviter le point en trop
42   """
43   logging.info('start')
44
45   facesAndFond = facesOnside
46   facesAndFond.append(wireFondFiss)
47   try:
48     partitionPeauByPipe = geompy.MakePartition(facesAndFond, pipexts, [], [], geompy.ShapeType["FACE"], 0, [], 1)
49   except:
50     logging.debug("probleme partition face pipe, contournement avec MakeSection")
51     sections = list()
52     for pipext in pipexts:
53       sections.append(geompy.MakeSection(facesOnside[0], pipext))
54     partitionPeauByPipe = geompy.MakePartition(facesAndFond, sections, [], [], geompy.ShapeType["FACE"], 0, [], 1)
55
56   # contrôle edge en trop sur edges circulaires
57   if len(verticesPipePeau) > 0: # --- au moins une extrémité du pipe sur cette face de peau
58     edgeEnTrop = list()
59     outilPart = pipexts
60     facesPeau = geompy.ExtractShapes(partitionPeauByPipe, geompy.ShapeType["FACE"], False)
61     facesPeauSorted, _, _ = sortFaces(facesPeau)
62     for face in facesPeauSorted[:-1]: # on ne teste que la ou les petites faces "circulaires"
63       nbv = geompy.NumberOfEdges(face)
64       logging.debug("nombre d'edges sur face circulaire: %s", nbv)
65       edgeEnTrop.append(bool(nbv > 3)) # TODO : distinguer les cas avec deux faces circulaires dont l'une est correcte
66     refaire = sum(edgeEnTrop)
67     if refaire > 0:
68       l_aux = [(geompy.MinDistance(verticesEdgesFondIn[0], fac), i_aux)  for i_aux, fac in enumerate(facesPeauSorted[:-1])]
69       l_aux.sort()
70       logging.debug("l_aux sorted: %s", l_aux)
71       direct = bool(l_aux[0][1] == 0) # l_aux[0][1] = indice de facesPeauSorted qui correspond à verticesEdgesFondIn[0], donc 0 pour cercles
72       for i_aux, bad in enumerate(edgeEnTrop):
73         if direct:
74           j_aux = i_aux
75         else:
76           j_aux = 1-i_aux
77         if bad:
78           outilPart[j_aux] = geompy.MakeProjection(cercles[j_aux],facesOnside[0])
79       partitionPeauByPipe = geompy.MakePartition(facesAndFond, outilPart, [], [], geompy.ShapeType["FACE"], 0, [], 1)
80
81   name="partitionPeauByPipe_{}".format(ifil)
82   geomPublish(initLog.debug, partitionPeauByPipe, name)
83   [edgesPeauFondIn, _, _] = extractionOrientee(fillingFaceExterne, partitionPeauByPipe, centreFondFiss, "EDGE", 1.e-3)
84   [_, _, facesPeauFondOn] = extractionOrientee(fillingFaceExterne, partitionPeauByPipe, centreFondFiss, "FACE", 1.e-3)
85
86   if verticesPipePeau: # --- au moins une extrémité du pipe sur cette face de peau
87     facesPeauSorted, _, _ = sortFaces(facesPeauFondOn)
88     facePeau = facesPeauSorted[-1] # la plus grande face
89   else:
90     facePeau =geompy.MakePartition(facesPeauFondOn, [], [], [], geompy.ShapeType["FACE"], 0, [], 1)
91     facesPeauSorted = [facePeau]
92
93   name="facePeau_{}".format(ifil)
94   geomPublish(initLog.always, facePeau, name, nro_cas)
95
96   return (facePeau, facesPeauSorted, edgesPeauFondIn)