Skip to content

Commit d8c7ce4

Browse files
authored
Add support for PCB rectangular hole (#472)
* Add support for PCB rectangular hole
1 parent 6207a7d commit d8c7ce4

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/examples/hole-rect.fixture.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { PCBViewer } from "../PCBViewer"
2+
3+
export const RectangularHole = () => {
4+
return (
5+
<div style={{ backgroundColor: "black" }}>
6+
<PCBViewer
7+
circuitJson={
8+
[
9+
{
10+
type: "pcb_board",
11+
pcb_board_id: "pcb_board_rect_hole_0",
12+
center: { x: 0, y: 0 },
13+
thickness: 1.6,
14+
num_layers: 2,
15+
width: 20,
16+
height: 12,
17+
outline: undefined,
18+
material: "fr4",
19+
},
20+
{
21+
type: "pcb_hole",
22+
pcb_hole_id: "pcb_hole_rect_0",
23+
x: -4,
24+
y: 0,
25+
hole_shape: "rect",
26+
hole_width: 3,
27+
hole_height: 2,
28+
},
29+
{
30+
type: "pcb_hole",
31+
pcb_hole_id: "pcb_hole_circle_0",
32+
x: 4,
33+
y: 0,
34+
hole_shape: "circle",
35+
hole_diameter: 2,
36+
},
37+
{
38+
type: "pcb_hole",
39+
pcb_hole_id: "pcb_hole_rect_1",
40+
x: 0,
41+
y: -4,
42+
hole_shape: "rect",
43+
hole_width: 2,
44+
hole_height: 4,
45+
},
46+
] as any
47+
}
48+
/>
49+
</div>
50+
)
51+
}
52+
53+
export default RectangularHole

src/lib/convert-element-to-primitive.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,28 @@ export const convertElementToPrimitives = (
309309
ccw_rotation: (element as PcbHoleRotatedPill).ccw_rotation,
310310
},
311311
]
312+
} else if (element.hole_shape === "rect") {
313+
const { x, y, hole_width, hole_height } = element
314+
315+
if (typeof hole_width !== "number" || typeof hole_height !== "number") {
316+
return []
317+
}
318+
319+
return [
320+
{
321+
_pcb_drawing_object_id: `rect_${globalPcbDrawingObjectCount++}`,
322+
pcb_drawing_type: "rect",
323+
x,
324+
y,
325+
w: hole_width,
326+
h: hole_height,
327+
layer: "drill",
328+
_element: element,
329+
_parent_pcb_component,
330+
_parent_source_component,
331+
},
332+
]
312333
}
313-
// TODO square hole
314334
// TODO oval hole
315335
return []
316336
}

0 commit comments

Comments
 (0)