main
John Lauer MCP2562FD-E/SN component page: batch 2 2069f2d 2d ago
#!/usr/bin/env python3
"""Lead profile comparison: section through pin 1's centre line (y = +1.905 in the 3D frame) of two STEPs, with the
0.25 mm gauge plane and each model's gauge-plane foot L marked. usage: lead_compare.py a.step labelA b.step labelB out.png"""
import sys, cadquery as cq
import matplotlib; matplotlib.use("Agg"); import matplotlib.pyplot as plt
from OCP.BRepAlgoAPI import BRepAlgoAPI_Section
from OCP.gp import gp_Pln, gp_Pnt, gp_Dir
def prof(path):
    s = cq.Compound.makeCompound(cq.importers.importStep(path).solids().vals())
    sec = BRepAlgoAPI_Section(s.wrapped, gp_Pln(gp_Pnt(0, 1.905, 0), gp_Dir(0, 1, 0))); sec.Build(); p = cq.Shape.cast(sec.Shape())
    g = BRepAlgoAPI_Section(p.wrapped, gp_Pln(gp_Pnt(0, 0, 0.25), gp_Dir(0, 0, 1))); g.Build()
    xs = sorted(v.X for v in cq.Shape.cast(g.Shape()).Vertices() if v.X < 0)
    tip = p.BoundingBox().xmin
    return [[(q.x, q.z) for q in e.positions([i / 24 for i in range(25)])] for e in p.Edges()], tip, xs[0] - tip
fig, axs = plt.subplots(1, 2, figsize=(11, 4.2), dpi=120)
for ax, (path, lab) in zip(axs, [(sys.argv[1], sys.argv[2]), (sys.argv[3], sys.argv[4])]):
    edges, tip, L = prof(path)
    for e in edges: ax.plot([p[0] for p in e], [p[1] for p in e], color="#222", lw=1.2)
    ax.axhline(0.25, color="#d9822b", ls="--", lw=0.8); ax.axhline(0, color="#888", lw=0.6)
    ax.annotate("", (tip, 0.33), (tip + L, 0.33), arrowprops=dict(arrowstyle="<->", color="#00807a"))
    ax.text(tip + L / 2, 0.38, f"L = {L:.3f} mm", ha="center", color="#00807a", fontsize=9)
    ax.set_xlim(-3.1, -1.4); ax.set_ylim(-0.1, 1.85); ax.set_aspect("equal"); ax.grid(alpha=0.2)
    ax.set_title(lab, fontsize=9)
fig.suptitle("Pin 1 lead, section through its centre line; dashed: 0.25 mm gauge plane. Microchip C04-00057-SN: L 0.40 to 1.27 mm", fontsize=9)
fig.savefig(sys.argv[5], bbox_inches="tight"); print(sys.argv[5])