← Commit history

Sync current source (open-source, up to date)

John Lauer ·60b71b3566 ·3mo ago ·parent a9108ee
2 files changed +136
src/provenance.rsadded+73
@@ -0,0 +1,73 @@+//! Canonical source-provenance LABELING — the single rule for how every Adom+//! EDA app names where a symbol / footprint / 3D / datasheet actually came from.+//!+//! THE RULE (John, 2026-06-23): label by the DISCOVERY SOURCE — where the file+//! was actually downloaded — NOT by content_origin (who authored the model).+//!+//!   - ONLY the maker's OWN website counts as "the manufacturer", and then we+//!     NAME the site: "Texas Instruments (ti.com)", "Analog Devices (analog.com)".+//!   - The moment the manufacturer hands you off to a 3rd-party library —+//!     UltraLibrarian, SnapMagic/SnapEDA, Component Search Engine — that+//!     AGGREGATOR is the source. NEVER label it "Manufacturer".+//!   - A fuzzy bare "Manufacturer" is misleading and banned.+//!+//! This module is mirrored (same mapping) in adom-symbol, adom-footprint and+//! adom-lbr so the label is identical everywhere. See the `chip-provenance-labeling` skill.++/// The maker's canonical website domain, for "Texas Instruments (ti.com)" labels.+/// Matched case-insensitively on a substring of the manufacturer name.+pub fn mfr_domain(manufacturer: &str) -> Option<&'static str> {+    let m = manufacturer.to_lowercase();+    let table = [+        ("texas instr", "ti.com"), ("analog dev", "analog.com"),+        ("stmicro", "st.com"), ("nxp", "nxp.com"), ("microchip", "microchip.com"),+        ("infineon", "infineon.com"), ("on semi", "onsemi.com"), ("onsemi", "onsemi.com"),+        ("nordic", "nordicsemi.com"), ("espressif", "espressif.com"),+        ("renesas", "renesas.com"), ("diodes inc", "diodes.com"), ("vishay", "vishay.com"),+        ("bosch", "bosch-sensortec.com"), ("maxim", "analog.com"), ("dialog", "renesas.com"),+        ("rohm", "rohm.com"), ("toshiba", "toshiba.com"), ("skyworks", "skyworksinc.com"),+        ("qorvo", "qorvo.com"), ("micron", "micron.com"), ("cypress", "infineon.com"),+        ("silicon lab", "silabs.com"), ("silabs", "silabs.com"), ("lattice", "latticesemi.com"),+        ("winbond", "winbond.com"), ("ti ", "ti.com"),+    ];+    table.iter().find(|(k, _)| m.contains(k)).map(|(_, v)| *v)+}++/// The human label for a source, given the discovery-source slug + the+/// manufacturer name. THIS is the function every app calls.+pub fn source_label(discovery: &str, manufacturer: &str) -> String {+    match discovery.to_lowercase().as_str() {+        // Manufacturer-DIRECT: only when downloaded from the maker's own site.+        "manufacturer" | "mfr" | "vendor" => {+            if let Some(dom) = mfr_domain(manufacturer) {+                if manufacturer.is_empty() { format!("Manufacturer · {dom}") }+                else { format!("{manufacturer} ({dom})") }+            } else if !manufacturer.is_empty() {+                format!("{manufacturer} (direct)")+            } else {+                "Manufacturer (direct site)".to_string()+            }+        }+        // 3rd-party aggregators — NEVER "the manufacturer".+        "cse" | "componentsearch" | "cse_ul" | "samacsys" => "Component Search Engine".into(),+        "snapeda" | "snapmagic" => "SnapEDA".into(),+        "ultralibrarian" | "ul" => "Ultra Librarian".into(),+        "mouser" => "Mouser".into(),+        "digikey" => "DigiKey".into(),+        "arrow" => "Arrow".into(),+        "lcsc" => "LCSC".into(),+        "kicad_community" => "KiCad community".into(),+        other => other.to_string(),+    }+}++/// A short note for the "the manufacturer linked you to it, but it's a 3rd+/// party" middle-ground — appended in tooltips so the user knows the maker+/// pointed here even though the file came off an aggregator.+pub fn linked_from_mfr_note(manufacturer: &str) -> String {+    if manufacturer.is_empty() {+        "the manufacturer's page linked to this 3rd-party library".to_string()+    } else {+        format!("{manufacturer}'s own page links here, but the file is hosted by this 3rd-party library — not downloaded from {manufacturer} directly")+    }+}
tests/golden/TST-ALL.kicad_symadded+63
@@ -0,0 +1,63 @@+(kicad_symbol_lib+  (version 20231120)+  (generator "adom")+  (symbol "TST-ALL"+    (pin_names (offset 1.016))+    (exclude_from_sim no)+    (in_bom yes)+    (on_board yes)+    (property "Reference" "U"+      (at 0.00 16.64 0)+      (effects (font (size 1.27 1.27)))+    )+    (property "Value" "TST-ALL"+      (at 0.00 -20.79 0)+      (effects (font (size 1.27 1.27)))+    )+    (property "Footprint" "QFN-16"+      (at 0 0 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Datasheet" "https://x/y.pdf"+      (at 0 0 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Description" "all-sides coverage"+      (at 0 0 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Manufacturer" "Adom Test"+      (at 0 0 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Mouser" "MOU-123"+      (at 0 0 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (symbol "TST-ALL_0_1"+      (rectangle (start -10.16 8.10) (end 10.16 -12.25)+        (stroke (width 0.254) (type default))+        (fill (type background))+      )+      (text "IO" (at -9.14 0.00 0)+        (effects (font (size 0.762 0.762) (color 132 0 0 1)) (justify left))+      )+      (text "Out" (at 9.14 0.00 0)+        (effects (font (size 0.762 0.762) (color 132 0 0 1)) (justify right))+      )+      (text "Power" (at -2.27 7.08 900)+        (effects (font (size 0.762 0.762) (color 132 0 0 1)) (justify right))+      )+      (text "Gnd" (at -2.27 -11.23 900)+        (effects (font (size 0.762 0.762) (color 132 0 0 1)) (justify left))+      )+    )+    (symbol "TST-ALL_1_1"+      (pin bidirectional line (at -12.70 -2.00 0) (length 2.54) (name "SDA") (number "1"))+      (pin bidirectional line (at -12.70 -4.54 0) (length 2.54) (name "SCL") (number "2"))+      (pin output line (at 12.70 -2.00 180) (length 2.54) (name "TX") (number "5"))+      (pin power_in line (at -0.27 10.54 270) (length 2.54) (name "V3V3") (number "16"))+      (pin power_in line (at -0.27 -14.69 90) (length 2.54) (name "GND") (number "8"))+    )+  )+)