1 # -*- coding: utf-8 -*-
4 from .geomsmesh import geompy
5 from .geomsmesh import geomPublish
6 from .geomsmesh import geomPublishInFather
8 from .prolongeVertices import prolongeVertices
10 # -----------------------------------------------------------------------------
11 # --- zone de defaut, constructions geometrique avec CAO d'origine
13 def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoyen, lgExtrusion=50):
15 Construction CAO de la zone à remailler, quand on utilise la CAO d'origine,
16 apres appel creeZoneDefautMaillage
17 @param objetSain : la géometrie de l'objet initial
18 @param shapeDefaut : objet géometrique représentant la fissure
19 (selon les cas, un point central, ou une shape plus complexe,
20 dont on ne garde que les vertices)
21 @param origShapes : liste id subShapes
22 @param verticesShapes : listes noeuds de bord
23 @param dmoyen : longueur arete moyenne bord
24 @lgExtrusion : distance d'extrusion de la face du defaut
25 (ne vaut que pour des fissures courtes)
26 @return (facesDefaut, centreDefaut, normalDefaut, extrusionDefaut)
40 for ishape, vertices in enumerate(verticesShapes):
41 aShape = origShapes[ishape]
42 [face] = geompy.SubShapes(objetSain, [aShape])
44 curve = geompy.MakePolyline(vertices, False)
48 geomPublish(initLog.debug, curve, name)
50 cdg = geompy.MakeCDG(curve)
53 name="cdgpoly_%d"%aShape
54 geomPublish(initLog.debug, cdg, name)
56 projCdg = geompy.MakeProjection(cdg, face)
59 name="projCdg_%d"%aShape
60 geomPublish(initLog.debug, projCdg, name)
62 normal = geompy.GetNormal(face, projCdg)
63 normals.append(normal)
65 name="normal_%d"%aShape
66 geomPublish(initLog.debug, normal, name)
68 extrusion = geompy.MakePrismVecH2Ways(curve, normal, 10)
69 extrusions.append(extrusion)
71 name="extrusion_%d"%aShape
72 geomPublish(initLog.debug, extrusion, name)
74 verticesProlongees = prolongeVertices(vertices)
76 curveprol = geompy.MakePolyline(verticesProlongees, False)
78 name="polyProl_%d"%aShape
79 geomPublish(initLog.debug, curveprol, name)
81 extruprol = geompy.MakePrismVecH2Ways(curveprol, normal, 10)
83 name="extruProl_%d"%aShape
84 geomPublish(initLog.debug, extruprol, name)
86 partition = geompy.MakePartition([face], [extruprol], [], [], geompy.ShapeType["FACE"], 0, [], 0)
87 partitions.append(partition)
89 name="partition_%d"%aShape
90 geomPublish(initLog.debug, partition, name)
94 centreSphere = geompy.MakeCDG(shapeDefaut)
95 geomPublish(initLog.debug, centreSphere, "cdg_defaut")
96 ccurves = geompy.MakeCompound(curves)
97 gravCenter = geompy.MakeCDG(ccurves)
98 geomPublish(initLog.debug, gravCenter, "cdg_curves")
99 for i in range(len(partitions)):
101 logging.debug(" --- original shape %s", origShapes[i])
104 subFaces = geompy.ExtractShapes(partitions[i], geompy.ShapeType["FACE"], True)
105 for aFace in subFaces:
106 cdg = geompy.MakeCDG(aFace)
107 distance = geompy.MinDistance(cdg, centreSphere)
108 dists.append(distance)
109 facesToSort.append(aFace)
111 logging.debug("distance = %s", distance)
116 for j,d in enumerate(dists):
118 aFace = facesToSort[j]
119 name="decoupe_%d"%origShapes[i]
120 geomPublish(initLog.debug, aFace, name)
121 decoupes.append(aFace)
126 facesDefaut = decoupes[0]
127 if len(decoupes) > 1:
128 facesDefaut = geompy.MakePartition(decoupes, [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
129 geomPublish(initLog.debug, facesDefaut, "facesDefaut")
132 if len(decoupes) > 1: # plusieurs faces de defaut
133 subFaces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True)
134 # --- regroupe les subFaces en shells connectes
135 theFaces = list(subFaces) # copy
136 while len(theFaces) > 0:
137 logging.debug("------- len(theFaces) %s" , len(theFaces))
138 theFace = theFaces[0]
139 logging.debug(" start with face %s",theFaces[0])
143 while len(toAdd) > 0:
146 for i in range(len(theFaces)):
147 logging.debug(" try %s", theFaces[i])
149 logging.debug(" with %s", aFace)
151 edge = geompy.GetSharedShapesMulti([aFace, theFaces[i]], geompy.ShapeType["EDGE"])
156 if theFaces[i] not in toAdd:
157 toAdd.append(theFaces[i])
159 logging.debug(" --- add %s", theFaces[i])
161 for k in sorted(toRemove, reverse=True):
163 theShell = geompy.MakeShell(aShell)
164 name = "theShell%d"%len(shells)
165 geomPublish(initLog.debug, theShell,name)
166 shells.append(theShell)
169 for aShell in shells: # --- trouver le shell en contact avec la fissure
170 distances.append(geompy.MinDistance(aShell, shapeDefaut))
171 minDist = min(distances)
172 for index in range(len(distances)):
173 if distances[index] == minDist:
175 theShellDefaut = shells[index]
177 else: # --- une seule face de defaut
178 subFaces = [facesDefaut]
179 theShellDefaut = geompy.MakeShell(subFaces)
181 geomPublish(initLog.debug, theShellDefaut,"theShellDefaut")
183 theFaces = geompy.ExtractShapes(theShellDefaut, geompy.ShapeType["FACE"], True)
185 for aFace in theFaces:
186 distances.append(geompy.MinDistance(aFace, centreSphere))
187 minDist = min(distances)
188 for index in range(len(distances)):
189 if distances[index] == minDist:
192 centreDefaut = geompy.MakeProjection(centreSphere, theFaces[index])
194 geomPublish(initLog.debug, centreDefaut, "centreDefaut")
195 normalDefaut = geompy.GetNormal(subFaces[index], centreDefaut)
197 geomPublish(initLog.debug, normalDefaut, "normalDefaut")
198 extrusionDefaut = geompy.MakePrismVecH(theShellDefaut, normalDefaut, -lgExtrusion)
199 info = geompy.ShapeInfo(extrusionDefaut)
200 logging.debug("shape info %s", info)
201 if (info['SOLID'] > 1) or (info['COMPOUND'] > 0) :
202 solids = geompy.ExtractShapes(extrusionDefaut, geompy.ShapeType["SOLID"], True)
204 for i in range(1,len(solids)):
205 solid0 = geompy.MakeFuse(solid0, solids[i])
206 extrusionDefaut = solid0
208 geomPublish(initLog.debug, extrusionDefaut, "extrusionDefaut")
210 return facesDefaut, centreDefaut, normalDefaut, extrusionDefaut