Salome HOME
44f9525aa94b32e16c57567c91bc25b9c23caeb1
[modules/smesh.git] / src / Tools / blocFissure / gmu / construitEdgesRadialesDebouchantes_c.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 """Construction des listes d'edges radiales sur chaque extrémité débouchante"""
21
22 import logging
23 import GEOM
24
25 from .geomsmesh import geompy
26 from .geomsmesh import geomPublish
27 from . import initLog
28 from .sortEdges import sortEdges
29
30 def construitEdgesRadialesDebouchantes_c(facesPipePeau, edgeRadFacePipePeau, \
31                                          listNappes, idFacesDebouchantes):
32   """Construction des listes d'edges radiales sur chaque extrémité débouchante"""
33   logging.info('start')
34   listEdges = list()
35   for n_nappe, nappes in enumerate(listNappes):
36     ifd = idFacesDebouchantes[n_nappe] # indice de face débouchante (facesPipePeau)
37     if ifd < 0:
38       listEdges.append([])
39     else:
40       face = facesPipePeau[ifd]
41       edges = [edgeRadFacePipePeau[ifd]]
42       for n_nappe, nappe in enumerate(nappes):
43         if n_nappe > 0:
44           obj = geompy.MakeSection(face, nappe) # normalement une edge, parfois un compound d'edges dont un tout petit
45           edge = obj
46
47           l_shapes = geompy.ExtractShapes(obj, geompy.ShapeType["VERTEX"], False)
48           if len(l_shapes) > 2:
49             eds = geompy.ExtractShapes(obj, geompy.ShapeType["EDGE"], False)
50             [edsorted, _, maxl] = sortEdges(eds)
51             edge = edsorted[-1]
52           else:
53             maxl = geompy.BasicProperties(edge)[0]
54
55           if maxl < 0.01: # problème MakeSection
56             logging.info("problème MakeSection recherche edge radiale %s, longueur trop faible: %s, utilisation partition", n_nappe, maxl)
57             partNappeFace = geompy.MakePartition([face, nappe], [] , [], [], geompy.ShapeType["FACE"], 0, [], 0)
58             l_shapes= geompy.ExtractShapes(partNappeFace, geompy.ShapeType["EDGE"], False)
59             l_nouv_edges = list()
60             for shape in l_shapes:
61               dmax=100.
62               l_vertex = geompy.ExtractShapes(shape, geompy.ShapeType["VERTEX"], False)
63               distx = [geompy.MinDistance(vertex, face) for vertex in l_vertex]
64               distx += [geompy.MinDistance(vertex, nappe) for vertex in l_vertex]
65               dmax = max(distx)
66               lgedge = geompy.BasicProperties(shape)[0]
67               logging.debug("  dmax %s, longueur edge %s",dmax, lgedge)
68               if dmax < 0.01 and  lgedge > 0.01:
69                 l_nouv_edges.append(shape)
70
71             if l_nouv_edges:
72               logging.debug("  edges issues de la partition: %s", l_nouv_edges)
73               for num, edge in enumerate(l_nouv_edges):
74                 geomPublish(initLog.debug, edge, "l_nouv_edges%d"%num)
75               [edsorted, _, maxl] = sortEdges(l_nouv_edges)
76               logging.debug("  longueur edge trouvée: %s", maxl)
77               edge = edsorted[-1]
78             else:
79               logging.info("problème partition recherche edge radiale %s", n_nappe)
80               l_vertex = geompy.ExtractShapes(partNappeFace, geompy.ShapeType["VERTEX"], False)
81               l_vertexnouv= list()
82               for vertex in l_vertex:
83                 distx = geompy.MinDistance(vertex, face)
84                 distx += geompy.MinDistance(vertex, nappe)
85                 logging.debug("vertex distance: %s", distx)
86                 if distx < 0.005:
87                   l_vertexnouv.append(vertex)
88               logging.debug("nombre vertex candidats %s", len(l_vertexnouv))
89               if len(l_vertexnouv) >= 2:
90                 l_edges = [geompy.MakeEdge(l_vertexnouv[j],l_vertexnouv[(j+1)%len(l_vertexnouv)]) for j in range(len(l_vertexnouv))]
91                 [edsorted2, _, maxl] = sortEdges(l_edges)
92                 edge = edsorted2[-1]
93                 logging.debug("lg edge: %s", maxl)
94               else:
95                 logging.debug("problème recherche edge radiale %s non résolu", n_nappe)
96           edges.append(edge)
97           name = 'edgeEndPipe%d'%n_nappe
98           geomPublish(initLog.debug, edge, name)
99       listEdges.append(edges)
100
101   return listEdges