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