Skip to content

Commit

Permalink
support for plated holes
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jun 11, 2024
1 parent 7077f10 commit 2b66bb9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
46 changes: 35 additions & 11 deletions src/convert-kicad-json-to-tscircuit-soup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions src/kicad-zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 4 additions & 2 deletions src/parse-kicad-mod-to-kicad-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 {
Expand All @@ -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())
Expand All @@ -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,
Expand Down

0 comments on commit 2b66bb9

Please sign in to comment.