From 4ee59fdeb1283aef11a36046cf4af3b16ca91ac2 Mon Sep 17 00:00:00 2001 From: jdegenstein Date: Wed, 19 Oct 2022 13:15:49 -0500 Subject: [PATCH] Bring up to date with mainline CQ-editor ec81ad9 partial PR for cq_utils.py only --- cq_editor/cq_utils.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cq_editor/cq_utils.py b/cq_editor/cq_utils.py index e74cd82..0c30d94 100644 --- a/cq_editor/cq_utils.py +++ b/cq_editor/cq_utils.py @@ -7,7 +7,7 @@ from types import SimpleNamespace from OCP.XCAFPrs import XCAFPrs_AISObject from OCP.TopoDS import TopoDS_Shape -from OCP.AIS import AIS_InteractiveObject, AIS_Shape, AIS_ColoredShape +from OCP.AIS import AIS_InteractiveObject, AIS_Shape from OCP.Quantity import \ Quantity_TOC_RGB as TOC_RGB, Quantity_Color @@ -66,7 +66,7 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha ais = obj else: shape = to_compound(obj) - ais = AIS_ColoredShape(shape.wrapped) + ais = AIS_Shape(shape.wrapped) if 'alpha' in options: ais.SetTransparency(options['alpha']) @@ -109,13 +109,23 @@ def to_occ_color(color) -> Quantity_Color: color.blueF(), TOC_RGB) -def get_occ_color(ais : AIS_ColoredShape) -> QColor: - - color = Quantity_Color() - ais.Color(color) +def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor: + + if isinstance(obj, AIS_InteractiveObject): + color = Quantity_Color() + obj.Color(color) + else: + color = obj return QColor.fromRgbF(color.Red(), color.Green(), color.Blue()) +def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape: + + drawer = ais.Attributes() + drawer.ShadingAspect().SetColor(color) + + return ais + def reload_cq(): # NB: order of reloads is important