Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion src/fn/sod123.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -19,6 +24,74 @@ export const sod123 = (
raw_params: z.input<typeof sod_def>,
): { 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,
Expand All @@ -39,6 +112,8 @@ export const sod123 = (

return {
circuitJson: sodWithoutParsing(parameters).concat(
...fabricationPaths,
fabricationValueText as AnyCircuitElement,
silkscreenRefText as AnyCircuitElement,
courtyard as AnyCircuitElement,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/sod123.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions tests/fixtures/compareFootprinterVsKicad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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 =
Expand Down Expand Up @@ -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")),
)
Expand Down
Loading
Loading