Skip to content

Commit

Permalink
Merge pull request #34 from tscircuit/hole-implementation
Browse files Browse the repository at this point in the history
implement Hole and pcb_hole rendering
  • Loading branch information
seveibar authored Sep 5, 2024
2 parents ac9889e + 769dfab commit c9c0d5a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { Jumper } from "./normal-components/Jumper"
export { SilkscreenPath } from "./primitive-components/SilkscreenPath"
export { PlatedHole } from "./primitive-components/PlatedHole"
export { Constraint } from "./primitive-components/Constraint"
export { Hole } from "./primitive-components/Hole"
36 changes: 36 additions & 0 deletions lib/components/primitive-components/Hole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import { holeProps } from "@tscircuit/props"
import type { PCBHole } from "@tscircuit/soup"

export class Hole extends PrimitiveComponent<typeof holeProps> {
pcb_hole_id: string | null = null
isPcbPrimitive = true

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

getPcbSize(): { width: number; height: number } {
const { _parsedProps: props } = this
return { width: props.holeDiameter, height: props.holeDiameter }
}

doInitialPcbPrimitiveRender(): void {
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()

const pcb_hole: PCBHole = {
type: "pcb_hole",
hole_shape: "round",
hole_diameter: props.holeDiameter,
x: position.x,
y: position.y,
}

const inserted_hole = db.pcb_hole.insert(pcb_hole)
// this.pcb_hole_id = inserted_hole.pcb_hole_id!
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tests/components/primitive-components/hole.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("Hole component rendering", () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<hole holeDiameter="0.08in" pcbX={3} pcbY={1} />
</board>,
)

circuit.render()

const pcbHoles = circuit.db.pcb_hole.list()

expect(pcbHoles.length).toBe(1)
expect((pcbHoles[0] as any).hole_diameter).toBeCloseTo(2.032)
expect(pcbHoles[0].x).toBe(3)
expect(pcbHoles[0].y).toBe(1)

expect(circuit.getCircuitJson()).toMatchPcbSnapshot(import.meta.path)
})

0 comments on commit c9c0d5a

Please sign in to comment.