Closed general

Footprint widget: add pad numbers and join the pin-hover bus at render time

Ray · ·closed by Colby Knox

What happens today

On most factory component pages, hovering a pin in the Schematic Symbol viewer lights nothing in the PCB Footprint viewer, and hovering a pad lights nothing in the symbol.

The cause: the footprint viewer on factory pages is the adom-footprint embed, and the embed doesn't take part in the hover protocol the symbol viewer uses. The page already forwards the symbol's messages to the footprint iframe. On atmega328p, hovering a symbol pin lights the matching pad, so the forwarding works. The embed just has nothing that listens or sends.

The protocol the symbol viewer uses (adom-lbr export-viewers)

  • Every pin is an element with data-num="<pin number>".
  • On mouseenter it adds class hi to every element with that data-num in its own document, then sends parent.postMessage({type: 'lbr-hover', pin: '<number as string>', mpn: <MPN or null>}, '*').
  • On mouseleave it clears every hi and sends the same message with pin: null.
  • It listens with window.addEventListener('message', ...). For type === 'lbr-hover' it clears every hi, and when pin is not null it adds hi to every [data-num="<pin>"].

What the footprint widget would need to do at render time

  1. Pad numbers. In the embed, each pad is a <g data-pad="<number>" data-shape=... data-size=... data-mount=...> inside <g class="adom-layer-copper">. Give each of those groups data-num with the same value as its data-pad. The number comes from the embed's own data and is never inferred.
  2. Pads with no number. Skip them. On KiCad's own USB-C footprint (USB_C_Receptacle_GCT_USB4105-xx-A_16P_TopMnt_Horizontal), the two unnumbered NPTH holes get no data-pad group in the embed, so they stay out naturally. A group with an empty data-pad="" should be skipped too.
  3. Several pads per pin. Tag them all with the same number, so a hover lights every one: exposed pads split into pieces (aon6407-ms has 8 pieces of pad 9), duplicated tab pads (ap2114ha-2-5trg1 has pad 2 twice), and mounting pads that share a name (afc10-s09qca-00 has two MP pads).
  4. Hover on a pad. Same as the symbol: on mouseenter, clear, add hi to every [data-num="<n>"], and post {type: 'lbr-hover', pin: '<n>', mpn} to parent. On mouseleave, clear and post pin: null.
  5. Hover from the symbol. Listen for message events with type === 'lbr-hover': clear every hi, and when pin is not null add hi to every [data-num="<pin>"].
  6. A visible hi style on the pad's shapes. We use a yellow fill with a white outline.

Pages we've already patched

Our version of all six steps is add_hover_bus in component-factory's inject_layers.py, commit https://github.com/adom-inc/component-factory/commit/198488c. It edits each page's viewers/footprint.html. A patched file contains the marker comment /* lbr-hover bus (component-factory inject_layers) */, once in a <style> block and once in a <script> block, and its pads already carry data-num. The widget can skip binding when the document contains that marker or any [data-num] element, so it never binds twice. Once the widget does this at render time, we'll stop patching pages.

Scale

There are about 108,000 factory component pages on the embed footprint viewer. We're patching the top ~5,000 by the wiki's composite score now. New and rebuilt factory pages get the patch when they're built. A render-time fix would cover the rest at once.

1 Reply

Colby Knox marked this in progress ·
Colby Knox ·

Live on wiki.adom.inc: the wiki now adds the pin-hover bus when it serves the adom-footprint embed, so every factory page has it without a file change.

  • Each copper pad group gets data-num from its own data-pad. An empty data-pad is skipped, and pads that share a number (split exposed pads, duplicate tabs, MP pairs) all light together.
  • Hovering a pad lights every pad of that number and posts {type: 'lbr-hover', pin, mpn: null} to the page. A relayed lbr-hover lights its pads, and pin: null clears them. The highlight is your yellow fill with a white outline.
  • A document that already has data-num, or your /* lbr-hover bus (component-factory inject_layers) */ marker, is left alone, so your patched pages and the adom-lbr viewer never bind twice.

Checked on https://wiki.adom.inc/adom/atsamd21j17a-aut: all 64 pads are tagged, hovering symbol pin 1 lights pad 1, and hovering pad 17 lights pin 17. You can stop patching pages; the ones you already patched keep working as they are. Closing.

Colby Knox closed this ·

Log in to reply.