← Commit history

Delete kicad/tools/passive-symbols/build_pages.py

John Lauer ·48c93d0dea ·2d ago ·parent dd428dc
1 file changed −156
kicad/tools/passive-symbols/build_pages.pydeleted−156
@@ -1,156 +0,0 @@-#!/usr/bin/env python3-"""Put the L1 / C1 / D1 outline symbols on their wiki component pages (working copies under-/home/adom/project/page-work/sym3/<slug>), the way adom/tps54202ddcr was done:-  - the page's symbol file replaced by the project symbol (page footprint / Rating fields kept)-  - viewers/symbol.html from `adom-symbol embed`, patched to speak the lbr-hover bus-  - artwork/<MPN>-3d-outline-*.svg + artwork/<MPN>-thumbs.json (adom/chip-artwork-cache@1)-  - page.json component.viewers.symbol-README edits are done separately (by hand) so the prose reads right on each page.-"""-import copy, datetime, hashlib, json, os, re, shutil, subprocess, sys-HERE = os.path.dirname(os.path.abspath(__file__))-KI = os.path.normpath(os.path.join(HERE, "..", ".."))-sys.path.insert(0, KI)-import sexp-from sexp import Sym as S--W = "/home/adom/project/page-work/sym3"-O = os.path.join(HERE, "outlines")-NOW = datetime.datetime.now(datetime.timezone.utc).isoformat()---def sha(p):-    return hashlib.sha256(open(p, "rb").read()).hexdigest()---PAGES = [-    dict(slug="amplh5030s-150mt", owner="john", mpn="AMPLH5030S-150MT", tag="named180",-         package="SMD molded 5.7 x 5.3 x 2.8 mm (AMPLH5030S)",-         source="AMPLH5030S-150MT.step", display="amplh5030s-150mt.glb", mark=None,-         endpoint="POST /outline?upAxis=y (plain) + POST /outline?upAxis=y&name=AMPLH5030S&suffix=-named&rot=180; "-                  "the raised AMPLH5030S letters of the Abracon print are dropped from the plain outline and the flat name polylines added",-         sourceUpAxis="y", sourceToDisplay="rotate +90 deg about X, then lift 0.05 mm (terminals reach 0.05 mm below the STEP origin)",-         text="AMPLH5030S",-         placement="flat white text on the top, centred on the line of Abracon's printed AMPLH5030S mark in the STEP and reading the same way (upside down to the iso camera); the print's raised letters are replaced, not doubled",-         manufacturerMarking=True,-         markingReview="the Abracon STEP already prints AMPLH5030S on the top, so no virtual mark was etched; the outline shows that print once, redrawn as flat text at the same place and direction",-         generatedBy="service-step2glb /outline (OpenCascade HLR) of the Abracon STEP: plain outline with the raised print removed, plus the service's flat AMPLH5030S at rot 180 (tools/passive-symbols/l1_compose.py on john/buck-12v5v-molecule)",-         hintsRegen="Regenerate only if AMPLH5030S-150MT.step changes."),-    dict(slug="eee-fk1v470p", owner="john", mpn="EEE-FK1V470P", tag="named270",-         package="SMD aluminium electrolytic, case D (6.3 x 5.8 mm)",-         source="EEE-FK1V470P.step", display="eee-fk1v470p.glb", mark="EEE-FK1V470P-etched.step",-         endpoint="POST /outline?upAxis=y&name=EEE-FK1V470P&suffix=-named&rot=270",-         sourceUpAxis="y", sourceToDisplay="rotate +90 deg about X, then 180 deg about Z (+ terminal on footprint pad 1)",-         text="EEE-FK1V470P",-         placement="flat white text on the silver field of the can top, along the black minus stripe, reading from the + side; same side and direction as EEE-FK1V470P-etched.step",-         manufacturerMarking=False,-         markingReview="one marking, same side and direction as the etched STEP",-         generatedBy="service-step2glb /outline (OpenCascade HLR) from the bare STEP, part number as flat text at rot 270",-         hintsRegen="Regenerate only if EEE-FK1V470P.step or the etch changes."),-    dict(slug="in-s63btg", owner="adom", mpn="IN-S63BTG", tag="",-         package="0603",-         source="IN-S63BTG.step", display="IN-S63BTG.glb", mark="IN-S63BTG.step",-         endpoint="POST /outline?upAxis=z (plain outline of the side-etched STEP, no name option)",-         sourceUpAxis="z", sourceToDisplay="identity (the STEP is Z-up and seated on z = 0)",-         text="IN-S63BTG",-         placement="the MPN is etched on the -Y side wall of the lens block (provenance/IN-S63BTG-etch.report.json), which faces away from the iso camera, so the outline shows no text; the top and the lens window stay clear and no name was added on top",-         manufacturerMarking=False,-         markingReview="no marking visible in the outline: the side etch is on the far wall; never a name across the lens",-         generatedBy="service-step2glb /outline (OpenCascade HLR) of the side-etched STEP, no name",-         hintsRegen="Regenerate only if IN-S63BTG.step changes. A view of the -Y wall needs a yaw option on /outline (it has none today)."),-]-STYLES = [("symbol", "ink-heavy", "Schematic ink"), ("teal", "teal", "Teal"), ("blueprint", "blueprint", "Blueprint"),-          ("dark", "dark", "Dark ink")]--PATCH_FN = """  // lbr-hover bus (same contract as adom-lbr's footprint and 3D viewers): post the hovered pin to the-  // page, and light a pin when another viewer posts one, so symbol and footprint highlight together.-  function lbrPost(n){ try{ parent.postMessage({type:'lbr-hover', pin:n==null?null:String(n), mpn:(PINS&&PINS.mpn)||document.title}, '*'); }catch(_){} }-  window.addEventListener('message', function(e){ var d=e.data||{}; if(d.type!=='lbr-hover') return;-    var q=d.pin==null?null:PINS.filter(function(x){ return String(x.number)===String(d.pin); })[0];-    if(q) highlightPin(q); else if(typeof clearHL==='function') clearHL(); });-"""---def patch_embed(html):-    a = "  function highlightPin(p){"-    assert html.count(a) == 1, "highlightPin anchor"-    html = html.replace(a, PATCH_FN + a)-    e = "highlightPin(p); },\n      move:"-    assert html.count(e) == 1, "enter anchor"-    html = html.replace(e, "highlightPin(p); lbrPost(p.number); },\n      move:")-    l = "hideT=setTimeout(hideTip,45); }"-    assert html.count(l) == 1, "leave anchor"-    html = html.replace(l, "hideT=setTimeout(hideTip,45); lbrPost(null); }")-    return html---projlib = sexp.parse(open(os.path.join(KI, "lib", "buck12v5v.kicad_sym"), encoding="utf-8").read())-projsyms = {e[1]: e for e in projlib if isinstance(e, list) and e and e[0] == "symbol"}-for P in PAGES:-    d = os.path.join(W, P["slug"])-    pj = json.load(open(os.path.join(d, "page.json")))-    comp = pj["component"]-    symfile = comp["parts"]["symbol"]-    old = sexp.parse(open(os.path.join(d, symfile), encoding="utf-8").read())-    oldsym = sexp.first(old, "symbol")-    oldprops = {p[1]: p[2] for p in sexp.find(oldsym, "property")}-    sym = copy.deepcopy(projsyms[P["mpn"]])-    props = sexp.find(sym, "property")-    for p in props:-        if p[1] == "Footprint":-            p[2] = oldprops.get("Footprint", p[2])     # the page's own footprint library name-        if p[1] == "Adom_Chip_Outline":-            p[2] = f"artwork/{P['mpn']}-3d-outline-dark{'-' + P['tag'] if P['tag'] else ''}.svg"-    if "Rating" in oldprops:-        i = max(i for i, e in enumerate(sym) if isinstance(e, list) and e and e[0] == "property")-        sym.insert(i + 1, [S("property"), "Rating", oldprops["Rating"], [S("at"), S("0"), S("-14"), S("0")],-                           [S("effects"), [S("font"), [S("size"), S("1.27"), S("1.27")]], [S("hide"), S("yes")]]])-    lib = [S("kicad_symbol_lib"), [S("version"), 20231120], [S("generator"), "adom"], sym]-    open(os.path.join(d, symfile), "w", encoding="utf-8").write(sexp.dump(lib) + "\n")-    os.makedirs(os.path.join(d, "viewers"), exist_ok=True)-    vh = os.path.join(d, "viewers", "symbol.html")-    subprocess.run(["adom-symbol", "embed", "--file", os.path.join(d, symfile), "--out", vh], check=True,-                   stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)-    html = patch_embed(open(vh).read())-    open(vh, "w").write(html)-    comp.setdefault("viewers", None)-    comp["viewers"] = dict(comp["viewers"] or {}, symbol="viewers/symbol.html")-    json.dump(pj, open(os.path.join(d, "page.json"), "w"), indent=2, ensure_ascii=False)-    # artwork cache-    ad = os.path.join(d, "artwork")-    os.makedirs(ad, exist_ok=True)-    assets = []-    for style, src_style, label in STYLES:-        suffix = f"-{P['tag']}" if P["tag"] else ""-        name = f"{P['mpn']}-3d-outline-{src_style}{suffix}.svg"-        shutil.copy(os.path.join(O, name), os.path.join(ad, name))-        vb = re.search(r'viewBox="0 0 (\d+) (\d+)"', open(os.path.join(ad, name)).read())-        assets.append({"kind": "chip-outline", "format": "svg", "style": style, "label": label, "path": f"artwork/{name}",-                       "sha256": sha(os.path.join(ad, name)), "sizeBytes": os.path.getsize(os.path.join(ad, name)),-                       "width": int(vb.group(1)), "height": int(vb.group(2)), "transparent": True})-    recipe = {"schema": "adom/chip-artwork-cache@1", "sourceStepSha256": sha(os.path.join(d, P["source"])),-              "displayGlbSha256": sha(os.path.join(d, P["display"]))}-    if P["mark"]:-        recipe["markStepSha256"] = sha(os.path.join(d, P["mark"]))-    recipe.update({"endpoint": P["endpoint"], "pose": "iso", "upAxis": "Z", "sourceUpAxis": P["sourceUpAxis"],-                   "sourceToDisplayMm": P["sourceToDisplay"]})-    src = {"step": P["source"], "displayGlb": P["display"]}-    if P["mark"]:-        src["markStep"] = P["mark"]-    man = {"schema": "adom/chip-artwork-cache@1", "mpn": P["mpn"], "package": P["package"], "upAxis": "z", "units": "mm",-           "cacheKey": hashlib.sha256(json.dumps(recipe, sort_keys=True).encode()).hexdigest(),-           "source": src,-           "marking": {"text": P["text"], "placement": P["placement"], "manufacturerMarking": P["manufacturerMarking"]},-           "recipe": recipe,-           "review": {"orientation": "Z-up display, iso pose (the service's standard camera); native seating and pin 1 are checked separately",-                      "markingPlacement": P["markingReview"] + "; matches the symbol on john/buck-12v5v-molecule",-                      "projectedArtwork": f"Visually reviewed {NOW[:10]}: rendered on #0d1117 with headless Chrome and in the native KiCad 10 schematic export"},-           "verification": {"status": "matched-at-publication", "checkedAtIso": NOW,-                            "checks": ["Live source STEP hash", "Live displayed GLB hash", "All cached asset hashes"],-                            "notContinuous": True},-           "assets": assets,-           "hints": ["Reuse these outlines for symbols (adom-symbol --outline-svg ... --outline-name none); do not add a second name.",-                     P["hintsRegen"]],-           "generatedBy": P["generatedBy"], "generatedAtIso": NOW}-    json.dump(man, open(os.path.join(ad, f"{P['mpn']}-thumbs.json"), "w"), indent=1)-    print(P["slug"], symfile, "->", [a["path"] for a in assets])