Skip to content
Merged
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
46 changes: 46 additions & 0 deletions lib/components/normal-components/Panel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { panelProps } from "@tscircuit/props"
import { distance } from "circuit-json"
import type { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import { Group } from "../primitive-components/Group/Group"

export class Panel extends Group<typeof panelProps> {
pcb_panel_id: string | null = null

get config() {
return {
componentName: "Panel",
Expand All @@ -14,6 +17,10 @@ export class Panel extends Group<typeof panelProps> {
return true
}

get isSubcircuit() {
return true
}

add(component: PrimitiveComponent) {
if (component.lowercaseComponentName !== "board") {
throw new Error("<panel> can only contain <board> elements")
Expand All @@ -28,4 +35,43 @@ export class Panel extends Group<typeof panelProps> {

super.runRenderCycle()
}

doInitialPcbComponentRender() {
super.doInitialPcbComponentRender()
if (this.root?.pcbDisabled) return

const { db } = this.root!
const props = this._parsedProps

const inserted = db.pcb_panel.insert({
width: distance.parse(props.width),
height: distance.parse(props.height),
center: this._getGlobalPcbPositionBeforeLayout(),
covered_with_solder_mask: !(props.noSolderMask ?? false),
})

this.pcb_panel_id = inserted.pcb_panel_id
}

updatePcbComponentRender() {
if (this.root?.pcbDisabled) return
if (!this.pcb_panel_id) return

const { db } = this.root!
const props = this._parsedProps

db.pcb_panel.update(this.pcb_panel_id, {
width: distance.parse(props.width),
height: distance.parse(props.height),
center: this._getGlobalPcbPositionBeforeLayout(),
covered_with_solder_mask: !(props.noSolderMask ?? false),
})
}

removePcbComponentRender() {
if (!this.pcb_panel_id) return

this.root?.db.pcb_panel.delete(this.pcb_panel_id)
this.pcb_panel_id = null
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"bun-match-svg": "0.0.12",
"calculate-elbow": "^0.0.12",
"chokidar-cli": "^3.0.0",
"circuit-json": "^0.0.306",
"circuit-json": "^0.0.307",
"circuit-json-to-bpc": "^0.0.13",
"circuit-json-to-connectivity-map": "^0.0.22",
"circuit-json-to-gltf": "^0.0.31",
Expand Down
35 changes: 35 additions & 0 deletions tests/components/normal-components/panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,38 @@ test("panel must contain at least one board", () => {
circuit.render()
}).toThrow("<panel> must contain at least one <board>")
})

test("panel emits pcb_panel with center", () => {
const { circuit } = getTestFixture()

circuit.add(
<panel width="100mm" height="50mm" pcbX="10mm" pcbY="20mm">
<board width="10mm" height="10mm" routingDisabled />
</panel>,
)

circuit.render()

const pcbPanel = circuit.db.pcb_panel.list()[0]
expect(pcbPanel).toMatchObject({
width: 100,
height: 50,
center: { x: 10, y: 20 },
covered_with_solder_mask: true,
})
})

test("panel noSolderMask disables solder mask coverage", () => {
const { circuit } = getTestFixture()

circuit.add(
<panel width="100mm" height="100mm" noSolderMask>
<board width="10mm" height="10mm" routingDisabled />
</panel>,
)

circuit.render()

const pcbPanel = circuit.db.pcb_panel.list()[0]
expect(pcbPanel.covered_with_solder_mask).toBe(false)
})