component
EEE-FK1V470P
Public Unreviewedby John Lauer
Panasonic EEE-FK1V470P: 47 uF 20% 35 V SMD aluminium electrolytic capacitor, FK series, case size D (6.3 mm diameter x 5.8 mm).
main
John Lauer
Hero GLB per eda-component-hero: colour-preserving virtual MPN etch, footprint pad outlines, silkscreen and pad labels as nonphysical layers; marked STEP added as a variant; original STEP and board GLB unchanged; provenance
21c2966
6d ago
#!/usr/bin/env python3
"""Rigidly transform a STEP keeping colours and names (XCAF): the untouched shapes are wrapped in a new
assembly whose component location carries the transform. Rotations are about the ORIGIN, applied in
the order given, then the translation.
Usage: xcaf_transform.py in.step out.step [--rot x:-90] [--rot z:180] [--tr dx,dy,dz] (degrees, mm)"""
import sys, math, argparse
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
from OCP.gp import gp_Trsf, gp_Ax1, gp_Pnt, gp_Dir, gp_Vec
from OCP.TopLoc import TopLoc_Location
from OCP.Bnd import Bnd_Box
from OCP.BRepBndLib import BRepBndLib
ap = argparse.ArgumentParser(); ap.add_argument('src'); ap.add_argument('out')
ap.add_argument('--rot', action='append', default=[]); ap.add_argument('--tr', default='0,0,0')
a = ap.parse_args()
doc = TDocStd_Document(TCollection_ExtendedString("doc"))
r = STEPCAFControl_Reader(); r.SetColorMode(True); r.SetNameMode(True); r.SetLayerMode(True)
assert r.ReadFile(a.src) == 1; r.Transfer(doc)
st = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
labs = []
it = TDF_ChildIterator(st.Label(), False)
while it.More():
l = it.Value(); it.Next()
if st.IsFree_s(l) and st.IsTopLevel(l): labs.append(l)
T = gp_Trsf()
for spec in a.rot:
ax, deg = spec.split(':'); d = {"x": gp_Dir(1,0,0), "y": gp_Dir(0,1,0), "z": gp_Dir(0,0,1)}[ax]
R = gp_Trsf(); R.SetRotation(gp_Ax1(gp_Pnt(0,0,0), d), math.radians(float(deg)))
T = R.Multiplied(T)
dx, dy, dz = map(float, a.tr.split(',')); M = gp_Trsf(); M.SetTranslation(gp_Vec(dx, dy, dz)); T = M.Multiplied(T)
asm = st.NewShape()
for lab in labs: st.AddComponent(asm, lab, TopLoc_Location(T))
st.UpdateAssemblies()
b = Bnd_Box(); BRepBndLib.Add_s(st.GetShape_s(asm), b); mn, mx = b.CornerMin(), b.CornerMax()
w = STEPCAFControl_Writer(); w.SetColorMode(True); w.SetNameMode(True); w.SetLayerMode(True)
w.Transfer(doc, STEPControl_AsIs); w.Write(a.out)
print(f"free shapes {len(labs)}; out bbox x {mn.X():.3f}..{mx.X():.3f} y {mn.Y():.3f}..{mx.Y():.3f} z {mn.Z():.3f}..{mx.Z():.3f}")