Skip to content

Commit

Permalink
Merge pull request #29 from anas-sarkez/main
Browse files Browse the repository at this point in the history
Add silkscreen for all passive-fn for example [0402,0603...] , and add plus sign prop and silkscreen
  • Loading branch information
AnasSarkiz authored Sep 3, 2024
2 parents be96c4e + 35851ba commit 7be2a70
Show file tree
Hide file tree
Showing 40 changed files with 243 additions and 128 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"version": "0.0.58",
"description": "",
"main": "dist/index.cjs",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"test": "FULL_RUN=1 ava",
"dev": "cd previews && npm i && npm run storybook",
Expand All @@ -21,7 +19,9 @@
"@tscircuit/soup-util": "^0.0.11",
"@types/node": "^20.12.13",
"ava": "^6.1.3",
"circuit-to-svg": "^0.0.13",

"circuit-to-svg": "^0.0.15",

"esbuild": "^0.21.4",
"esbuild-register": "^3.5.0",
"tsup": "^8.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/fn/res.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnySoupElement } from "@tscircuit/soup"
import { passive, type PassiveDef } from "../helpers/passive-fn"
import { PassiveDef, passive } from "../helpers/passive-fn"

export const res = (params: PassiveDef): AnySoupElement[] => {
return passive(params)
Expand Down
61 changes: 55 additions & 6 deletions src/helpers/passive-fn.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AnySoupElement } from "@tscircuit/soup"
import type { AnySoupElement, PcbSilkscreenPath } from "@tscircuit/soup"
import { rectpad } from "../helpers/rectpad"
import mm from "@tscircuit/mm"
import { platedhole } from "./platedhole"

import { positive_sign } from "./positive_sign"
type StandardSize = {
imperial: string
metric: string
Expand Down Expand Up @@ -110,6 +110,7 @@ export type PassiveDef = {
imperial?: string
w?: number
h?: number
polarized?: boolean
}

const deriveXFromH = (h: number) => 0.079 * h ** 2 + 0.94 * h - 0.009
Expand All @@ -118,7 +119,7 @@ const deriveGFromW = (w: number) => 0.59 * w - 0.31
const deriveCFromW = (w: number) => -0.01 * w ** 2 + 0.94 * w + 0.03

export const passive = (params: PassiveDef): AnySoupElement[] => {
let { tht, p, pw, ph, metric, imperial, w, h } = params
let { tht, p, pw, ph, metric, imperial, w, h, polarized } = params

if (typeof w === "string") w = mm(w)
if (typeof h === "string") h = mm(h)
Expand Down Expand Up @@ -163,16 +164,64 @@ export const passive = (params: PassiveDef): AnySoupElement[] => {

if (pw === undefined) throw new Error("could not infer pad width")
if (ph === undefined) throw new Error("could not infer pad width")
// if (params.w && params.p && params.pw) {

const PcbSilkscreenPath: PcbSilkscreenPath[] = [
{
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "1",
pcb_silkscreen_path_id: "1",
stroke_width: 0.05,
route: [
{ x: -p / 2 + pw / 2 + 0.1, y: ph / 2 },
{ x: p / 2 - pw / 2 - 0.1, y: ph / 2 },
],
},
{
type: "pcb_silkscreen_path",
layer: "top",
pcb_component_id: "2",
pcb_silkscreen_path_id: "2",
stroke_width: 0.05,
route: [
{ x: -p / 2 + pw / 2 + 0.1, y: -ph / 2 },
{ x: p / 2 - pw / 2 - 0.1, y: -ph / 2 },
],
},
]

let pcbSilkscreenPositiveSign: PcbSilkscreenPath[] | undefined
if (polarized) {
pcbSilkscreenPositiveSign = positive_sign(p, pw, ph)
}
if (tht) {
return [
const pads = [
platedhole(1, -p / 2, 0, pw, (pw * 1) / 0.8),
platedhole(2, p / 2, 0, pw, (pw * 1) / 0.8),
]
} else {
return [

if (PcbSilkscreenPath.length > 0 && polarized) {
return [...pads, ...PcbSilkscreenPath, ...pcbSilkscreenPositiveSign!]
// biome-ignore lint/style/noUselessElse: <explanation>
} else if (PcbSilkscreenPath.length > 0 && !polarized) {
return [...pads, ...PcbSilkscreenPath]
}

return pads
// biome-ignore lint/style/noUselessElse: <explanation>
} else if (!tht) {
const pads = [
rectpad(["1", "left"], -p / 2, 0, pw, ph),
rectpad(["2", "right"], p / 2, 0, pw, ph),
]

if (PcbSilkscreenPath.length > 0 && polarized) {
return [...pads, ...PcbSilkscreenPath, ...pcbSilkscreenPositiveSign!]
// biome-ignore lint/style/noUselessElse: <explanation>
} else if (PcbSilkscreenPath.length > 0 && !polarized) {
return [...pads, ...PcbSilkscreenPath]
}
return pads
}
}
32 changes: 32 additions & 0 deletions src/helpers/positive_sign.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { PcbSilkscreenPath } from "@tscircuit/soup"

export const positive_sign: (
p: number,
pw: number,
ph: number,
) => PcbSilkscreenPath[] = (p, pw, ph) => {
return [
{
type: "pcb_silkscreen_path",
layer: "bottom",
pcb_component_id: "positive_sign",
pcb_silkscreen_path_id: "4",
stroke_width: 0.02,
route: [
{ x: -p / 2 - pw * 1.6, y: ph / 14 },
{ x: -p / 2 - pw * 1.2, y: ph / 14 },
],
},
{
type: "pcb_silkscreen_path",
layer: "bottom",
pcb_component_id: "positive_sign",
pcb_silkscreen_path_id: "3",
stroke_width: 0.02,
route: [
{ x: -p / 2 - pw * 1.4, y: -ph / 8 },
{ x: -p / 2 - pw * 1.4, y: ph / 4 },
],
},
]
}
1 change: 1 addition & 0 deletions tests/fixtures/get-test-fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { logSoup } from "@tscircuit/log-soup"
import type { AnySoupElement } from "@tscircuit/soup"
import type { ExecutionContext } from "ava"

import { circuitJsonToPcbSvg, circuitJsonToSchematicSvg } from "circuit-to-svg"
import fs from "node:fs"
import path from "node:path"
Expand Down
8 changes: 4 additions & 4 deletions tests/led.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ test("led_rect", async (t) => {
const { fp, snapshotSoup } = await getTestFixture(t)
const soup = led({
tht: false,
p: 2.5,
p: 1.5,
pw: 0.5,
ph: 0.5,
metric: "mm",
})

snapshotSoup(soup)
Expand All @@ -19,12 +20,11 @@ test("led_hole", async (t) => {
const { fp, snapshotSoup } = await getTestFixture(t)
const soup = led({
tht: true,
p: 2,
p: 1.5,
pw: 0.5,
ph: 0.5,
metric: "mm",
w: 5,
h: 2,
polarized: true,
})

snapshotSoup(soup)
Expand Down
7 changes: 4 additions & 3 deletions tests/output/bga footprint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions tests/output/bga64_w10_h10_grid8x8_p1.27mm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions tests/output/bga7_w8_h8_grid3x3_p1_missing(center,B1).svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions tests/output/cap footprint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7be2a70

Please sign in to comment.