Salome HOME
Copyright update 2021
[modules/smesh.git] / src / Tools / blocFissure / gmu / fusionMaillageAttributionDefaut.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 """
21 Created on Tue Jun 24 09:14:13 2014
22
23 @author: I48174 (Olivier HOAREAU)
24 """
25
26 import logging
27 from .geomsmesh import geompy
28 from .geomsmesh import smesh
29 from .geomsmesh import geomPublish
30 from .geomsmesh import geomPublishInFather
31 from . import initLog
32 import GEOM
33 import SMESH
34
35 from .listOfExtraFunctions import createNewMeshesFromCorner
36 from .listOfExtraFunctions import createLinesFromMesh
37
38 # -----------------------------------------------------------------------------
39 # --- groupe de quadrangles de face transformé en face géométrique par filling
40
41 def fusionMaillageDefaut(maillageSain, maillageDefautCible, maillageInterneCible, zoneDefaut_skin, shapeDefaut, listOfCorners):
42     """ """
43     # TODO: rédiger la docstring
44     
45     logging.info("start")
46     
47     facesNonCoupees = []
48     facesCoupees = []
49     maillagesNonCoupes = []
50     maillagesCoupes = []
51         
52     # On crée une liste contenant le maillage de chaque face.
53     listOfNewMeshes = createNewMeshesFromCorner(maillageDefautCible, listOfCorners)
54     
55     i = 0
56     while i < len(listOfNewMeshes):
57         lines = createLinesFromMesh(listOfNewMeshes[i])
58         setOfLines = []
59         for line in lines:
60             # On possède l'information 'ID' de chaque noeud composant chaque
61             # ligne de la face. A partir de l'ID, on crée un vertex. Un
62             # ensemble de vertices constitue une ligne. Un ensemble de lignes
63             # constitue la face.
64             tmpCoords = [maillageDefautCible.GetNodeXYZ(node) for node in line]
65             tmpPoints = [geompy.MakeVertex(val[0], val[1], val[2]) for val in tmpCoords]
66             line = geompy.MakeInterpol(tmpPoints, False, False)
67             setOfLines.append(line)
68         
69         # A partir des lignes de la face,
70         # on recrée un objet GEOM temporaire par filling.
71         filling = geompy.MakeFilling(geompy.MakeCompound(setOfLines), 2, 5, 0.0001, 0.0001, 0, GEOM.FOM_Default, True)
72         #logging.debug("face de filling")
73         #geomPublish(initLog.debug, filling, 'filling_{0}'.format(i + 1))
74         
75         tmpPartition = geompy.MakePartition([filling], [shapeDefaut], [], [], geompy.ShapeType["FACE"], 0, [], 0)
76         tmpExplodeRef = geompy.ExtractShapes(filling, geompy.ShapeType["EDGE"], True)
77         tmpExplodeNum = geompy.ExtractShapes(tmpPartition, geompy.ShapeType["EDGE"], True)
78         if len(tmpExplodeRef) == len(tmpExplodeNum):
79             logging.debug("face de filling non coupee")
80             geompy.addToStudy( filling, "faceNonCoupee_{0}".format(i + 1)) # doit etre publie pour critere OK plus bas
81             facesNonCoupees.append(filling)
82             maillagesNonCoupes.append(listOfNewMeshes[i])
83         else:
84             logging.debug("face de filling coupee")
85             geompy.addToStudy( filling, "faceCoupee_{0}".format(i + 1))
86             facesCoupees.append(filling)
87             maillagesCoupes.append(listOfNewMeshes[i])
88         
89         i += 1
90     
91     listOfInternMeshes = [maillageInterneCible] + [msh.GetMesh() for msh in maillagesNonCoupes]
92     
93     newMaillageInterne = smesh.Concatenate(listOfInternMeshes, 1, 1, 1e-05, False)
94     
95     facesEnTrop = []
96     
97     criteres = [smesh.GetCriterion(SMESH.FACE, SMESH.FT_BelongToGenSurface, SMESH.FT_Undefined, face) for face in facesNonCoupees]
98     filtres = [smesh.GetFilterFromCriteria([critere]) for critere in criteres]
99     for i, filtre in enumerate(filtres):
100         filtre.SetMesh(maillageSain.GetMesh())
101         faceEnTrop = maillageSain.GroupOnFilter(SMESH.FACE, 'faceEnTrop_{0}'.format(i + 1), filtre)
102         facesEnTrop.append(faceEnTrop)
103     
104     newZoneDefaut_skin = maillageSain.GetMesh().CutListOfGroups([zoneDefaut_skin], facesEnTrop, 'newZoneDefaut_skin')
105     
106     smesh.SetName(newMaillageInterne, 'newInternalBoundary')
107         
108     return newZoneDefaut_skin, newMaillageInterne
109