mirror of
https://github.com/jdegenstein/jmwright-CQ-Editor.git
synced 2025-12-19 22:24:19 +01:00
Update cq_utils.py to bring up to date with Mainline a2df6ff
This commit is contained in:
@@ -9,10 +9,14 @@ from OCP.XCAFPrs import XCAFPrs_AISObject
|
||||
from OCP.TopoDS import TopoDS_Shape
|
||||
from OCP.AIS import AIS_InteractiveObject, AIS_Shape
|
||||
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
|
||||
|
||||
DEFAULT_FACE_COLOR = Quantity_Color(GOLD)
|
||||
DEFAULT_MATERIAL = Graphic3d_MaterialAspect(Graphic3d_NOM_JADE)
|
||||
|
||||
def find_cq_objects(results : dict):
|
||||
|
||||
return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if isinstance(v,cq.Workplane)}
|
||||
@@ -30,7 +34,7 @@ def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.
|
||||
elif isinstance(obj,list) and isinstance(obj[0],cq.Shape):
|
||||
vals.extend(obj)
|
||||
elif isinstance(obj, TopoDS_Shape):
|
||||
vals.append(cq.Shape.cast(obj))
|
||||
vals.append(cq.Shape.cast(obj))
|
||||
elif isinstance(obj,list) and isinstance(obj[0],TopoDS_Shape):
|
||||
vals.extend(cq.Shape.cast(o) for o in obj)
|
||||
elif hasattr(obj, "wrapped") and isinstance(obj.wrapped, TopoDS_Shape):
|
||||
@@ -68,14 +72,17 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
|
||||
shape = to_compound(obj)
|
||||
ais = AIS_Shape(shape.wrapped)
|
||||
|
||||
set_material(ais, DEFAULT_MATERIAL)
|
||||
set_color(ais, DEFAULT_FACE_COLOR)
|
||||
|
||||
if 'alpha' in options:
|
||||
ais.SetTransparency(options['alpha'])
|
||||
set_transparency(ais, options['alpha'])
|
||||
if 'color' in options:
|
||||
ais.SetColor(to_occ_color(options['color']))
|
||||
set_color(ais, to_occ_color(options['color']))
|
||||
if 'rgba' in options:
|
||||
r,g,b,a = options['rgba']
|
||||
ais.SetColor(to_occ_color((r,g,b)))
|
||||
ais.SetTransparency(a)
|
||||
set_color(ais, to_occ_color((r,g,b)))
|
||||
set_transparency(ais, a)
|
||||
|
||||
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:
|
||||
|
||||
drawer = ais.Attributes()
|
||||
drawer.SetupOwnShadingAspect()
|
||||
drawer.ShadingAspect().SetColor(color)
|
||||
|
||||
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():
|
||||
|
||||
# NB: order of reloads is important
|
||||
|
||||
Reference in New Issue
Block a user