Salome HOME
Mise à niveau python
[modules/smesh.git] / src / Tools / blocFissure / gmu / quadranglesToShapeWithCorner.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 """Remarque : cette focntion n'est jamais appelée ????"""
21
22 import logging
23
24 import GEOM
25
26 from .geomsmesh import geompy
27 from .geomsmesh import geomPublish
28 from .geomsmesh import geomPublishInFather
29
30 from . import initLog
31
32 from .listOfExtraFunctions import createNewMeshesFromCorner
33 from .listOfExtraFunctions import createLinesFromMesh
34
35 # -----------------------------------------------------------------------------
36 # --- groupe de quadrangles de face transformé en face géométrique par filling
37
38 def quadranglesToShapeWithCorner(meshQuad, shapeDefaut, listOfCorners):
39   """TODO: rédiger la docstring"""
40
41   logging.info("start")
42
43   #fillings = [list(), list()]
44   tmpFillings = list()
45   noeuds_bords = list()
46   #bords_Partages = [list(), list()]
47   tmpBords = list()
48   fillconts = list()
49   idFilToCont = list()
50
51   facesNonCoupees = list()
52   facesCoupees = list()
53   aretesNonCoupees = list()
54   aretesCoupees = list()
55
56   setOfNodes = list()
57   setOfLines = list()
58   listOfEdges = list()
59   # On crée une liste contenant le maillage de chaque face.
60   listOfNewMeshes = createNewMeshesFromCorner(meshQuad, listOfCorners)
61   for msh in listOfNewMeshes:
62     # On crée une liste de noeuds correspondant aux faces suivant
63     # le modèle liste[face][ligne][noeud].
64     #lines = createLinesFromMesh(msh, listOfCorners[0])
65     lines = createLinesFromMesh(msh)
66     setOfNodes.append(lines)
67
68   for face in setOfNodes:
69     tmpFace = list()
70     for line in face:
71       # On possède l'information 'ID' de chaque noeud composant chaque
72       # ligne de chaque face. A partir de l'ID, on crée un vertex. Un
73       # ensemble de vertices constitue une ligne. Un ensemble de lignes
74       # constitue une face.
75       tmpCoords = [meshQuad.GetNodeXYZ(node) for node in line]
76       tmpPoints = [geompy.MakeVertex(val[0], val[1], val[2]) for val in tmpCoords]
77       line = geompy.MakeInterpol(tmpPoints, False, False)
78       tmpFace.append(line)
79     setOfLines.append(tmpFace)
80
81   for i, face in enumerate(setOfLines):
82     # A partir des lignes de chaque face,
83     # on recrée un objet GEOM temporaire par filling.
84     filling = geompy.MakeFilling(geompy.MakeCompound(face), 2, 5, 0.0001, 0.0001, 0, GEOM.FOM_Default, True)
85     geomPublish(initLog.debug, filling, 'filling_{}'.format(i + 1))
86     tmpFillings.append(filling)
87
88   for face in setOfNodes:
89     # On prend la première ligne qui correspond aux bords partagés
90     listOfEdges.append(face[0])
91
92   for edge in listOfEdges:
93     # On utilise les points de bords pour créer des aretes vives
94     tmpCoords = [meshQuad.GetNodeXYZ(node) for node in list(edge)]
95     tmpPoints = [geompy.MakeVertex(val[0], val[1], val[2]) for val in tmpCoords]
96     line = geompy.MakeInterpol(tmpPoints, False, False)
97     tmpBords.append(line)
98
99   for i, filling in enumerate(tmpFillings):
100     tmpPartition = geompy.MakePartition([filling], [shapeDefaut], list(), list(), geompy.ShapeType["FACE"], 0, list(), 0, True)
101     tmpExplodeRef = geompy.ExtractShapes(filling, geompy.ShapeType["EDGE"], True)
102     tmpExplodeNum = geompy.ExtractShapes(tmpPartition, geompy.ShapeType["EDGE"], True)
103     if len(tmpExplodeRef) == len(tmpExplodeNum):
104       geomPublish(initLog.debug, filling, "faceNonCoupee_{}".format(i + 1))
105       facesNonCoupees.append(filling)
106     else:
107       geomPublish(initLog.debug, filling, "faceCoupee_{}".format(i + 1))
108       facesCoupees.append(filling)
109   fillings = facesCoupees, facesNonCoupees
110
111   for i, filling in enumerate(tmpBords):
112     tmpPartition = geompy.MakePartition([shapeDefaut], [filling], list(), list(), geompy.ShapeType["SHELL"], 0, list(), 0, True)
113     tmpExplodeRef = geompy.ExtractShapes(shapeDefaut, geompy.ShapeType["EDGE"], True) + geompy.ExtractShapes(shapeDefaut, geompy.ShapeType["VERTEX"], True)
114     tmpExplodeNum = geompy.ExtractShapes(tmpPartition, geompy.ShapeType["EDGE"], True) + geompy.ExtractShapes(tmpPartition, geompy.ShapeType["VERTEX"], True)
115     if len(tmpExplodeRef) == len(tmpExplodeNum):
116       geomPublish(initLog.debug, filling, "areteNonCoupee_{}".format(i + 1))
117       aretesNonCoupees.append(filling)
118     else:
119       geomPublish(initLog.debug, filling, "areteCoupee_{}".format(i + 1))
120       aretesCoupees.append(filling)
121   bords_Partages = aretesCoupees, aretesNonCoupees
122
123 # TODO: A enlever
124 #    for i, face in enumerate(setOfLines):
125 #      for j, line in enumerate(face):
126 #      geomPublish(initLog.debug, line, 'face{0}_ligne{1}'.format(i + 1, j + 1))
127
128 #TODO: A enlever
129 #    for i, filling in enumerate(fillings[0]):
130 #      geomPublish(initLog.debug, filling, 'filling_{0}'.format(i + 1))
131 #      for j, line in enumerate(setOfLines[i]):
132 #      geompy.addToStudyInFather(filling, line, 'line_{0}'.format(j + 1))
133
134   return fillings, noeuds_bords, bords_Partages, fillconts, idFilToCont