2014-01-09 14:20:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-03-23 17:44:27 +03:00
|
|
|
# Copyright (C) 2014-2021 EDF R&D
|
2019-02-14 14:55:47 +03:00
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
|
|
#
|
2021-03-31 09:18:32 +02:00
|
|
|
"""Zone de défaut, constructions géométrique avec CAO d'origine"""
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
import logging
|
2021-04-01 16:19:17 +02:00
|
|
|
from . import initLog
|
|
|
|
|
2017-03-20 13:27:30 +01:00
|
|
|
from .geomsmesh import geompy
|
|
|
|
from .geomsmesh import geomPublish
|
|
|
|
from .prolongeVertices import prolongeVertices
|
2014-01-09 14:20:44 +00:00
|
|
|
|
2021-04-01 16:19:17 +02:00
|
|
|
def creeZoneDefautGeom(objetSain, shapeDefaut, origShapes, verticesShapes, lgExtrusion=50):
|
|
|
|
"""Construction CAO de la zone à remailler, quand on utilise la CAO d'origine,apres appel creeZoneDefautMaillage
|
|
|
|
|
2014-01-09 14:20:44 +00:00
|
|
|
@param objetSain : la géometrie de l'objet initial
|
|
|
|
@param shapeDefaut : objet géometrique représentant la fissure
|
|
|
|
(selon les cas, un point central, ou une shape plus complexe,
|
|
|
|
dont on ne garde que les vertices)
|
|
|
|
@param origShapes : liste id subShapes
|
|
|
|
@param verticesShapes : listes noeuds de bord
|
|
|
|
@lgExtrusion : distance d'extrusion de la face du defaut
|
|
|
|
(ne vaut que pour des fissures courtes)
|
|
|
|
@return (facesDefaut, centreDefaut, normalDefaut, extrusionDefaut)
|
|
|
|
"""
|
|
|
|
logging.info("start")
|
|
|
|
|
|
|
|
trace = True
|
2021-03-31 09:18:32 +02:00
|
|
|
faces = list()
|
|
|
|
curves = list()
|
|
|
|
cdgs = list()
|
|
|
|
projs = list()
|
|
|
|
normals = list()
|
|
|
|
extrusions = list()
|
|
|
|
partitions = list()
|
|
|
|
decoupes = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
for ishape, vertices in enumerate(verticesShapes):
|
|
|
|
aShape = origShapes[ishape]
|
|
|
|
[face] = geompy.SubShapes(objetSain, [aShape])
|
|
|
|
faces.append(face)
|
|
|
|
curve = geompy.MakePolyline(vertices, False)
|
|
|
|
curves.append(curve)
|
|
|
|
if trace:
|
|
|
|
name="poly_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, curve, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
cdg = geompy.MakeCDG(curve)
|
|
|
|
cdgs.append(cdg)
|
|
|
|
if trace:
|
|
|
|
name="cdgpoly_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, cdg, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
projCdg = geompy.MakeProjection(cdg, face)
|
|
|
|
projs.append(projCdg)
|
|
|
|
if trace:
|
|
|
|
name="projCdg_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, projCdg, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
normal = geompy.GetNormal(face, projCdg)
|
|
|
|
normals.append(normal)
|
|
|
|
if trace:
|
|
|
|
name="normal_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, normal, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
extrusion = geompy.MakePrismVecH2Ways(curve, normal, 10)
|
|
|
|
extrusions.append(extrusion)
|
|
|
|
if trace:
|
|
|
|
name="extrusion_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, extrusion, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
verticesProlongees = prolongeVertices(vertices)
|
|
|
|
#
|
|
|
|
curveprol = geompy.MakePolyline(verticesProlongees, False)
|
|
|
|
if trace:
|
|
|
|
name="polyProl_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, curveprol, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
extruprol = geompy.MakePrismVecH2Ways(curveprol, normal, 10)
|
|
|
|
if trace:
|
|
|
|
name="extruProl_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, extruprol, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
partition = geompy.MakePartition([face], [extruprol], [], [], geompy.ShapeType["FACE"], 0, [], 0)
|
|
|
|
partitions.append(partition)
|
|
|
|
if trace:
|
|
|
|
name="partition_%d"%aShape
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, partition, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
centreSphere = geompy.MakeCDG(shapeDefaut)
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, centreSphere, "cdg_defaut")
|
2014-01-09 14:20:44 +00:00
|
|
|
ccurves = geompy.MakeCompound(curves)
|
|
|
|
gravCenter = geompy.MakeCDG(ccurves)
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, gravCenter, "cdg_curves")
|
2021-03-31 09:18:32 +02:00
|
|
|
for indice, part in enumerate(partitions):
|
2014-01-09 14:20:44 +00:00
|
|
|
if trace:
|
2021-03-31 09:18:32 +02:00
|
|
|
logging.debug(" --- original shape %s", origShapes[indice])
|
|
|
|
dists = list()
|
|
|
|
facesToSort = list()
|
|
|
|
subFaces = geompy.ExtractShapes(part, geompy.ShapeType["FACE"], True)
|
2014-01-09 14:20:44 +00:00
|
|
|
for aFace in subFaces:
|
|
|
|
cdg = geompy.MakeCDG(aFace)
|
|
|
|
distance = geompy.MinDistance(cdg, centreSphere)
|
|
|
|
dists.append(distance)
|
|
|
|
facesToSort.append(aFace)
|
|
|
|
if trace:
|
|
|
|
logging.debug("distance = %s", distance)
|
|
|
|
if len(dists) > 0:
|
|
|
|
minDist = min(dists)
|
|
|
|
for j,d in enumerate(dists):
|
|
|
|
if d == minDist:
|
|
|
|
aFace = facesToSort[j]
|
2021-03-31 09:18:32 +02:00
|
|
|
name="decoupe_%d"%origShapes[indice]
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, aFace, name)
|
2014-01-09 14:20:44 +00:00
|
|
|
decoupes.append(aFace)
|
|
|
|
break
|
|
|
|
|
|
|
|
facesDefaut = decoupes[0]
|
|
|
|
if len(decoupes) > 1:
|
|
|
|
facesDefaut = geompy.MakePartition(decoupes, [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, facesDefaut, "facesDefaut")
|
2014-01-09 14:20:44 +00:00
|
|
|
|
2021-03-31 09:18:32 +02:00
|
|
|
shells = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
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
|
2021-03-31 09:18:32 +02:00
|
|
|
while theFaces:
|
2014-01-09 14:20:44 +00:00
|
|
|
logging.debug("------- len(theFaces) %s" , len(theFaces))
|
|
|
|
theFace = theFaces[0]
|
|
|
|
logging.debug(" start with face %s",theFaces[0])
|
2021-03-31 09:18:32 +02:00
|
|
|
theFaces[0:1] = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
aShell = [theFace]
|
|
|
|
toAdd =[theFace]
|
2021-03-31 09:18:32 +02:00
|
|
|
while toAdd:
|
|
|
|
toAdd = list()
|
|
|
|
toRemove = list()
|
|
|
|
for indice, la_face in enumerate(theFaces):
|
|
|
|
logging.debug(" try %s", la_face)
|
2014-01-09 14:20:44 +00:00
|
|
|
for aFace in aShell:
|
|
|
|
logging.debug(" with %s", aFace)
|
|
|
|
try:
|
2021-03-31 09:18:32 +02:00
|
|
|
_ = geompy.GetSharedShapesMulti([aFace, la_face], geompy.ShapeType["EDGE"])
|
2014-01-09 14:20:44 +00:00
|
|
|
edgeShared = True
|
|
|
|
except:
|
|
|
|
edgeShared = False
|
|
|
|
if edgeShared:
|
2021-03-31 09:18:32 +02:00
|
|
|
if la_face not in toAdd:
|
|
|
|
toAdd.append(la_face)
|
|
|
|
toRemove.append(indice)
|
|
|
|
logging.debug(" --- add %s", la_face)
|
2014-01-09 14:20:44 +00:00
|
|
|
aShell += toAdd
|
|
|
|
for k in sorted(toRemove, reverse=True):
|
2021-03-31 09:18:32 +02:00
|
|
|
theFaces[k:k+1] = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
theShell = geompy.MakeShell(aShell)
|
|
|
|
name = "theShell%d"%len(shells)
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, theShell,name)
|
2014-01-09 14:20:44 +00:00
|
|
|
shells.append(theShell)
|
|
|
|
#
|
2021-03-31 09:18:32 +02:00
|
|
|
distances = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
for aShell in shells: # --- trouver le shell en contact avec la fissure
|
|
|
|
distances.append(geompy.MinDistance(aShell, shapeDefaut))
|
|
|
|
minDist = min(distances)
|
2021-03-31 09:18:32 +02:00
|
|
|
for indice, dist in enumerate(distances):
|
|
|
|
if dist == minDist:
|
2021-04-01 16:19:17 +02:00
|
|
|
theShellDefaut = shells[indice]
|
2014-01-09 14:20:44 +00:00
|
|
|
break
|
|
|
|
#
|
|
|
|
else: # --- une seule face de defaut
|
|
|
|
subFaces = [facesDefaut]
|
|
|
|
theShellDefaut = geompy.MakeShell(subFaces)
|
|
|
|
if trace:
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, theShellDefaut,"theShellDefaut")
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
theFaces = geompy.ExtractShapes(theShellDefaut, geompy.ShapeType["FACE"], True)
|
2021-03-31 09:18:32 +02:00
|
|
|
distances = list()
|
2014-01-09 14:20:44 +00:00
|
|
|
for aFace in theFaces:
|
|
|
|
distances.append(geompy.MinDistance(aFace, centreSphere))
|
|
|
|
minDist = min(distances)
|
2021-03-31 09:18:32 +02:00
|
|
|
for indice, dist in enumerate(distances):
|
|
|
|
if dist == minDist:
|
|
|
|
indice0 = indice
|
2014-01-09 14:20:44 +00:00
|
|
|
break
|
|
|
|
|
2021-03-31 09:18:32 +02:00
|
|
|
centreDefaut = geompy.MakeProjection(centreSphere, theFaces[indice0])
|
2014-01-09 14:20:44 +00:00
|
|
|
if trace:
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, centreDefaut, "centreDefaut")
|
2021-03-31 09:18:32 +02:00
|
|
|
normalDefaut = geompy.GetNormal(subFaces[indice0], centreDefaut)
|
2014-01-09 14:20:44 +00:00
|
|
|
if trace:
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, normalDefaut, "normalDefaut")
|
2014-01-09 14:20:44 +00:00
|
|
|
extrusionDefaut = geompy.MakePrismVecH(theShellDefaut, normalDefaut, -lgExtrusion)
|
|
|
|
info = geompy.ShapeInfo(extrusionDefaut)
|
|
|
|
logging.debug("shape info %s", info)
|
|
|
|
if (info['SOLID'] > 1) or (info['COMPOUND'] > 0) :
|
|
|
|
solids = geompy.ExtractShapes(extrusionDefaut, geompy.ShapeType["SOLID"], True)
|
|
|
|
solid0 = solids[0]
|
|
|
|
for i in range(1,len(solids)):
|
|
|
|
solid0 = geompy.MakeFuse(solid0, solids[i])
|
|
|
|
extrusionDefaut = solid0
|
|
|
|
if trace:
|
2014-12-11 15:45:06 +01:00
|
|
|
geomPublish(initLog.debug, extrusionDefaut, "extrusionDefaut")
|
2014-01-09 14:20:44 +00:00
|
|
|
|
|
|
|
return facesDefaut, centreDefaut, normalDefaut, extrusionDefaut
|