diff --git a/src/convert-kicad-json-to-tscircuit-soup.ts b/src/convert-kicad-json-to-tscircuit-soup.ts index 37aa647..29a9f6a 100644 --- a/src/convert-kicad-json-to-tscircuit-soup.ts +++ b/src/convert-kicad-json-to-tscircuit-soup.ts @@ -27,20 +27,44 @@ export const convertKicadJsonToTsCircuitSoup = async ( pb.add("component", (cb) => { for (const pad of pads) { - cb.footprint.add("smtpad", (pb) => - pb - .setProps({ + if (pad.pad_type === "smd") { + cb.footprint.add("smtpad", (pb) => + pb + .setProps({ + x: pad.at[0], + y: -pad.at[1], + // ??? @tscircuit/builder bug? width and height are not recognized + width: pad.size[0], + height: pad.size[1], + layer: pad.layers?.[0]! as any, + shape: "rect", + port_hints: [pad.name], + }) + .setSize(pad.size[0], pad.size[1]), + ) + } else if (pad.pad_type === "thru_hole") { + cb.footprint.add("platedhole", (phb) => + phb.setProps({ x: pad.at[0], y: -pad.at[1], - // ??? @tscircuit/builder bug? width and height are not recognized - width: pad.size[0], - height: pad.size[1], - layer: pad.layers?.[0]! as any, - shape: "rect", + outer_diameter: pad.size[0], + hole_diameter: pad.drill, + // TODO kicad uses "*.Cu" and "*.Mask" to mean "every" + layers: ["top", "bottom"], port_hints: [pad.name], - }) - .setSize(pad.size[0], pad.size[1]), - ) + }), + ) + } else if (pad.pad_type === "np_thru_hole") { + cb.footprint.add("hole", (hb) => + hb.setProps({ + x: pad.at[0], + y: -pad.at[1], + hole_diameter: pad.drill, + }), + ) + } else if (pad.pad_type === "connect") { + // ??? + } } for (const fp_line of fp_lines) { if (fp_line.layer === "F.Cu") { diff --git a/src/kicad-zod.ts b/src/kicad-zod.ts index a23137b..6e96349 100644 --- a/src/kicad-zod.ts +++ b/src/kicad-zod.ts @@ -35,6 +35,7 @@ export const pad_def = z.object({ ]), at: point, size: point2, + drill: z.number().optional(), layers: z.array(z.string()).optional(), roundrect_rratio: z.number().optional(), chamfer_ratio: z.number().optional(), diff --git a/src/parse-kicad-mod-to-kicad-json.ts b/src/parse-kicad-mod-to-kicad-json.ts index 28f058c..028fef1 100644 --- a/src/parse-kicad-mod-to-kicad-json.ts +++ b/src/parse-kicad-mod-to-kicad-json.ts @@ -24,7 +24,7 @@ export const parseKicadModToKicadJson = (fileContent: string): KicadModJson => { const simpleTopLevelAttributes = Object.entries(kicad_mod_json_def.shape) .filter( ([attributeKey, def]) => - def._def.typeName === "ZodString" || attributeKey === "tags" + def._def.typeName === "ZodString" || attributeKey === "tags", ) .map(([attributeKey]) => attributeKey) for (const kicadSExprRow of kicadSExpr.slice(2)) { @@ -46,7 +46,7 @@ export const parseKicadModToKicadJson = (fileContent: string): KicadModJson => { const attrKey = attrAr[0].valueOf() acc[attrKey] = formatAttr(attrAr.slice(1), attrKey) return acc - }, {} as any) + }, {} as any), ) return { @@ -63,6 +63,7 @@ export const parseKicadModToKicadJson = (fileContent: string): KicadModJson => { for (const row of padRows) { const at = getAttr(row, "at") const size = getAttr(row, "size") + const drill = getAttr(row, "drill") let layers = getAttr(row, "layers") if (Array.isArray(layers)) { layers = layers.map((layer) => layer.valueOf()) @@ -79,6 +80,7 @@ export const parseKicadModToKicadJson = (fileContent: string): KicadModJson => { pad_type: row[2].valueOf(), pad_shape: row[3].valueOf(), at, + drill, size, layers, roundrect_rratio,