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