bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
78 stars 9 forks source link

build123d will remove to_tuple from Color => adapt get_rgba function #69

Open bernhard-42 opened 3 months ago

bernhard-42 commented 3 months ago
def get_rgba(color, alpha=None, def_color=None):
    color = def_color if color is None else color

    if hasattr(color, "toTuple"):  # CadQery Color
        *rgb, a = color.toTuple()

    elif hasattr(color, "percentage"):  # Alg123d Color
        rgb, a = color.percentage, color.a

    elif hasattr(color, "to_tuple"):  # Build123d
        *rgb, a = color.to_tuple()

    elif isinstance(color, Quantity_ColorRGBA):  # OCP
        ocp_rgb = color.GetRGB()
        rgb = (ocp_rgb.Red(), ocp_rgb.Green(), ocp_rgb.Blue())
        a = color.Alpha()

    elif isinstance(color, str) or isinstance(color, (tuple, list)):
        col = Color(color)
        rgb, a = col.percentage, col.a
    else:
        raise ValueError(f"Unknown color input {color} ({type(color)}")        

Add

elif isintance(color, Iterable):
    *rgb, a = list(color)

or so ...