Skip to content

Commit

Permalink
Merge pull request #48 from tscircuit/feat/pcb_keepout
Browse files Browse the repository at this point in the history
feat: pcb_keepout added
  • Loading branch information
imrishabh18 authored Sep 8, 2024
2 parents 2b8293c + 19b60fa commit 1cd0587
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { PlatedHole } from "./primitive-components/PlatedHole"
export { Constraint } from "./primitive-components/Constraint"
export { Hole } from "./primitive-components/Hole"
export { SilkscreenText } from "./primitive-components/SilkscreenText"
export { Keepout } from "./primitive-components/Keepout"
58 changes: 58 additions & 0 deletions lib/components/primitive-components/Keepout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import { pcbKeepoutProps } from "@tscircuit/props"
import type { RenderPhaseFn } from "../base-components/Renderable"
import type { PCBKeepout } from "@tscircuit/soup"
import { decomposeTSR } from "transformation-matrix"

export class Keepout extends PrimitiveComponent<typeof pcbKeepoutProps> {
pcb_keepout_id: string | null = null

isPcbPrimitive = true

get config() {
return {
zodProps: pcbKeepoutProps,
}
}

doInitialPcbPrimitiveRender(): void {
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()
const decomposedMat = decomposeTSR(
this._computePcbGlobalTransformBeforeLayout(),
)
const isRotated90 =
Math.abs(decomposedMat.rotation.angle * (180 / Math.PI) - 90) < 0.01

let pcb_keepout: PCBKeepout | null = null
if (props.shape === "circle") {
pcb_keepout = db.pcb_keepout.insert({
layers: ["top"],
shape: "circle",
// @ts-ignore: no idea why this is triggering
radius: props.radius,
center: {
x: position.x,
y: position.y,
},
})
} else if (props.shape === "rect") {
pcb_keepout = db.pcb_keepout.insert({
layers: ["top"],
shape: "rect",
...(isRotated90
? { width: props.height, height: props.width }
: { width: props.width, height: props.height }),
// @ts-ignore: no idea why this is triggering
center: {
x: position.x,
y: position.y,
},
})
}
if (pcb_keepout) {
this.pcb_keepout_id = pcb_keepout.pcb_keepout_id
}
}
}
3 changes: 2 additions & 1 deletion lib/components/primitive-components/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {
elm.type === "pcb_hole" ||
elm.type === "source_port" ||
elm.type === "pcb_port" ||
elm.type === "source_trace",
elm.type === "source_trace" ||
elm.type === "pcb_keepout",
)

const source_trace = db.source_trace.get(this.source_trace_id!)!
Expand Down
1 change: 1 addition & 0 deletions lib/fiber/intrinsic-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare global {
schematictext: Props.SchematicTextProps
smtpad: Props.SmtPadProps
platedhole: Props.PlatedHoleProps
keepout: Props.PcbKeepoutProps
hole: Props.HoleProps
port: Props.PortProps
group: Props.GroupProps
Expand Down
20 changes: 20 additions & 0 deletions lib/utils/createComponentsFromSoup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { PrimitiveComponent } from "../components/base-components/Primitive
import { SmtPad } from "lib/components/primitive-components/SmtPad"
import { SilkscreenPath } from "lib/components/primitive-components/SilkscreenPath"
import { PlatedHole } from "lib/components/primitive-components/PlatedHole"
import { Keepout } from "lib/components/primitive-components/Keepout"

export const createComponentsFromSoup = (
soup: AnySoupElement[],
Expand Down Expand Up @@ -53,6 +54,25 @@ export const createComponentsFromSoup = (
}),
)
}
} else if (elm.type === "pcb_keepout" && elm.shape === "circle") {
components.push(
new Keepout({
pcbX: elm.center.x,
pcbY: elm.center.y,
shape: "circle",
radius: elm.radius,
}),
)
} else if (elm.type === "pcb_keepout" && elm.shape === "rect") {
components.push(
new Keepout({
pcbX: elm.center.x,
pcbY: elm.center.y,
shape: "rect",
width: elm.width,
height: elm.height,
}),
)
}
}
return components
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@lume/kiwi": "^0.4.3",
"@tscircuit/infgrid-ijump-astar": "^0.0.9",
"@tscircuit/props": "^0.0.62",
"@tscircuit/soup": "^0.0.66",
"@tscircuit/soup-util": "0.0.18",
"@tscircuit/soup": "^0.0.67",
"@tscircuit/soup-util": "^0.0.23",
"footprinter": "^0.0.44",
"react": "^18.3.1",
"react-reconciler": "^0.29.2",
Expand Down

0 comments on commit 1cd0587

Please sign in to comment.