← Commit history

2.47.10: pin-name primes become _P (no false NAME@2); viewers draw KiCad overbars (#38 #39); GH 85d3b72

Colby Knox ·a120ed4ff8 · ·parent 1d410d4
11 files changed +94−12
CHANGELOG.md+4
@@ -1,5 +1,9 @@ # Changelog +## 2.47.10 (2026-11-10)+- `generate` keeps a prime in a pin name. `QH'` used to lose its prime, collide with `QH`, and come out as `QH@2`, which EAGLE and Fusion read as a second pad of `QH`, so the 74HC595's serial output was labelled QH. A prime that ends a name or a word (`'`, `ʼ`, `′`, `’`) now becomes `_P`: `QH'` is `QH_P`, `1ʼ` is `1_P`. An apostrophe inside a word, as in `X'tal`, is unchanged. When two different pin names still end up as one EAGLE name, `generate` prints `WARN: [pin-name-collision]`. (#38)+- The symbol viewer draws KiCad overbars: `~{1R}` shows as 1R with a bar over it instead of the markup. The viewer and Manager tooltips do the same. `data-name` keeps the raw name. (#39)+ ## 2.47.9 (2026-10-28) - A named non-plated pad that a symbol pin connects to (an `MP` pin on a mounting hole) stays a pad, with `WARN: [npth-wired]`. Under 2.47.8 it became a `<hole>`, so the pin's connect pointed at a pad that no longer existed and lint and validate failed. EAGLE connects pins to pads, never to holes. Every non-plated pad that no pin reaches is still a `<hole>`. (#36) 
Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-lbr"-version = "2.47.9"+version = "2.47.10" dependencies = [  "altium-codec",  "anyhow",
Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.47.9"+version = "2.47.10" edition = "2021" description = "adom-lbr generator / EDA translator: the canonical adom-lbr JSON is the hub, with native converters to Altium (.SchLib/.PcbLib/.IntLib), EAGLE/Fusion (.lbr), and KiCad. Altium output is written natively — no Altium needed at conversion time." 
VERSION+1−1
@@ -1 +1 @@-2.47.9+2.47.10
bin/adom-lbr
⋯ 1 unchanged line ⋯
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.9",+  "version": "2.47.10",   "type": "app",   "description": "adom-lbr \u2014 the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad \u21c4 Altium \u21c4 EAGLE/Fusion) through one canonical adom-lbr JSON \u2014 symbol + footprint + 3D + pin\u2194pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},
page.json+2−2
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.9",+  "version": "2.47.10",   "type": "app",   "description": "adom-lbr — the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad ⇄ Altium ⇄ EAGLE/Fusion) through one canonical adom-lbr JSON — symbol + footprint + 3D + pin↔pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},@@ -89,4 +89,4 @@       "label": "Browse parts"     }   ]-}\ No newline at end of file+}
src/main.rs+48−2
@@ -888,7 +888,17 @@ fn eagle_safe_name(name: &str) -> String {     };     let mut out = String::with_capacity(name.len());     let mut last_us = false;-    for ch in name.chars() {+    let chars: Vec<char> = name.chars().collect();+    for (i, &ch) in chars.iter().enumerate() {+        // A prime closing a name or a word (QH', 1ʼ, VDD′) is a different signal from the+        // name without it; dropping it made QH' collide with QH and dedup renamed it QH@2,+        // which EAGLE reads as a second pad of QH. It becomes a visible _P. An apostrophe+        // inside a word (X'tal) is not a prime and stays an ordinary illegal character.+        if is_prime(ch) && chars.get(i + 1).map_or(true, |n| !n.is_alphanumeric()) {+            out.push_str(if last_us { "P" } else { "_P" });+            last_us = false;+            continue;+        }         let ok = ch.is_ascii_alphanumeric() || matches!(ch, '_' | '+' | '-' | '.' | '/' | '!' | '@' | '$' | '#');         if ok { out.push(ch); last_us = false; }         else if !last_us { out.push('_'); last_us = true; }@@ -897,6 +907,12 @@ fn eagle_safe_name(name: &str) -> String {     if trimmed.is_empty() { "P".to_string() } else { trimmed } } +/// ASCII apostrophe, modifier-letter apostrophe, prime, and right single quote: the+/// four ways datasheets and KiCad symbols spell a prime.+fn is_prime(ch: char) -> bool {+    matches!(ch, '\'' | '\u{02BC}' | '\u{2032}' | '\u{2019}')+}+ /// `~{SS}` to `!SS!`; an unclosed group bars the rest of the name, which is /// what EAGLE's unclosed `!` does too. fn kicad_overbar_to_eagle(name: &str) -> String {@@ -936,9 +952,25 @@ fn dedup_pin_names(pins: &[KicadPin]) -> Vec<String> {             safe         } else {             let num = p.number.trim();-            if !num.is_empty() { num.to_string() } else { format!("P{}", i + 1) }+            if !num.is_empty() { eagle_safe_name(num) } else { format!("P{}", i + 1) }         }     }).collect();+    // Two pins whose DIFFERENT source names land on one EAGLE name would be renamed NAME@2,+    // which EAGLE reads as a second pad of one pin: the schematic then labels two different+    // signals alike. Repeats of one source name (GND, GND) are what @n is for.+    let mut origin: std::collections::HashMap<&str, &str> = std::collections::HashMap::new();+    let mut clashes: Vec<String> = Vec::new();+    for (p, e) in pins.iter().zip(&eff) {+        let raw = p.name.trim();+        match origin.get(e.as_str()) {+            Some(first) if *first != raw => clashes.push(format!("\"{first}\" and \"{raw}\" both become {e}")),+            Some(_) => {}+            None => { origin.insert(e.as_str(), raw); }+        }+    }+    if !clashes.is_empty() {+        eprintln!("WARN: [pin-name-collision] different pin names become one EAGLE name, so the second is written NAME@2 and reads as another pad of the first: {}. Rename one pin in the source symbol.", clashes.join("; "));+    }     let mut counts: std::collections::HashMap<String, u32> = std::collections::HashMap::new();     for n in &eff {         *counts.entry(n.clone()).or_insert(0) += 1;@@ -4771,6 +4803,20 @@ mod lost_feature_tests {         assert_eq!(eagle_safe_name("VCC"), "VCC", "names without overbars are untouched");     } +    #[test]+    fn a_prime_is_kept_as_p_so_qh_and_qh_prime_stay_two_pins() {+        assert_eq!(eagle_safe_name("QH'"), "QH_P");+        assert_eq!(eagle_safe_name("1\u{02BC}"), "1_P");+        assert_eq!(eagle_safe_name("VDD\u{2032}"), "VDD_P");+        assert_eq!(eagle_safe_name("Q1' (OUT)"), "Q1_P_OUT");+        assert_eq!(eagle_safe_name("X'tal"), "X_tal", "an apostrophe inside a word is not a prime");+        let pin = |name: &str, number: &str| KicadPin { name: name.into(), number: number.into(), pin_type: "output".into(), x: 0.0, y: 0.0, angle: 0, length: 2.54 };+        let names = dedup_pin_names(&[pin("QH", "7"), pin("QH'", "9"), pin("GND", "8"), pin("GND", "16")]);+        assert_eq!(names, vec!["QH", "QH_P", "GND", "GND@2"]);+        let unnamed = dedup_pin_names(&[pin("~", "1'"), pin("~", "1")]);+        assert_eq!(unnamed, vec!["1_P", "1"], "a pad-number fallback is EAGLE-safe too");+    }+     #[test]     fn pin_pad_mismatch_flags_a_wrong_pairing_but_not_a_thermal_pad() {         let sym = |n: usize| -> String {
src/manage.html+3−2
@@ -636,7 +636,8 @@ function setupHighlight(v){         hit.classList.add('pinhi');         const num=hit.dataset.num, nm=hit.dataset.name;         const kind=hit.closest('#fpbody')?'Pad':'Pin';-        tip.innerHTML=(nm&&nm!=='~')?`<b>${kind} ${num}</b> · ${nm}`:`<b>${kind} ${num}</b>`;+        tip.innerHTML='';const b=document.createElement('b');b.textContent=`${kind} ${num}`;tip.appendChild(b);+        if(nm&&nm!=='~'){tip.appendChild(document.createTextNode(' · '));let r=nm,i;while((i=r.indexOf('~{'))>=0){tip.appendChild(document.createTextNode(r.slice(0,i)));const a=r.slice(i+2),j=a.indexOf('}'),s=document.createElement('span');s.style.textDecoration='overline';s.textContent=j<0?a:a.slice(0,j);tip.appendChild(s);r=j<0?'':a.slice(j+1);}tip.appendChild(document.createTextNode(r));}         tip.style.display='block';         tip.style.left=(e.clientX+14)+'px';         tip.style.top=(e.clientY+14)+'px';@@ -1306,7 +1307,7 @@ function demoHoverPin(){   const num=hit.dataset.num;   document.querySelectorAll('#view [data-num="'+CSS.escape(num)+'"]').forEach(x=>x.classList.add('pinhi'));   const tip=document.getElementById('tip');-  if(tip){const r=hit.getBoundingClientRect();tip.innerHTML='<b>'+num+'</b> '+(hit.dataset.name||'');tip.style.display='block';tip.style.left=(r.right+10)+'px';tip.style.top=(r.top-6)+'px';}+  if(tip){const r=hit.getBoundingClientRect();tip.innerHTML='';const b=document.createElement('b');b.textContent=num;tip.appendChild(b);tip.appendChild(document.createTextNode(' '+(hit.dataset.name||'').replace(/~\{([^}]*)\}?/g,'$1')));tip.style.display='block';tip.style.left=(r.right+10)+'px';tip.style.top=(r.top-6)+'px';}   return hit; } function demoUnhover(){document.querySelectorAll('#view .pinhi').forEach(x=>x.classList.remove('pinhi'));const tip=document.getElementById('tip');if(tip)tip.style.display='none';}
src/manage.rs+31−1
@@ -669,7 +669,7 @@ fn symbol_svg(sym: &Symbol) -> String {             let anchor = if ux > 0.3 { "start" } else if ux < -0.3 { "end" } else { "middle" };             body += &format!(                 "<text x='{:.1}' y='{:.1}' font-size='{:.0}' fill='#e6e9ef' text-anchor='{}' dominant-baseline='central'>{}</text>",-                x2 + ux * fs * 0.5, y2 + uy * fs * 0.5, fs, anchor, esc_attr(&p.name)+                x2 + ux * fs * 0.5, y2 + uy * fs * 0.5, fs, anchor, overbar_svg(&p.name)             );         }     }@@ -798,6 +798,22 @@ fn footprint_svg(fp: &Footprint, names: &std::collections::HashMap<String, Strin     ) } +/// A pin name as SVG text content: KiCad's `~{..}` overbar spans become overlined+/// tspans and lose their markup; everything else is escaped. An unclosed `~{` bars+/// the rest of the name, as KiCad and EAGLE do; a lone `~` is literal.+fn overbar_svg(name: &str) -> String {+    let mut out = String::new();+    let mut rest = name;+    while let Some(i) = rest.find("~{") {+        out += &esc_attr(&rest[..i]);+        let after = &rest[i + 2..];+        let (bar, tail) = match after.find('}') { Some(j) => (&after[..j], &after[j + 1..]), None => (after, "") };+        out += &format!("<tspan text-decoration='overline'>{}</tspan>", esc_attr(bar));+        rest = tail;+    }+    out + &esc_attr(rest)+}+ fn esc_attr(s: &str) -> String {     s.replace('&', "&amp;").replace('\'', "&#39;").replace('"', "&quot;").replace('<', "&lt;") }@@ -1655,3 +1671,17 @@ pub fn export_composed(         panes.join("+"), rows.len(), has3d, out.display());     Ok(()) }++#[cfg(test)]+mod overbar_tests {+    use super::overbar_svg;++    #[test]+    fn kicad_overbars_become_overlined_tspans() {+        assert_eq!(overbar_svg("~{1R}"), "<tspan text-decoration='overline'>1R</tspan>");+        assert_eq!(overbar_svg("PB0 (~{SS}/PCINT0)"), "PB0 (<tspan text-decoration='overline'>SS</tspan>/PCINT0)");+        assert_eq!(overbar_svg("~{CS"), "<tspan text-decoration='overline'>CS</tspan>", "unclosed bars the rest");+        assert_eq!(overbar_svg("~"), "~", "a lone tilde is literal");+        assert_eq!(overbar_svg("A<B"), "A&lt;B");+    }+}
src/viewer2d.html+2−1
@@ -44,7 +44,8 @@ function els(n){return [].slice.call(document.querySelectorAll('[data-num="'+n+' function clearHi(){[].slice.call(document.querySelectorAll('.hi')).forEach(function(e){e.classList.remove('hi');});} function hi(n){els(n).forEach(function(e){e.classList.add('hi');});} function post(n){try{parent.postMessage({type:'lbr-hover',pin:n===null?null:String(n),mpn:MPN},'*');}catch(_){}}-function showTip(n,x,y){var p=byNum[String(n)];if(!p)return;tip.innerHTML='<span class=tn></span><div class=tt></div><div class=td></div>';tip.querySelector('.tn').textContent=n+'  '+(p.name||'');tip.querySelector('.tt').textContent=p.type||'';var d=p.desc||'';if(d)tip.querySelector('.td').textContent=d;else tip.querySelector('.td').style.display='none';tip.style.display='block';tip.style.left=(x+14)+'px';tip.style.top=(y+12)+'px';}+function ovName(el,pre,nm){el.textContent=pre;var r=nm,i;while((i=r.indexOf('~{'))>=0){el.appendChild(document.createTextNode(r.slice(0,i)));var a=r.slice(i+2),j=a.indexOf('}'),s=document.createElement('span');s.style.textDecoration='overline';s.textContent=j<0?a:a.slice(0,j);el.appendChild(s);r=j<0?'':a.slice(j+1);}el.appendChild(document.createTextNode(r));}+function showTip(n,x,y){var p=byNum[String(n)];if(!p)return;tip.innerHTML='<span class=tn></span><div class=tt></div><div class=td></div>';ovName(tip.querySelector('.tn'),n+'  ',p.name||'');tip.querySelector('.tt').textContent=p.type||'';var d=p.desc||'';if(d)tip.querySelector('.td').textContent=d;else tip.querySelector('.td').style.display='none';tip.style.display='block';tip.style.left=(x+14)+'px';tip.style.top=(y+12)+'px';} [].slice.call(document.querySelectorAll('.pingroup,.pad')).forEach(function(g){   var n=g.getAttribute('data-num');   g.addEventListener('mouseenter',function(e){clearHi();hi(n);post(n);showTip(n,e.clientX,e.clientY);});