Update cq_utils.py to bring up to date with Mainline a2df6ff

This commit is contained in:
jdegenstein
2022-10-27 14:50:32 -05:00
committed by GitHub
parent ca706045ba
commit 10a81d4e12

View File

@@ -9,10 +9,14 @@ from OCP.XCAFPrs import XCAFPrs_AISObject
from OCP.TopoDS import TopoDS_Shape from OCP.TopoDS import TopoDS_Shape
from OCP.AIS import AIS_InteractiveObject, AIS_Shape from OCP.AIS import AIS_InteractiveObject, AIS_Shape
from OCP.Quantity import \ from OCP.Quantity import \
Quantity_TOC_RGB as TOC_RGB, Quantity_Color Quantity_TOC_RGB as TOC_RGB, Quantity_Color, Quantity_NOC_GOLD as GOLD
from OCP.Graphic3d import Graphic3d_NOM_JADE, Graphic3d_MaterialAspect
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
DEFAULT_FACE_COLOR = Quantity_Color(GOLD)
DEFAULT_MATERIAL = Graphic3d_MaterialAspect(Graphic3d_NOM_JADE)
def find_cq_objects(results : dict): def find_cq_objects(results : dict):
return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if isinstance(v,cq.Workplane)} return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if isinstance(v,cq.Workplane)}
@@ -68,14 +72,17 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
shape = to_compound(obj) shape = to_compound(obj)
ais = AIS_Shape(shape.wrapped) ais = AIS_Shape(shape.wrapped)
set_material(ais, DEFAULT_MATERIAL)
set_color(ais, DEFAULT_FACE_COLOR)
if 'alpha' in options: if 'alpha' in options:
ais.SetTransparency(options['alpha']) set_transparency(ais, options['alpha'])
if 'color' in options: if 'color' in options:
ais.SetColor(to_occ_color(options['color'])) set_color(ais, to_occ_color(options['color']))
if 'rgba' in options: if 'rgba' in options:
r,g,b,a = options['rgba'] r,g,b,a = options['rgba']
ais.SetColor(to_occ_color((r,g,b))) set_color(ais, to_occ_color((r,g,b)))
ais.SetTransparency(a) set_transparency(ais, a)
return ais,shape return ais,shape
@@ -122,10 +129,27 @@ def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape: def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
drawer = ais.Attributes() drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
drawer.ShadingAspect().SetColor(color) drawer.ShadingAspect().SetColor(color)
return ais return ais
def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Shape:
drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
drawer.ShadingAspect().SetMaterial(material)
return ais
def set_transparency(ais : AIS_Shape, alpha: float) -> AIS_Shape:
drawer = ais.Attributes()
drawer.SetupOwnShadingAspect()
drawer.ShadingAspect().SetTransparency(alpha)
return ais
def reload_cq(): def reload_cq():
# NB: order of reloads is important # NB: order of reloads is important