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