1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from .geomsmesh import geompy
23 from .geomsmesh import geomPublish
24 from .geomsmesh import geomPublishInFather
26 from .prolongeVertices import prolongeVertices
28 # -----------------------------------------------------------------------------
29 # --- zone de defaut, constructions geometrique avec CAO d'origine
31 def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoyen, lgExtrusion=50):
33 Construction CAO de la zone à remailler, quand on utilise la CAO d'origine,
34 apres appel creeZoneDefautMaillage
35 @param objetSain : la géometrie de l'objet initial
36 @param shapeDefaut : objet géometrique représentant la fissure
37 (selon les cas, un point central, ou une shape plus complexe,
38 dont on ne garde que les vertices)
39 @param origShapes : liste id subShapes
40 @param verticesShapes : listes noeuds de bord
41 @param dmoyen : longueur arete moyenne bord
42 @lgExtrusion : distance d'extrusion de la face du defaut
43 (ne vaut que pour des fissures courtes)
44 @return (facesDefaut, centreDefaut, normalDefaut, extrusionDefaut)
58 for ishape, vertices in enumerate(verticesShapes):
59 aShape = origShapes[ishape]
60 [face] = geompy.SubShapes(objetSain, [aShape])
62 curve = geompy.MakePolyline(vertices, False)
66 geomPublish(initLog.debug, curve, name)
68 cdg = geompy.MakeCDG(curve)
71 name="cdgpoly_%d"%aShape
72 geomPublish(initLog.debug, cdg, name)
74 projCdg = geompy.MakeProjection(cdg, face)
77 name="projCdg_%d"%aShape
78 geomPublish(initLog.debug, projCdg, name)
80 normal = geompy.GetNormal(face, projCdg)
81 normals.append(normal)
83 name="normal_%d"%aShape
84 geomPublish(initLog.debug, normal, name)
86 extrusion = geompy.MakePrismVecH2Ways(curve, normal, 10)
87 extrusions.append(extrusion)
89 name="extrusion_%d"%aShape
90 geomPublish(initLog.debug, extrusion, name)
92 verticesProlongees = prolongeVertices(vertices)
94 curveprol = geompy.MakePolyline(verticesProlongees, False)
96 name="polyProl_%d"%aShape
97 geomPublish(initLog.debug, curveprol, name)
99 extruprol = geompy.MakePrismVecH2Ways(curveprol, normal, 10)
101 name="extruProl_%d"%aShape
102 geomPublish(initLog.debug, extruprol, name)
104 partition = geompy.MakePartition([face], [extruprol], [], [], geompy.ShapeType["FACE"], 0, [], 0)
105 partitions.append(partition)
107 name="partition_%d"%aShape
108 geomPublish(initLog.debug, partition, name)
112 centreSphere = geompy.MakeCDG(shapeDefaut)
113 geomPublish(initLog.debug, centreSphere, "cdg_defaut")
114 ccurves = geompy.MakeCompound(curves)
115 gravCenter = geompy.MakeCDG(ccurves)
116 geomPublish(initLog.debug, gravCenter, "cdg_curves")
117 for i in range(len(partitions)):
119 logging.debug(" --- original shape %s", origShapes[i])
122 subFaces = geompy.ExtractShapes(partitions[i], geompy.ShapeType["FACE"], True)
123 for aFace in subFaces:
124 cdg = geompy.MakeCDG(aFace)
125 distance = geompy.MinDistance(cdg, centreSphere)
126 dists.append(distance)
127 facesToSort.append(aFace)
129 logging.debug("distance = %s", distance)
134 for j,d in enumerate(dists):
136 aFace = facesToSort[j]
137 name="decoupe_%d"%origShapes[i]
138 geomPublish(initLog.debug, aFace, name)
139 decoupes.append(aFace)
144 facesDefaut = decoupes[0]
145 if len(decoupes) > 1:
146 facesDefaut = geompy.MakePartition(decoupes, [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
147 geomPublish(initLog.debug, facesDefaut, "facesDefaut")
150 if len(decoupes) > 1: # plusieurs faces de defaut
151 subFaces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True)
152 # --- regroupe les subFaces en shells connectes
153 theFaces = list(subFaces) # copy
154 while len(theFaces) > 0:
155 logging.debug("------- len(theFaces) %s" , len(theFaces))
156 theFace = theFaces[0]
157 logging.debug(" start with face %s",theFaces[0])
161 while len(toAdd) > 0:
164 for i in range(len(theFaces)):
165 logging.debug(" try %s", theFaces[i])
167 logging.debug(" with %s", aFace)
169 edge = geompy.GetSharedShapesMulti([aFace, theFaces[i]], geompy.ShapeType["EDGE"])
174 if theFaces[i] not in toAdd:
175 toAdd.append(theFaces[i])
177 logging.debug(" --- add %s", theFaces[i])
179 for k in sorted(toRemove, reverse=True):
181 theShell = geompy.MakeShell(aShell)
182 name = "theShell%d"%len(shells)
183 geomPublish(initLog.debug, theShell,name)
184 shells.append(theShell)
187 for aShell in shells: # --- trouver le shell en contact avec la fissure
188 distances.append(geompy.MinDistance(aShell, shapeDefaut))
189 minDist = min(distances)
190 for index in range(len(distances)):
191 if distances[index] == minDist:
193 theShellDefaut = shells[index]
195 else: # --- une seule face de defaut
196 subFaces = [facesDefaut]
197 theShellDefaut = geompy.MakeShell(subFaces)
199 geomPublish(initLog.debug, theShellDefaut,"theShellDefaut")
201 theFaces = geompy.ExtractShapes(theShellDefaut, geompy.ShapeType["FACE"], True)
203 for aFace in theFaces:
204 distances.append(geompy.MinDistance(aFace, centreSphere))
205 minDist = min(distances)
206 for index in range(len(distances)):
207 if distances[index] == minDist:
210 centreDefaut = geompy.MakeProjection(centreSphere, theFaces[index])
212 geomPublish(initLog.debug, centreDefaut, "centreDefaut")
213 normalDefaut = geompy.GetNormal(subFaces[index], centreDefaut)
215 geomPublish(initLog.debug, normalDefaut, "normalDefaut")
216 extrusionDefaut = geompy.MakePrismVecH(theShellDefaut, normalDefaut, -lgExtrusion)
217 info = geompy.ShapeInfo(extrusionDefaut)
218 logging.debug("shape info %s", info)
219 if (info['SOLID'] > 1) or (info['COMPOUND'] > 0) :
220 solids = geompy.ExtractShapes(extrusionDefaut, geompy.ShapeType["SOLID"], True)
222 for i in range(1,len(solids)):
223 solid0 = geompy.MakeFuse(solid0, solids[i])
224 extrusionDefaut = solid0
226 geomPublish(initLog.debug, extrusionDefaut, "extrusionDefaut")
228 return facesDefaut, centreDefaut, normalDefaut, extrusionDefaut