Salome HOME
Update of CheckDone
[modules/smesh.git] / src / Tools / blocFissure / gmu / facesCirculaires.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 """Tore : faces 1/2 circulaires et leur centre, edges de ces faces dans le plan de fissure"""
21
22 import logging
23
24 from . import initLog
25
26 import GEOM
27
28 from .geomsmesh import geompy
29 from .geomsmesh import geomPublishInFather
30
31 def facesCirculaires(bloc, tore):
32   """
33   Extraction des faces demi circulaires à l'intersection du tore partitionné et de la paroi,
34   de leur centre, les edges de ces faces situees dans le plan de fissure et un booleen par edge,
35   indiquant son sens (normal / reversed).
36   @param bloc : bloc defaut
37   @param tore : le tore partitionné et coupé
38   @return (faces, centres, edges, reverses)
39   """
40   logging.info("start")
41
42   faces = geompy.GetShapesOnShape(bloc, tore, geompy.ShapeType["FACE"], GEOM.ST_ON)
43
44   centres = list()
45   alledges = list()
46   for i_aux in range(4):
47     geomPublishInFather(initLog.debug, tore, faces[i_aux], 'face{}'.format(i_aux))
48     [_,centre,_] = geompy.ExtractShapes(faces[i_aux], geompy.ShapeType["VERTEX"], True)
49     centres.append(centre)
50     geomPublishInFather(initLog.debug, faces[i_aux], centre, 'centre{}'.format(i_aux))
51     alledges.append(geompy.ExtractShapes(faces[i_aux], geompy.ShapeType["EDGE"], True))
52
53   dicoedge = dict()
54   edges = list()
55   reverses = list()
56
57   for i_aux, edgesface in enumerate(alledges):
58
59     lenef = list()
60     for edge in edgesface:
61       props = geompy.BasicProperties(edge)
62       lenef.append(props[0])
63
64     maxlen = max(lenef)
65     for j_aux, edge in enumerate(edgesface):
66       if lenef[j_aux] < maxlen:
67         edgid = geompy.GetSubShapeID(tore, edge)
68         if not (edgid in dicoedge):
69           dicoedge[edgid] = edge
70           edges.append(edge)
71           named = 'edge_{}_{}'.format(i_aux,j_aux)
72           geomPublishInFather(initLog.debug, faces[i_aux], edge, named)
73           vertices = geompy.ExtractShapes(edge, geompy.ShapeType["VERTEX"], False)
74           #firstVertex = geompy.GetFirstVertex(edge)
75           if geompy.GetSubShapeID(tore, vertices[0]) != geompy.GetSubShapeID(tore, centres[i_aux]):
76             reverses.append(1)
77             #print 'reversed ' + str(edgid)
78           else:
79             reverses.append(0)
80             #print 'normal' + str(edgid)
81
82   return faces, centres, edges, reverses