by adom
2020 Addressable RGB LED · 800 Kbps single-line cascade · 16 mA per channel (V1.0 sheet), 12 mA from V1.2
master
#!/usr/bin/env python3
"""Name the wrapper assemblies the etch rotations leave behind ('Open CASCADE STEP translator ...') and put the
provenance comment back in the STEP header. Geometry, colours and part names unchanged.
Usage: finish_step.py in.step out.step"""
import sys
from OCP.STEPCAFControl import STEPCAFControl_Reader, STEPCAFControl_Writer
from OCP.STEPControl import STEPControl_AsIs
from OCP.TDocStd import TDocStd_Document
from OCP.TCollection import TCollection_ExtendedString
from OCP.XCAFDoc import XCAFDoc_DocumentTool
from OCP.TDF import TDF_ChildIterator, TDF_Label
from OCP.TDataStd import TDataStd_Name
src, out = sys.argv[1:3]
doc = TDocStd_Document(TCollection_ExtendedString("d")); r = STEPCAFControl_Reader(); r.SetColorMode(True); r.SetNameMode(True); r.SetLayerMode(True)
assert r.ReadFile(src) == 1; r.Transfer(doc)
st = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
def nm(l):
n = TDataStd_Name(); return n.Get().ToExtString() if l.FindAttribute(TDataStd_Name.GetID_s(), n) else ''
def setn(l, s): TDataStd_Name.Set_s(l, TCollection_ExtendedString(s))
names = {0: 'WS2812B-2020', 1: 'WS2812B-2020 package'}
def walk(l, depth):
if st.IsReference_s(l):
ref = TDF_Label(); st.GetReferredShape_s(l, ref)
if nm(l).startswith('=>'): setn(l, nm(ref) if not nm(ref).startswith('Open CASCADE') else names.get(depth, 'WS2812B-2020 package'))
walk(ref, depth); return
if nm(l).startswith('Open CASCADE') or (depth > 0 and nm(l) == 'WS2812B-2020'): setn(l, names.get(depth, 'WS2812B-2020 package'))
if st.IsAssembly_s(l):
it = TDF_ChildIterator(l, False)
while it.More(): c = it.Value(); it.Next(); walk(c, depth + 1)
it = TDF_ChildIterator(st.Label(), False)
while it.More():
l = it.Value(); it.Next()
if st.IsFree_s(l) and st.IsTopLevel(l): walk(l, 0)
wr = STEPCAFControl_Writer(); wr.SetColorMode(True); wr.SetNameMode(True); wr.SetLayerMode(True); wr.Transfer(doc, STEPControl_AsIs); assert wr.Write(out) == 1
hdr = ("/* WS2812B-2020 (Worldsemi) 3D model - AI-generated (Claude, Adom) from the WS2812B-2020 datasheet V1.0\n"
" (2018-07-25) p.1 Mechanical Dimensions and p.2 Side View / PIN Configuration, with OpenCascade (OCP).\n"
" Not a manufacturer model. Die patch positions are illustrative (the datasheet sketch is undimensioned).\n"
" laser_etch = virtual MPN mark on the -Y side of the white body (identification aid, not the real marking).\n"
" Pin 1 DO (-X,+Y), 2 GND (-X,-Y), 3 DI (+X,-Y), 4 VDD (+X,+Y); mm, Z up, seated on z = 0. */")
t = open(out, encoding='latin-1').read().replace('HEADER;', 'HEADER;\n' + hdr, 1); open(out, 'w', encoding='latin-1').write(t)