Skip to content
Open
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
1 change: 1 addition & 0 deletions src/any_circuit_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const any_circuit_element = z.union([
pcb.pcb_courtyard_outline,
pcb.pcb_courtyard_polygon,
pcb.pcb_courtyard_circle,
pcb.pcb_thtpad,
sch.schematic_box,
sch.schematic_text,
sch.schematic_line,
Expand Down
1 change: 1 addition & 0 deletions src/pcb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export * from "./pcb_courtyard_rect"
export * from "./pcb_courtyard_outline"
export * from "./pcb_courtyard_polygon"
export * from "./pcb_courtyard_circle"
export * from "./pcb_thtpad"

import type { PcbComponent } from "./pcb_component"
import type { PcbHole } from "./pcb_hole"
Expand Down
133 changes: 133 additions & 0 deletions src/pcb/pcb_thtpad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { z } from "zod"
import { distance, type Distance, rotation, type Rotation } from "src/units"
import { layer_ref, type LayerRef } from "src/pcb/properties/layer_ref"
import { getZodPrefixedIdWithDefault } from "src/common"
import { expectTypesMatch } from "src/utils/expect-types-match"

const pcb_thtpad_circle = z.object({
type: z.literal("pcb_thtpad"),
shape: z.literal("circle"),
pcb_group_id: z.string().optional(),
subcircuit_id: z.string().optional(),
outer_diameter: z.number(),
hole_diameter: z.number(),
is_covered_with_solder_mask: z.boolean().optional(),
x: distance,
y: distance,
layers: z.array(layer_ref),
port_hints: z.array(z.string()).optional(),
pcb_component_id: z.string().optional(),
pcb_port_id: z.string().optional(),
pcb_thtpad_id: getZodPrefixedIdWithDefault("pcb_thtpad"),
soldermask_margin: z.number().optional(),
})

export interface PcbThtPadCircle {
type: "pcb_thtpad"
shape: "circle"
pcb_group_id?: string
subcircuit_id?: string
outer_diameter: number
hole_diameter: number
is_covered_with_solder_mask?: boolean
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_thtpad_id: string
soldermask_margin?: number
}

const pcb_thtpad_rect = z.object({
type: z.literal("pcb_thtpad"),
shape: z.literal("rect"),
pcb_group_id: z.string().optional(),
subcircuit_id: z.string().optional(),
width: z.number(),
height: z.number(),
hole_diameter: z.number(),
is_covered_with_solder_mask: z.boolean().optional(),
x: distance,
y: distance,
layers: z.array(layer_ref),
port_hints: z.array(z.string()).optional(),
pcb_component_id: z.string().optional(),
pcb_port_id: z.string().optional(),
pcb_thtpad_id: getZodPrefixedIdWithDefault("pcb_thtpad"),
soldermask_margin: z.number().optional(),
})

export interface PcbThtPadRect {
type: "pcb_thtpad"
shape: "rect"
pcb_group_id?: string
subcircuit_id?: string
width: number
height: number
hole_diameter: number
is_covered_with_solder_mask?: boolean
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_thtpad_id: string
soldermask_margin?: number
}

const pcb_thtpad_pill = z.object({
type: z.literal("pcb_thtpad"),
shape: z.literal("pill"),
pcb_group_id: z.string().optional(),
subcircuit_id: z.string().optional(),
width: z.number(),
height: z.number(),
hole_diameter: z.number(),
is_covered_with_solder_mask: z.boolean().optional(),
x: distance,
y: distance,
layers: z.array(layer_ref),
port_hints: z.array(z.string()).optional(),
pcb_component_id: z.string().optional(),
pcb_port_id: z.string().optional(),
pcb_thtpad_id: getZodPrefixedIdWithDefault("pcb_thtpad"),
soldermask_margin: z.number().optional(),
ccw_rotation: rotation.optional(),
})

export interface PcbThtPadPill {
type: "pcb_thtpad"
shape: "pill"
pcb_group_id?: string
subcircuit_id?: string
width: number
height: number
hole_diameter: number
is_covered_with_solder_mask?: boolean
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_thtpad_id: string
soldermask_margin?: number
ccw_rotation?: Rotation
}

export const pcb_thtpad = z.union([
pcb_thtpad_circle,
pcb_thtpad_rect,
pcb_thtpad_pill,
])

export type PcbThtPad = PcbThtPadCircle | PcbThtPadRect | PcbThtPadPill

expectTypesMatch<PcbThtPadCircle, z.infer<typeof pcb_thtpad_circle>>(true)
expectTypesMatch<PcbThtPadRect, z.infer<typeof pcb_thtpad_rect>>(true)
expectTypesMatch<PcbThtPadPill, z.infer<typeof pcb_thtpad_pill>>(true)

export type PcbThtPadInput = z.input<typeof pcb_thtpad>