Skip to content

Commit 65b978f

Browse files
support pill hole & square pad pcb_plated_hole (#352)
1 parent 16135b0 commit 65b978f

File tree

5 files changed

+130
-13
lines changed

5 files changed

+130
-13
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { PCBViewer } from "../PCBViewer"
2+
3+
export const PlatedHoleRotatedPillWithRectPad: React.FC = () => {
4+
return (
5+
<div style={{ backgroundColor: "black" }}>
6+
<PCBViewer
7+
circuitJson={
8+
[
9+
{
10+
x: 0,
11+
y: 0,
12+
type: "pcb_plated_hole",
13+
shape: "rotated_pill_hole_with_rect_pad",
14+
layers: ["top", "bottom"],
15+
port_hints: ["1"],
16+
pcb_port_id: "pcb_port_1001",
17+
hole_height: 2,
18+
hole_width: 4,
19+
hole_ccw_rotation: 45,
20+
rect_pad_width: 5,
21+
rect_pad_height: 3,
22+
rect_ccw_rotation: 45,
23+
pcb_component_id: "pcb_component_1001",
24+
pcb_plated_hole_id: "pcb_plated_hole_1001",
25+
},
26+
{
27+
x: 6,
28+
y: 0,
29+
type: "pcb_plated_hole",
30+
shape: "rotated_pill_hole_with_rect_pad",
31+
layers: ["top", "bottom"],
32+
port_hints: ["1"],
33+
pcb_port_id: "pcb_port_1002",
34+
hole_height: 2,
35+
hole_width: 4,
36+
hole_ccw_rotation: 0,
37+
rect_pad_width: 5,
38+
rect_pad_height: 3,
39+
rect_ccw_rotation: 0,
40+
pcb_component_id: "pcb_component_1002",
41+
pcb_plated_hole_id: "pcb_plated_hole_1002",
42+
},
43+
] as any
44+
}
45+
/>
46+
</div>
47+
)
48+
}
49+
50+
export default PlatedHoleRotatedPillWithRectPad

src/lib/Drawer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,29 @@ export class Drawer {
286286
ctx.restore()
287287
}
288288

289+
rotatedPill(
290+
x: number,
291+
y: number,
292+
w: number,
293+
h: number,
294+
ccw_rotation: Rotation,
295+
) {
296+
const ctx = this.getLayerCtx()
297+
this.applyAperture()
298+
299+
ctx.save()
300+
301+
const [centerX, centerY] = applyToPoint(this.transform, [x, y])
302+
ctx.translate(centerX, centerY)
303+
const cw_rotation = 360 - ccw_rotation
304+
if (ccw_rotation) ctx.rotate((cw_rotation * Math.PI) / 180)
305+
ctx.translate(-centerX, -centerY)
306+
307+
this.pill(x, y, w, h)
308+
309+
ctx.restore()
310+
}
311+
289312
circle(x: number, y: number, r: number, mesh_fill?: boolean) {
290313
const r$ = scaleOnly(this.transform, r)
291314
const [x$, y$] = applyToPoint(this.transform, [x, y])

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const convertElementToPrimitives = (
138138
_parent_pcb_component,
139139
_parent_source_component,
140140
_source_port,
141+
ccw_rotation: (element as any).ccw_rotation,
141142
},
142143
]
143144
} else if (element.shape === "circle") {
@@ -333,6 +334,45 @@ export const convertElementToPrimitives = (
333334
layer: "drill", // Pill-shaped hole in drill layer
334335
},
335336
]
337+
} else if (element.shape === "rotated_pill_hole_with_rect_pad") {
338+
const {
339+
x,
340+
y,
341+
hole_width,
342+
hole_height,
343+
hole_ccw_rotation,
344+
rect_pad_width,
345+
rect_pad_height,
346+
rect_ccw_rotation,
347+
} = element as any // Use as any to access new properties
348+
349+
return [
350+
{
351+
_pcb_drawing_object_id: `rect_${globalPcbDrawingObjectCount++}`,
352+
pcb_drawing_type: "rect",
353+
x,
354+
y,
355+
w: rect_pad_width,
356+
h: rect_pad_height,
357+
layer: "top", // Rectangular pad on top layer
358+
_element: element,
359+
_parent_pcb_component,
360+
_parent_source_component,
361+
_source_port,
362+
ccw_rotation: rect_ccw_rotation,
363+
},
364+
{
365+
_pcb_drawing_object_id: `pill_${globalPcbDrawingObjectCount++}`,
366+
_element: element,
367+
pcb_drawing_type: "pill",
368+
x,
369+
y,
370+
w: hole_width,
371+
h: hole_height,
372+
layer: "drill", // Pill-shaped hole in drill layer
373+
ccw_rotation: hole_ccw_rotation,
374+
},
375+
]
336376
} else {
337377
return []
338378
}

src/lib/draw-primitives.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,21 @@ export const drawRect = (drawer: Drawer, rect: Rect) => {
157157
})
158158
}
159159

160-
export const drawRotatedRect = (
161-
drawer: Drawer,
162-
rect: Rect & { ccw_rotation: Rotation },
163-
) => {
160+
export const drawRotatedRect = (drawer: Drawer, rect: Rect) => {
164161
drawer.equip({
165162
color: getColor(rect),
166163
layer: rect.layer,
167164
})
168165

169-
drawer.rotatedRect(rect.x, rect.y, rect.w, rect.h, rect.ccw_rotation)
166+
drawer.rotatedRect(rect.x, rect.y, rect.w, rect.h, rect.ccw_rotation!)
167+
}
168+
169+
export const drawRotatedPill = (drawer: Drawer, pill: Pill) => {
170+
drawer.equip({
171+
color: getColor(pill),
172+
layer: pill.layer,
173+
})
174+
drawer.rotatedPill(pill.x, pill.y, pill.w, pill.h, pill.ccw_rotation!)
170175
}
171176

172177
export const drawCircle = (drawer: Drawer, circle: Circle) => {
@@ -208,21 +213,18 @@ export const drawPrimitive = (drawer: Drawer, primitive: Primitive) => {
208213
case "text":
209214
return drawText(drawer, primitive)
210215
case "rect":
211-
// @ts-ignore
212-
if (primitive._element?.shape === "rotated_rect") {
213-
return drawRotatedRect(drawer, {
214-
...primitive,
215-
// @ts-ignore
216-
ccw_rotation: primitive._element.ccw_rotation,
217-
mesh_fill: primitive.mesh_fill,
218-
})
216+
if (primitive.ccw_rotation) {
217+
return drawRotatedRect(drawer, primitive)
219218
}
220219
return drawRect(drawer, primitive)
221220
case "circle":
222221
return drawCircle(drawer, primitive)
223222
case "oval":
224223
return drawOval(drawer, primitive)
225224
case "pill":
225+
if (primitive.ccw_rotation) {
226+
return drawRotatedPill(drawer, primitive)
227+
}
226228
return drawPill(drawer, primitive)
227229
case "polygon":
228230
return drawPolygon(drawer, primitive)

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface Rect extends PCBDrawingObject {
6161
is_filled?: boolean
6262
has_stroke?: boolean
6363
is_stroke_dashed?: boolean
64+
ccw_rotation?: number
6465
}
6566

6667
export interface Circle extends PCBDrawingObject {
@@ -85,6 +86,7 @@ export interface Pill extends PCBDrawingObject {
8586
y: number
8687
w: number
8788
h: number
89+
ccw_rotation?: number
8890
}
8991

9092
export interface Polygon extends PCBDrawingObject {

0 commit comments

Comments
 (0)