diff --git a/src/fn/sod123.ts b/src/fn/sod123.ts index f346b7b4..d24a0480 100644 --- a/src/fn/sod123.ts +++ b/src/fn/sod123.ts @@ -1,4 +1,9 @@ -import type { AnyCircuitElement, PcbCourtyardRect } from "circuit-json" +import type { + AnyCircuitElement, + PcbCourtyardRect, + PcbFabricationNotePath, + PcbFabricationNoteText, +} from "circuit-json" import { z } from "zod" import { rectpad } from "../helpers/rectpad" import { silkscreenRef, type SilkscreenRef } from "src/helpers/silkscreenRef" @@ -19,6 +24,74 @@ export const sod123 = ( raw_params: z.input, ): { circuitJson: AnyCircuitElement[]; parameters: any } => { const parameters = sod_def.parse(raw_params) + + const fabricationPaths: PcbFabricationNotePath[] = [ + [ + { x: 0.25, y: 0 }, + { x: 0.75, y: 0 }, + ], + [ + { x: 0.25, y: 0.4 }, + { x: -0.35, y: 0 }, + ], + [ + { x: 0.25, y: -0.4 }, + { x: 0.25, y: 0.4 }, + ], + [ + { x: -0.35, y: 0 }, + { x: 0.25, y: -0.4 }, + ], + [ + { x: -0.35, y: 0 }, + { x: -0.35, y: 0.55 }, + ], + [ + { x: -0.35, y: 0 }, + { x: -0.35, y: -0.55 }, + ], + [ + { x: -0.75, y: 0 }, + { x: -0.35, y: 0 }, + ], + [ + { x: -1.4, y: 0.9 }, + { x: -1.4, y: -0.9 }, + ], + [ + { x: 1.4, y: 0.9 }, + { x: -1.4, y: 0.9 }, + ], + [ + { x: 1.4, y: -0.9 }, + { x: 1.4, y: 0.9 }, + ], + [ + { x: -1.4, y: -0.9 }, + { x: 1.4, y: -0.9 }, + ], + ].map((route, index) => ({ + type: "pcb_fabrication_note_path", + pcb_fabrication_note_path_id: `sod123_fab_path_${index}`, + pcb_component_id: "", + layer: "top", + route, + stroke_width: 0.1, + })) + + // Match KiCad D_SOD-123 F.Fab texts: + const fabricationValueText: PcbFabricationNoteText = { + type: "pcb_fabrication_note_text", + pcb_fabrication_note_text_id: "sod123_fab_value", + font: "tscircuit2024", + font_size: 1, + pcb_component_id: "", + text: "D_SOD-123", + layer: "top", + anchor_position: { x: 0, y: -2 }, + anchor_alignment: "center", + } + const silkscreenRefText: SilkscreenRef = silkscreenRef( 0, length.parse(parameters.h) / 4 + 0.4, @@ -39,6 +112,8 @@ export const sod123 = ( return { circuitJson: sodWithoutParsing(parameters).concat( + ...fabricationPaths, + fabricationValueText as AnyCircuitElement, silkscreenRefText as AnyCircuitElement, courtyard as AnyCircuitElement, ), diff --git a/tests/__snapshots__/sod123.snap.svg b/tests/__snapshots__/sod123.snap.svg index be674646..c7ad04ae 100644 --- a/tests/__snapshots__/sod123.snap.svg +++ b/tests/__snapshots__/sod123.snap.svg @@ -1 +1 @@ -{REF} \ No newline at end of file +{REF}D_SOD-123 \ No newline at end of file diff --git a/tests/fixtures/compareFootprinterVsKicad.ts b/tests/fixtures/compareFootprinterVsKicad.ts index e1e86fe8..7ae14ed9 100644 --- a/tests/fixtures/compareFootprinterVsKicad.ts +++ b/tests/fixtures/compareFootprinterVsKicad.ts @@ -328,9 +328,10 @@ function translateCourtyardElements( export async function compareFootprinterVsKicad( footprinterString: string, kicadPath: string, - options: { + rawOptions: { includeSilkscreen?: boolean - } = { includeSilkscreen: true }, + includeFabricationNotes?: boolean + } = { includeSilkscreen: true, includeFabricationNotes: false }, ): Promise<{ avgRelDiff: number combinedFootprintElements: any[] @@ -339,6 +340,12 @@ export async function compareFootprinterVsKicad( courtyardIntersectionOverUnionPercent: number fpSilkscreenElements: any[] }> { + const options = { + includeSilkscreen: true, + includeFabricationNotes: false, + ...rawOptions, + } + const BASE_URL = "https://kicad-mod-cache.tscircuit.com/" const kicadUrl = BASE_URL + kicadPath const normalizedFootprintName = @@ -485,6 +492,9 @@ export async function compareFootprinterVsKicad( e.type === "pcb_courtyard_rect" || e.type === "pcb_courtyard_circle" || e.type === "pcb_courtyard_polygon" || + (options.includeFabricationNotes === true && + (e.type === "pcb_fabrication_note_path" || + e.type === "pcb_fabrication_note_text")) || (options.includeSilkscreen === true && (e.type === "pcb_silkscreen_path" || e.type === "pcb_silkscreen_text")), ) diff --git a/tests/kicad-parity/__snapshots__/sod123.snap.svg b/tests/kicad-parity/__snapshots__/sod123.snap.svg index 0490d493..432426ee 100644 --- a/tests/kicad-parity/__snapshots__/sod123.snap.svg +++ b/tests/kicad-parity/__snapshots__/sod123.snap.svg @@ -1 +1 @@ -{REF}REF**Diff: 0.00% \ No newline at end of file +{REF}REF**Diff: 0.00%D_SOD-123D_SOD-123 \ No newline at end of file diff --git a/tests/kicad-parity/sod123_kicad_parity.test.ts b/tests/kicad-parity/sod123_kicad_parity.test.ts index 6779245f..0b92123d 100644 --- a/tests/kicad-parity/sod123_kicad_parity.test.ts +++ b/tests/kicad-parity/sod123_kicad_parity.test.ts @@ -11,6 +11,7 @@ test("parity/sod123", async () => { } = await compareFootprinterVsKicad( "sod123", "Diode_SMD.pretty/D_SOD-123.circuit.json", + { includeFabricationNotes: true }, ) const svgContent = convertCircuitJsonToPcbSvg(combinedFootprintElements, { diff --git a/tests/sod123.test.ts b/tests/sod123.test.ts index fd2b7ad1..89b92254 100644 --- a/tests/sod123.test.ts +++ b/tests/sod123.test.ts @@ -7,3 +7,62 @@ test("sod123", () => { const svgContent = convertCircuitJsonToPcbSvg(soup) expect(svgContent).toMatchSvgSnapshot(import.meta.path, "sod123") }) + +test("sod123 includes KiCad fabrication geometry", () => { + const circuitJson = fp.string("sod123").circuitJson() + const fabricationPaths = circuitJson.filter( + (element) => element.type === "pcb_fabrication_note_path", + ) + const fabricationTexts = circuitJson.filter( + (element) => element.type === "pcb_fabrication_note_text", + ) + + expect(fabricationPaths).toHaveLength(11) + expect(fabricationPaths.map((path) => path.route)).toEqual([ + [ + { x: 0.25, y: 0 }, + { x: 0.75, y: 0 }, + ], + [ + { x: 0.25, y: 0.4 }, + { x: -0.35, y: 0 }, + ], + [ + { x: 0.25, y: -0.4 }, + { x: 0.25, y: 0.4 }, + ], + [ + { x: -0.35, y: 0 }, + { x: 0.25, y: -0.4 }, + ], + [ + { x: -0.35, y: 0 }, + { x: -0.35, y: 0.55 }, + ], + [ + { x: -0.35, y: 0 }, + { x: -0.35, y: -0.55 }, + ], + [ + { x: -0.75, y: 0 }, + { x: -0.35, y: 0 }, + ], + [ + { x: -1.4, y: 0.9 }, + { x: -1.4, y: -0.9 }, + ], + [ + { x: 1.4, y: 0.9 }, + { x: -1.4, y: 0.9 }, + ], + [ + { x: 1.4, y: -0.9 }, + { x: 1.4, y: 0.9 }, + ], + [ + { x: -1.4, y: -0.9 }, + { x: 1.4, y: -0.9 }, + ], + ]) + expect(fabricationTexts).toHaveLength(1) +})