controle_python

This commit is contained in:
GERALD NICOLAS 2021-03-31 09:18:32 +02:00
parent be0d884bdf
commit 71de383cb6

View File

@ -17,6 +17,7 @@
# #
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
# #
"""Zone de défaut, constructions géométrique avec CAO d'origine"""
import logging import logging
from .geomsmesh import geompy from .geomsmesh import geompy
@ -25,9 +26,6 @@ from .geomsmesh import geomPublishInFather
from . import initLog from . import initLog
from .prolongeVertices import prolongeVertices from .prolongeVertices import prolongeVertices
# -----------------------------------------------------------------------------
# --- zone de defaut, constructions geometrique avec CAO d'origine
def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoyen, lgExtrusion=50): def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoyen, lgExtrusion=50):
""" """
Construction CAO de la zone à remailler, quand on utilise la CAO d'origine, Construction CAO de la zone à remailler, quand on utilise la CAO d'origine,
@ -46,14 +44,14 @@ def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoye
logging.info("start") logging.info("start")
trace = True trace = True
faces = [] faces = list()
curves = [] curves = list()
cdgs = [] cdgs = list()
projs = [] projs = list()
normals = [] normals = list()
extrusions = [] extrusions = list()
partitions = [] partitions = list()
decoupes = [] decoupes = list()
for ishape, vertices in enumerate(verticesShapes): for ishape, vertices in enumerate(verticesShapes):
aShape = origShapes[ishape] aShape = origShapes[ishape]
@ -106,7 +104,6 @@ def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoye
if trace: if trace:
name="partition_%d"%aShape name="partition_%d"%aShape
geomPublish(initLog.debug, partition, name) geomPublish(initLog.debug, partition, name)
pass
# #
centreSphere = geompy.MakeCDG(shapeDefaut) centreSphere = geompy.MakeCDG(shapeDefaut)
@ -114,12 +111,12 @@ def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoye
ccurves = geompy.MakeCompound(curves) ccurves = geompy.MakeCompound(curves)
gravCenter = geompy.MakeCDG(ccurves) gravCenter = geompy.MakeCDG(ccurves)
geomPublish(initLog.debug, gravCenter, "cdg_curves") geomPublish(initLog.debug, gravCenter, "cdg_curves")
for i in range(len(partitions)): for indice, part in enumerate(partitions):
if trace: if trace:
logging.debug(" --- original shape %s", origShapes[i]) logging.debug(" --- original shape %s", origShapes[indice])
dists = [] dists = list()
facesToSort = [] facesToSort = list()
subFaces = geompy.ExtractShapes(partitions[i], geompy.ShapeType["FACE"], True) subFaces = geompy.ExtractShapes(part, geompy.ShapeType["FACE"], True)
for aFace in subFaces: for aFace in subFaces:
cdg = geompy.MakeCDG(aFace) cdg = geompy.MakeCDG(aFace)
distance = geompy.MinDistance(cdg, centreSphere) distance = geompy.MinDistance(cdg, centreSphere)
@ -127,70 +124,67 @@ def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoye
facesToSort.append(aFace) facesToSort.append(aFace)
if trace: if trace:
logging.debug("distance = %s", distance) logging.debug("distance = %s", distance)
pass
pass
if len(dists) > 0: if len(dists) > 0:
minDist = min(dists) minDist = min(dists)
for j,d in enumerate(dists): for j,d in enumerate(dists):
if d == minDist: if d == minDist:
aFace = facesToSort[j] aFace = facesToSort[j]
name="decoupe_%d"%origShapes[i] name="decoupe_%d"%origShapes[indice]
geomPublish(initLog.debug, aFace, name) geomPublish(initLog.debug, aFace, name)
decoupes.append(aFace) decoupes.append(aFace)
break break
pass
pass
facesDefaut = decoupes[0] facesDefaut = decoupes[0]
if len(decoupes) > 1: if len(decoupes) > 1:
facesDefaut = geompy.MakePartition(decoupes, [], [], [], geompy.ShapeType["FACE"], 0, [], 0) facesDefaut = geompy.MakePartition(decoupes, [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
geomPublish(initLog.debug, facesDefaut, "facesDefaut") geomPublish(initLog.debug, facesDefaut, "facesDefaut")
shells=[] shells = list()
if len(decoupes) > 1: # plusieurs faces de defaut if len(decoupes) > 1: # plusieurs faces de defaut
subFaces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True) subFaces = geompy.ExtractShapes(facesDefaut, geompy.ShapeType["FACE"], True)
# --- regroupe les subFaces en shells connectes # --- regroupe les subFaces en shells connectes
theFaces = list(subFaces) # copy theFaces = list(subFaces) # copy
while len(theFaces) > 0: while theFaces:
logging.debug("------- len(theFaces) %s" , len(theFaces)) logging.debug("------- len(theFaces) %s" , len(theFaces))
theFace = theFaces[0] theFace = theFaces[0]
logging.debug(" start with face %s",theFaces[0]) logging.debug(" start with face %s",theFaces[0])
theFaces[0:1] = [] theFaces[0:1] = list()
aShell = [theFace] aShell = [theFace]
toAdd =[theFace] toAdd =[theFace]
while len(toAdd) > 0: while toAdd:
toAdd = [] toAdd = list()
toRemove = [] toRemove = list()
for i in range(len(theFaces)): for indice, la_face in enumerate(theFaces):
logging.debug(" try %s", theFaces[i]) logging.debug(" try %s", la_face)
for aFace in aShell: for aFace in aShell:
logging.debug(" with %s", aFace) logging.debug(" with %s", aFace)
try: try:
edge = geompy.GetSharedShapesMulti([aFace, theFaces[i]], geompy.ShapeType["EDGE"]) _ = geompy.GetSharedShapesMulti([aFace, la_face], geompy.ShapeType["EDGE"])
edgeShared = True edgeShared = True
except: except:
edgeShared = False edgeShared = False
if edgeShared: if edgeShared:
if theFaces[i] not in toAdd: if la_face not in toAdd:
toAdd.append(theFaces[i]) toAdd.append(la_face)
toRemove.append(i) toRemove.append(indice)
logging.debug(" --- add %s", theFaces[i]) logging.debug(" --- add %s", la_face)
aShell += toAdd aShell += toAdd
for k in sorted(toRemove, reverse=True): for k in sorted(toRemove, reverse=True):
theFaces[k:k+1] = [] theFaces[k:k+1] = list()
theShell = geompy.MakeShell(aShell) theShell = geompy.MakeShell(aShell)
name = "theShell%d"%len(shells) name = "theShell%d"%len(shells)
geomPublish(initLog.debug, theShell,name) geomPublish(initLog.debug, theShell,name)
shells.append(theShell) shells.append(theShell)
# #
distances = [] distances = list()
for aShell in shells: # --- trouver le shell en contact avec la fissure for aShell in shells: # --- trouver le shell en contact avec la fissure
distances.append(geompy.MinDistance(aShell, shapeDefaut)) distances.append(geompy.MinDistance(aShell, shapeDefaut))
minDist = min(distances) minDist = min(distances)
for index in range(len(distances)): for indice, dist in enumerate(distances):
if distances[index] == minDist: if dist == minDist:
indice0 = indice
break break
theShellDefaut = shells[index] theShellDefaut = shells[indice0]
# #
else: # --- une seule face de defaut else: # --- une seule face de defaut
subFaces = [facesDefaut] subFaces = [facesDefaut]
@ -199,18 +193,19 @@ def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, dmoye
geomPublish(initLog.debug, theShellDefaut,"theShellDefaut") geomPublish(initLog.debug, theShellDefaut,"theShellDefaut")
theFaces = geompy.ExtractShapes(theShellDefaut, geompy.ShapeType["FACE"], True) theFaces = geompy.ExtractShapes(theShellDefaut, geompy.ShapeType["FACE"], True)
distances = [] distances = list()
for aFace in theFaces: for aFace in theFaces:
distances.append(geompy.MinDistance(aFace, centreSphere)) distances.append(geompy.MinDistance(aFace, centreSphere))
minDist = min(distances) minDist = min(distances)
for index in range(len(distances)): for indice, dist in enumerate(distances):
if distances[index] == minDist: if dist == minDist:
indice0 = indice
break break
centreDefaut = geompy.MakeProjection(centreSphere, theFaces[index]) centreDefaut = geompy.MakeProjection(centreSphere, theFaces[indice0])
if trace: if trace:
geomPublish(initLog.debug, centreDefaut, "centreDefaut") geomPublish(initLog.debug, centreDefaut, "centreDefaut")
normalDefaut = geompy.GetNormal(subFaces[index], centreDefaut) normalDefaut = geompy.GetNormal(subFaces[indice0], centreDefaut)
if trace: if trace:
geomPublish(initLog.debug, normalDefaut, "normalDefaut") geomPublish(initLog.debug, normalDefaut, "normalDefaut")
extrusionDefaut = geompy.MakePrismVecH(theShellDefaut, normalDefaut, -lgExtrusion) extrusionDefaut = geompy.MakePrismVecH(theShellDefaut, normalDefaut, -lgExtrusion)