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
15 changes: 13 additions & 2 deletions src/pcb/pcb_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const pcb_trace_route_point_wire = z.object({
start_pcb_port_id: z.string().optional(),
end_pcb_port_id: z.string().optional(),
layer: layer_ref,
color: z.string().optional(),
})

export const pcb_trace_route_point_via = z.object({
Expand All @@ -22,6 +23,8 @@ export const pcb_trace_route_point_via = z.object({
outer_diameter: distance.optional(),
from_layer: z.string(),
to_layer: z.string(),
// Allow color to be specified on vias for type uniformity, though it may be ignored downstream
color: z.string().optional(),
})

export const pcb_trace_route_point = z.union([
Expand All @@ -46,7 +49,10 @@ export const pcb_trace = z
should_round_corners: z.boolean().optional(),
trace_length: z.number().optional(),
rats_nest_color: z.string().optional(),
route: z.array(pcb_trace_route_point),
// Non-empty route to avoid undefined at index 0 in consumers/tests
route: z.tuple([pcb_trace_route_point]).rest(pcb_trace_route_point),
// Optional explicit color for entire trace; per-point colors take precedence downstream
color: z.string().optional(),
})
.describe("Defines a trace on the PCB")

Expand All @@ -61,6 +67,7 @@ export interface PcbTraceRoutePointWire {
start_pcb_port_id?: string
end_pcb_port_id?: string
layer: LayerRef
color?: string
}

export interface PcbTraceRoutePointVia {
Expand All @@ -71,6 +78,7 @@ export interface PcbTraceRoutePointVia {
outer_diameter?: Distance
from_layer: string
to_layer: string
color?: string
}

export type PcbTraceRoutePoint = PcbTraceRoutePointWire | PcbTraceRoutePointVia
Expand All @@ -96,7 +104,10 @@ export interface PcbTrace {
should_round_corners?: boolean
trace_length?: number
rats_nest_color?: string
route: Array<PcbTraceRoutePoint>
// At least one route point is required
route: [PcbTraceRoutePoint, ...PcbTraceRoutePoint[]]
// Optional explicit color at trace-level
color?: string
}

/**
Expand Down
58 changes: 43 additions & 15 deletions src/schematic/schematic_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface SchematicTraceEdge {
is_crossing?: boolean
from_schematic_port_id?: string
to_schematic_port_id?: string
color?: string
}

export interface SchematicTrace {
Expand All @@ -28,36 +29,63 @@ export interface SchematicTrace {
subcircuit_id?: string
/** Optional for now, but will be required in a future release */
subcircuit_connectivity_map_key?: string
color?: string
}

export const schematic_trace = z.object({
type: z.literal("schematic_trace"),
schematic_trace_id: z.string(),
source_trace_id: z.string().optional(),
junctions: z.array(
z.object({
x: z.number(),
y: z.number(),
}),
),
edges: z.array(
z.object({
from: z.object({
junctions: z
.tuple([
z.object({
x: z.number(),
y: z.number(),
}),
to: z.object({
])
.rest(
z.object({
x: z.number(),
y: z.number(),
}),
is_crossing: z.boolean().optional(),
from_schematic_port_id: z.string().optional(),
to_schematic_port_id: z.string().optional(),
}),
),
),
edges: z
.tuple([
z.object({
from: z.object({
x: z.number(),
y: z.number(),
}),
to: z.object({
x: z.number(),
y: z.number(),
}),
is_crossing: z.boolean().optional(),
from_schematic_port_id: z.string().optional(),
to_schematic_port_id: z.string().optional(),
color: z.string().optional(),
}),
])
.rest(
z.object({
from: z.object({
x: z.number(),
y: z.number(),
}),
to: z.object({
x: z.number(),
y: z.number(),
}),
is_crossing: z.boolean().optional(),
from_schematic_port_id: z.string().optional(),
to_schematic_port_id: z.string().optional(),
color: z.string().optional(),
}),
),
subcircuit_id: z.string().optional(),
// TODO: make required in a future release
subcircuit_connectivity_map_key: z.string().optional(),
color: z.string().optional(),
})

export type SchematicTraceInput = z.input<typeof schematic_trace>
Expand Down