-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from tscircuit/hole-implementation
implement Hole and pcb_hole rendering
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/components/primitive-components/__snapshots__/hole-pcb.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |