Salome HOME
Copyright update 2020
[modules/smesh.git] / src / Tools / blocFissure / gmu / facesCirculaires.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  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 from .geomsmesh import geompy
23 from .geomsmesh import geomPublish
24 from .geomsmesh import geomPublishInFather
25 from . import initLog
26
27 # -----------------------------------------------------------------------------
28 # --- TORE
29 ## --- faces 1/2 circulaires et leur centre, edges de ces faces dans le plan de fissure
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   geomPublishInFather(initLog.debug, tore, faces[0], 'face0' )
45   geomPublishInFather(initLog.debug, tore, faces[1], 'face1' )
46   geomPublishInFather(initLog.debug, tore, faces[2], 'face2' )
47   geomPublishInFather(initLog.debug, tore, faces[3], 'face3' )
48
49   centres = [None, None, None, None]
50   [v1,centres[0],v3] = geompy.ExtractShapes(faces[0], geompy.ShapeType["VERTEX"], True)
51   [v1,centres[1],v3] = geompy.ExtractShapes(faces[1], geompy.ShapeType["VERTEX"], True)
52   [v1,centres[2],v3] = geompy.ExtractShapes(faces[2], geompy.ShapeType["VERTEX"], True)
53   [v1,centres[3],v3] = geompy.ExtractShapes(faces[3], geompy.ShapeType["VERTEX"], True)
54
55   geomPublishInFather(initLog.debug, faces[0], centres[0], 'centre0' )
56   geomPublishInFather(initLog.debug, faces[1], centres[1], 'centre1' )
57   geomPublishInFather(initLog.debug, faces[2], centres[2], 'centre2' )
58   geomPublishInFather(initLog.debug, faces[3], centres[3], 'centre3' )
59
60   alledges = [None, None, None, None]
61   alledges[0] = geompy.ExtractShapes(faces[0], geompy.ShapeType["EDGE"], True)
62   alledges[1] = geompy.ExtractShapes(faces[1], geompy.ShapeType["EDGE"], True)
63   alledges[2] = geompy.ExtractShapes(faces[2], geompy.ShapeType["EDGE"], True)
64   alledges[3] = geompy.ExtractShapes(faces[3], geompy.ShapeType["EDGE"], True)
65
66   dicoedge = {}
67   edges = []
68   reverses = []
69   for i in range(len(alledges)):
70     edgesface = alledges[i]
71     lenef = []
72     for j in range(len(edgesface)):
73       props = geompy.BasicProperties(edgesface[j])
74       lenef.append(props[0])
75       pass
76     maxlen = max(lenef)
77     for j in range(len(edgesface)):
78       if lenef[j] < maxlen:
79         edgid = geompy.GetSubShapeID(tore, edgesface[j])
80         if not (edgid in dicoedge):
81           dicoedge[edgid] = edgesface[j]
82           edges.append(edgesface[j])
83           named = 'edge_' + str(i) + '_' +str(j)
84           geomPublishInFather(initLog.debug, faces[i], edgesface[j], named)
85           vertices = geompy.ExtractShapes(edgesface[j], geompy.ShapeType["VERTEX"], False)
86           #firstVertex = geompy.GetFirstVertex(edgesface[j])
87           if geompy.GetSubShapeID(tore, vertices[0]) != geompy.GetSubShapeID(tore, centres[i]):
88             reverses.append(1)
89             #print 'reversed ' + str(edgid)
90           else:
91             reverses.append(0)
92             #print 'normal' + str(edgid)
93           pass
94         pass
95       pass
96     pass
97
98   return faces, centres, edges, reverses
99