diff --git a/scripts/refactor.ts b/scripts/refactor.ts index 8dde538..c3f76c9 100644 --- a/scripts/refactor.ts +++ b/scripts/refactor.ts @@ -5,24 +5,55 @@ import fs from "node:fs" const anthropic = new Anthropic() -const filePath = "./src/pcb/pcb_board.ts" -const fileContents = fs.readFileSync(filePath, "utf8") +const filePaths = [ + "./src/pcb/pcb_fabrication_note_path.ts", + "./src/pcb/pcb_component.ts", + "./src/pcb/pcb_port_not_matched_error.ts", + "./src/pcb/pcb_silkscreen_text.ts", + "./src/pcb/pcb_trace_error.ts", + "./src/pcb/pcb_silkscreen_pill.ts", + "./src/pcb/pcb_plated_hole.ts", + "./src/pcb/pcb_fabrication_note_text.ts", + "./src/pcb/pcb_silkscreen_circle.ts", + "./src/pcb/pcb_silkscreen_path.ts", + "./src/pcb/pcb_text.ts", + "./src/pcb/pcb_keepout.ts", + "./src/pcb/pcb_via.ts", + // "./src/pcb/properties/supplier_name.ts", + // "./src/pcb/properties/pcb_route_hints.ts", + // "./src/pcb/properties/layer_ref.ts", + // "./src/pcb/properties/route_hint_point.ts", + "./src/pcb/pcb_silkscreen_oval.ts", + "./src/pcb/pcb_placement_error.ts", + "./src/pcb/pcb_port.ts", + "./src/pcb/pcb_silkscreen_rect.ts", + "./src/pcb/pcb_trace_hint.ts", + "./src/pcb/pcb_smtpad.ts", + "./src/pcb/pcb_silkscreen_line.ts", + "./src/pcb/pcb_hole.ts", + "./src/pcb/pcb_trace.ts", + // "./src/pcb/pcb_board.ts", +] -const msg = await anthropic.messages.create({ - model: "claude-3-sonnet-20240229", - max_tokens: 4000, - messages: [ - { - role: "user", - content: `${refactorTemplate.replace(/\$\{PATHNAME\}/g, filePath).replace(/\$\{FILECONTENTS\}/g, fileContents)}`, - }, - ], -}) +for (const filePath of filePaths) { + const fileContents = fs.readFileSync(filePath, "utf8") -const resText: string = (msg as any).content[0].text - .split("```")[1] - .replace(/^ts\n/, "") + const msg = await anthropic.messages.create({ + model: "claude-3-sonnet-20240229", + max_tokens: 4000, + messages: [ + { + role: "user", + content: `${refactorTemplate.replace(/\$\{PATHNAME\}/g, filePath).replace(/\$\{FILECONTENTS\}/g, fileContents)}`, + }, + ], + }) -// Replace the file -console.log(`Replacing ${filePath} with ai-refactored version`) -fs.writeFileSync(filePath, resText) + const resText: string = (msg as any).content[0].text + .split("```")[1] + .replace(/^ts\n/, "") + + // Replace the file + console.log(`Replacing ${filePath} with ai-refactored version`) + fs.writeFileSync(filePath, resText) +} diff --git a/src/pcb/pcb_component.ts b/src/pcb/pcb_component.ts index 1fa1766..fac86d2 100644 --- a/src/pcb/pcb_component.ts +++ b/src/pcb/pcb_component.ts @@ -1,11 +1,10 @@ import { z } from "zod" -import { point, type Point } from "../common" -import { layer_ref, type LayerRef } from "./properties/layer_ref" -import { rotation, length, type Rotation, type Length } from "../units" -import { getZodPrefixedIdWithDefault } from "src/common/getZodPrefixedIdWithDefault" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { rotation, length, type Rotation, type Length } from "src/units" import { expectTypesMatch } from "src/utils/expect-types-match" -export const pcb_component = z +export const pcb_component_zod = z .object({ type: z.literal("pcb_component"), pcb_component_id: getZodPrefixedIdWithDefault("pcb_component"), @@ -18,9 +17,12 @@ export const pcb_component = z }) .describe("Defines a component on the PCB") -export type PCBComponentInput = z.input -type InferredPCBComponent = z.infer +export type PcbComponentInput = z.input +type InferredPcbComponent = z.infer +/** + * Defines a component on the PCB + */ export interface PcbComponent { type: "pcb_component" pcb_component_id: string @@ -37,4 +39,4 @@ export interface PcbComponent { */ export type PCBComponent = PcbComponent -expectTypesMatch(true) +expectTypesMatch(true) diff --git a/src/pcb/pcb_fabrication_note_path.ts b/src/pcb/pcb_fabrication_note_path.ts index a1f657c..ceafb88 100644 --- a/src/pcb/pcb_fabrication_note_path.ts +++ b/src/pcb/pcb_fabrication_note_path.ts @@ -1,8 +1,9 @@ import { z } from "zod" -import { getZodPrefixedIdWithDefault } from "src/common/getZodPrefixedIdWithDefault" -import { visible_layer } from "./properties/layer_ref" -import { point } from "src/common" -import { length } from "src/units" +import { getZodPrefixedIdWithDefault } from "src/common" +import { visible_layer, type LayerRef } from "src/properties/layer_ref" +import { point, type Point } from "src/common" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_fabrication_note_path = z .object({ @@ -20,7 +21,25 @@ export const pcb_fabrication_note_path = z "Defines a fabrication path on the PCB for fabricators or assemblers", ) -export type PcbFabricationNotePath = z.infer -export type PcbFabricationNotePathInput = z.input< - typeof pcb_fabrication_note_path -> +export type PcbFabricationNotePathInput = z.input +type InferredPcbFabricationNotePath = z.infer + +/** + * Defines a fabrication path on the PCB for fabricators or assemblers + */ +export interface PcbFabricationNotePath { + type: "pcb_fabrication_note_path" + pcb_fabrication_note_path_id: string + pcb_component_id: string + layer: LayerRef + route: Point[] + stroke_width: Length + color?: string +} + +/** + * @deprecated use PcbFabricationNotePath + */ +export type PCBFabricationNotePath = PcbFabricationNotePath + +expectTypesMatch(true) diff --git a/src/pcb/pcb_fabrication_note_text.ts b/src/pcb/pcb_fabrication_note_text.ts index acf1e08..60e48aa 100644 --- a/src/pcb/pcb_fabrication_note_text.ts +++ b/src/pcb/pcb_fabrication_note_text.ts @@ -1,8 +1,9 @@ import { z } from "zod" -import { visible_layer } from "./properties/layer_ref" -import { point } from "src/common" -import { distance } from "src/units" +import { point, type Point } from "src/common" +import { distance, type Length } from "src/units" +import { visible_layer, type LayerRef } from "src/properties/layer_ref" import { getZodPrefixedIdWithDefault } from "src/common/getZodPrefixedIdWithDefault" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_fabrication_note_text = z .object({ @@ -25,7 +26,28 @@ export const pcb_fabrication_note_text = z "Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators", ) -export type PcbFabricationNoteText = z.infer -export type PcbFabricationNoteTextInput = z.input< - typeof pcb_fabrication_note_text -> +export type PcbFabricationNoteTextInput = z.input +type InferredPcbFabricationNoteText = z.infer + +/** + * Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators + */ +export interface PcbFabricationNoteText { + type: "pcb_fabrication_note_text" + pcb_fabrication_note_text_id: string + font: "tscircuit2024" + font_size: Length + pcb_component_id: string + text: string + layer: LayerRef + anchor_position: Point + anchor_alignment: "center" | "top_left" | "top_right" | "bottom_left" | "bottom_right" + color?: string +} + +/** + * @deprecated use PcbFabricationNoteText + */ +export type PCBFabricationNoteText = PcbFabricationNoteText + +expectTypesMatch(true) diff --git a/src/pcb/pcb_hole.ts b/src/pcb/pcb_hole.ts index 763e36a..23fc325 100644 --- a/src/pcb/pcb_hole.ts +++ b/src/pcb/pcb_hole.ts @@ -1,9 +1,10 @@ import { z } from "zod" -import { distance } from "../units" +import { distance, type Distance } from "src/units" +import { getZodPrefixedIdWithDefault } from "src/utils/get-zod-prefixed-id-with-default" +import { expectTypesMatch } from "src/utils/expect-types-match" -export const pcb_hole = z - .object({ - pcb_hole_id: z.string(), +export const pcb_hole = z.union([ + z.object({ type: z.literal("pcb_hole"), hole_shape: z .enum(["circle", "square", "round"]) @@ -15,19 +16,38 @@ export const pcb_hole = z hole_diameter: z.number(), x: distance, y: distance, - }) - .or( - z.object({ - pcb_hole_id: z.string(), - type: z.literal("pcb_hole"), - hole_shape: z.literal("oval"), - hole_width: z.number(), - hole_height: z.number(), - x: distance, - y: distance, - }), - ) - .describe("Defines a hole on the PCB") + }), + z.object({ + type: z.literal("pcb_hole"), + pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"), + hole_shape: z.literal("oval"), + hole_width: z.number(), + hole_height: z.number(), + x: distance, + y: distance, + }), +]) + +export type PcbHoleInput = z.input +type InferredPcbHole = z.infer + +/** + * Defines a hole on the PCB + */ +export interface PcbHole { + type: "pcb_hole" + pcb_hole_id: string + hole_shape: "round" | "square" | "oval" + hole_diameter?: number + hole_width?: number + hole_height?: number + x: Distance + y: Distance +} + +/** + * @deprecated use PcbHole + */ +export type PCBHole = PcbHole -export type PCBHoleInput = z.input -export type PCBHole = z.infer +expectTypesMatch(true) diff --git a/src/pcb/pcb_keepout.ts b/src/pcb/pcb_keepout.ts index 5228276..eda9dc9 100644 --- a/src/pcb/pcb_keepout.ts +++ b/src/pcb/pcb_keepout.ts @@ -1,29 +1,61 @@ import { z } from "zod" -import { point } from "../common" -import { distance } from "../units" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { distance, type Distance } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" -export const pcb_keepout = z - .object({ +export const pcb_keepout = z.union([ + z.object({ type: z.literal("pcb_keepout"), shape: z.literal("rect"), + pcb_keepout_id: getZodPrefixedIdWithDefault("pcb_keepout"), center: point, width: distance, height: distance, - pcb_keepout_id: z.string(), layers: z.array(z.string()), // Specify layers where the keepout applies description: z.string().optional(), // Optional description of the keepout - }) - .or( - z.object({ - type: z.literal("pcb_keepout"), - shape: z.literal("circle"), - center: point, - radius: distance, - pcb_keepout_id: z.string(), - layers: z.array(z.string()), // Specify layers where the keepout applies - description: z.string().optional(), // Optional description of the keepout - }), - ) + }), + z.object({ + type: z.literal("pcb_keepout"), + shape: z.literal("circle"), + pcb_keepout_id: getZodPrefixedIdWithDefault("pcb_keepout"), + center: point, + radius: distance, + layers: z.array(z.string()), // Specify layers where the keepout applies + description: z.string().optional(), // Optional description of the keepout + }), +]) + +export type PcbKeepoutInput = z.input +type InferredPcbKeepout = z.infer + +/** + * Defines a keepout area on the PCB, which can be either a rectangle or a circle. + * The keepout area is specified for one or more layers, and an optional description can be provided. + */ +export interface PcbKeepout { + type: "pcb_keepout" + pcb_keepout_id: string + center: Point + layers: string[] + description?: string +} + +// Rectangular Keepout +export interface PcbKeepoutRect extends PcbKeepout { + shape: "rect" + width: Distance + height: Distance +} + +// Circular Keepout +export interface PcbKeepoutCircle extends PcbKeepout { + shape: "circle" + radius: Distance +} + +/** + * @deprecated use PcbKeepout + */ +export type PCBKeepout = PcbKeepout -export type PCBKeepoutInput = z.input -export type PCBKeepout = z.infer +expectTypesMatch(true) diff --git a/src/pcb/pcb_placement_error.ts b/src/pcb/pcb_placement_error.ts index 9497238..e99ab8e 100644 --- a/src/pcb/pcb_placement_error.ts +++ b/src/pcb/pcb_placement_error.ts @@ -1,13 +1,30 @@ import { z } from "zod" +import { getZodPrefixedIdWithDefault } from "src/common" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_placement_error = z .object({ - pcb_error_id: z.string(), - type: z.literal("pcb_error"), - error_type: z.literal("pcb_placement_error"), + type: z.literal("pcb_placement_error"), + pcb_placement_error_id: getZodPrefixedIdWithDefault("pcb_placement_error"), message: z.string(), }) .describe("Defines a placement error on the PCB") -export type PCBPlacementErrorInput = z.input -export type PCBPlacementError = z.infer +export type PcbPlacementErrorInput = z.input +type InferredPcbPlacementError = z.infer + +/** + * Defines a placement error on the PCB + */ +export interface PcbPlacementError { + type: "pcb_placement_error" + pcb_placement_error_id: string + message: string +} + +/** + * @deprecated use PcbPlacementError + */ +export type PCBPlacementError = PcbPlacementError + +expectTypesMatch(true) diff --git a/src/pcb/pcb_plated_hole.ts b/src/pcb/pcb_plated_hole.ts index 8c949a0..4799364 100644 --- a/src/pcb/pcb_plated_hole.ts +++ b/src/pcb/pcb_plated_hole.ts @@ -1,9 +1,11 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref } from "./properties/layer_ref" +import { distance, type Distance } 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" -export const pcb_plated_hole = z - .object({ +export const pcb_plated_hole = z.union([ + z.object({ type: z.literal("pcb_plated_hole"), shape: z.literal("circle"), outer_diameter: z.number(), @@ -14,26 +16,58 @@ export const pcb_plated_hole = z port_hints: z.array(z.string()).optional(), pcb_component_id: z.string().optional(), pcb_port_id: z.string().optional(), - pcb_plated_hole_id: z.string(), - }) - .or( - z.object({ - type: z.literal("pcb_plated_hole"), - shape: z.enum(["oval", "pill"]), - outer_width: z.number(), - outer_height: z.number(), - hole_width: z.number(), - hole_height: z.number(), - 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_plated_hole_id: z.string(), - }), - ) + pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole"), + }), + z.object({ + type: z.literal("pcb_plated_hole"), + shape: z.enum(["oval", "pill"]), + outer_width: z.number(), + outer_height: z.number(), + hole_width: z.number(), + hole_height: z.number(), + 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_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole"), + }), +]) .describe("Defines a plated hole on the PCB") -export type PCBPlatedHoleInput = z.input -export type PCBPlatedHole = z.infer +export type PcbPlatedHoleInput = z.input +type InferredPcbPlatedHole = z.infer + +/** + * Defines a plated hole on the PCB + */ +export interface PcbPlatedHole { + type: "pcb_plated_hole" + shape: "circle" | "oval" | "pill" + outer_diameter?: number + outer_width?: number + outer_height?: number + hole_diameter?: number + hole_width?: number + hole_height?: number + x: Distance + y: Distance + layers: LayerRef[] + port_hints?: string[] + pcb_component_id?: string + pcb_port_id?: string + pcb_plated_hole_id: string +} + +/** + * @deprecated use PcbPlatedHole + */ +export type PCBPlatedHole = PcbPlatedHole + +/** + * @deprecated use PcbPlatedHoleInput + */ +export type PCBPlatedHoleInput = PcbPlatedHoleInput + +expectTypesMatch(true) diff --git a/src/pcb/pcb_port.ts b/src/pcb/pcb_port.ts index 4f15c66..ecd4167 100644 --- a/src/pcb/pcb_port.ts +++ b/src/pcb/pcb_port.ts @@ -1,11 +1,12 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref } from "./properties/layer_ref" +import { distance, type Distance, getZodPrefixedIdWithDefault } from "src/units" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_port = z .object({ type: z.literal("pcb_port"), - pcb_port_id: z.string(), + pcb_port_id: getZodPrefixedIdWithDefault("pcb_port"), source_port_id: z.string(), pcb_component_id: z.string(), x: distance, @@ -14,5 +15,30 @@ export const pcb_port = z }) .describe("Defines a port on the PCB") -export type PCBPort = z.infer -export type PCBPortInput = z.input +export type PcbPortInput = z.input +type InferredPcbPort = z.infer + +/** + * Defines a port on the PCB + */ +export interface PcbPort { + type: "pcb_port" + pcb_port_id: string + source_port_id: string + pcb_component_id: string + x: Distance + y: Distance + layers: LayerRef[] +} + +/** + * @deprecated use PcbPort + */ +export type PCBPort = PcbPort + +/** + * @deprecated use PcbPortInput + */ +export type PCBPortInput = PcbPortInput + +expectTypesMatch(true) diff --git a/src/pcb/pcb_port_not_matched_error.ts b/src/pcb/pcb_port_not_matched_error.ts index 4933c0f..5373f32 100644 --- a/src/pcb/pcb_port_not_matched_error.ts +++ b/src/pcb/pcb_port_not_matched_error.ts @@ -1,16 +1,32 @@ import { z } from "zod" +import { getZodPrefixedIdWithDefault } from "src/common" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_port_not_matched_error = z .object({ - pcb_error_id: z.string(), - type: z.literal("pcb_error"), - error_type: z.literal("pcb_port_not_matched_error"), + type: z.literal("pcb_port_not_matched_error"), + pcb_error_id: getZodPrefixedIdWithDefault("pcb_error"), message: z.string(), pcb_component_ids: z.array(z.string()), }) - .describe("Defines a trace error on the PCB") + .describe("Defines a trace error on the PCB where a port is not matched") -export type PCBPortNotMatchedErrorInput = z.input< - typeof pcb_port_not_matched_error -> -export type PCBPortNotMatchedError = z.infer +export type PcbPortNotMatchedErrorInput = z.input +type InferredPcbPortNotMatchedError = z.infer + +/** + * Defines a trace error on the PCB where a port is not matched + */ +export interface PcbPortNotMatchedError { + type: "pcb_port_not_matched_error" + pcb_error_id: string + message: string + pcb_component_ids: string[] +} + +/** + * @deprecated use PcbPortNotMatchedError + */ +export type PCBPortNotMatchedError = PcbPortNotMatchedError + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_circle.ts b/src/pcb/pcb_silkscreen_circle.ts index f1facb4..836826e 100644 --- a/src/pcb/pcb_silkscreen_circle.ts +++ b/src/pcb/pcb_silkscreen_circle.ts @@ -1,18 +1,38 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref, visible_layer } from "./properties/layer_ref" -import { point } from "src/common/point" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_circle = z .object({ type: z.literal("pcb_silkscreen_circle"), - pcb_silkscreen_circle_id: z.string(), + pcb_silkscreen_circle_id: getZodPrefixedIdWithDefault("pcb_silkscreen_circle"), pcb_component_id: z.string(), center: point, - radius: distance, - layer: visible_layer, + radius: length, + layer: layer_ref, }) .describe("Defines a silkscreen circle on the PCB") -export type PcbSilkscreenCircle = z.infer export type PcbSilkscreenCircleInput = z.input +type InferredPcbSilkscreenCircle = z.infer + +/** + * Defines a silkscreen circle on the PCB + */ +export interface PcbSilkscreenCircle { + type: "pcb_silkscreen_circle" + pcb_silkscreen_circle_id: string + pcb_component_id: string + center: Point + radius: Length + layer: LayerRef +} + +/** + * @deprecated use PcbSilkscreenCircle + */ +export type PcbSilkscreenCircleInput = PcbSilkscreenCircleInput + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_line.ts b/src/pcb/pcb_silkscreen_line.ts index 84c1b11..07895a6 100644 --- a/src/pcb/pcb_silkscreen_line.ts +++ b/src/pcb/pcb_silkscreen_line.ts @@ -1,11 +1,13 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref, visible_layer } from "./properties/layer_ref" +import { distance, type Distance } from "src/units" +import { layer_ref, type LayerRef, visible_layer } from "src/properties/layer_ref" +import { getZodPrefixedIdWithDefault } from "src/common" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_line = z .object({ type: z.literal("pcb_silkscreen_line"), - pcb_silkscreen_line_id: z.string(), + pcb_silkscreen_line_id: getZodPrefixedIdWithDefault("pcb_silkscreen_line"), pcb_component_id: z.string(), stroke_width: distance.default("0.1mm"), x1: distance, @@ -16,5 +18,27 @@ export const pcb_silkscreen_line = z }) .describe("Defines a silkscreen line on the PCB") -export type PcbSilkscreenLine = z.infer export type PcbSilkscreenLineInput = z.input +type InferredPcbSilkscreenLine = z.infer + +/** + * Defines a silkscreen line on the PCB + */ +export interface PcbSilkscreenLine { + type: "pcb_silkscreen_line" + pcb_silkscreen_line_id: string + pcb_component_id: string + stroke_width: Distance + x1: Distance + y1: Distance + x2: Distance + y2: Distance + layer: LayerRef +} + +/** + * @deprecated use PcbSilkscreenLine + */ +export type PCBSilkscreenLine = PcbSilkscreenLine + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_oval.ts b/src/pcb/pcb_silkscreen_oval.ts index dbd47c6..eb76872 100644 --- a/src/pcb/pcb_silkscreen_oval.ts +++ b/src/pcb/pcb_silkscreen_oval.ts @@ -1,12 +1,13 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref, visible_layer } from "./properties/layer_ref" -import { point } from "src/common/point" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef, visible_layer, type VisibleLayer } from "src/properties/layer_ref" +import { distance, type Distance } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_oval = z .object({ type: z.literal("pcb_silkscreen_oval"), - pcb_silkscreen_oval_id: z.string(), + pcb_silkscreen_oval_id: getZodPrefixedIdWithDefault("pcb_silkscreen_oval"), pcb_component_id: z.string(), center: point, radius_x: distance, @@ -15,5 +16,25 @@ export const pcb_silkscreen_oval = z }) .describe("Defines a silkscreen oval on the PCB") -export type PcbSilkscreenOval = z.infer export type PcbSilkscreenOvalInput = z.input +type InferredPcbSilkscreenOval = z.infer + +/** + * Defines a silkscreen oval on the PCB + */ +export interface PcbSilkscreenOval { + type: "pcb_silkscreen_oval" + pcb_silkscreen_oval_id: string + pcb_component_id: string + center: Point + radius_x: Distance + radius_y: Distance + layer: VisibleLayer +} + +/** + * @deprecated use PcbSilkscreenOval + */ +export type PcbSilkscreenOvalDeprecated = PcbSilkscreenOval + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_path.ts b/src/pcb/pcb_silkscreen_path.ts index e9b33e9..d33cfd6 100644 --- a/src/pcb/pcb_silkscreen_path.ts +++ b/src/pcb/pcb_silkscreen_path.ts @@ -1,12 +1,13 @@ import { z } from "zod" -import { visible_layer } from "./properties/layer_ref" -import { point } from "src/common" -import { length } from "src/units" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { visible_layer, type LayerRef } from "src/properties/layer_ref" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_path = z .object({ type: z.literal("pcb_silkscreen_path"), - pcb_silkscreen_path_id: z.string(), + pcb_silkscreen_path_id: getZodPrefixedIdWithDefault("pcb_silkscreen_path"), pcb_component_id: z.string(), layer: visible_layer, route: z.array(point), @@ -14,5 +15,24 @@ export const pcb_silkscreen_path = z }) .describe("Defines a silkscreen path on the PCB") -export type PcbSilkscreenPath = z.infer export type PcbSilkscreenPathInput = z.input +type InferredPcbSilkscreenPath = z.infer + +/** + * Defines a silkscreen path on the PCB + */ +export interface PcbSilkscreenPath { + type: "pcb_silkscreen_path" + pcb_silkscreen_path_id: string + pcb_component_id: string + layer: LayerRef + route: Point[] + stroke_width: Length +} + +/** + * @deprecated use PcbSilkscreenPath + */ +export type PcbSilkscreenPathDeprecated = PcbSilkscreenPath + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_pill.ts b/src/pcb/pcb_silkscreen_pill.ts index 8e7cb43..415d269 100644 --- a/src/pcb/pcb_silkscreen_pill.ts +++ b/src/pcb/pcb_silkscreen_pill.ts @@ -1,19 +1,40 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref, visible_layer } from "./properties/layer_ref" -import { point } from "src/common/point" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_pill = z .object({ type: z.literal("pcb_silkscreen_pill"), - pcb_silkscreen_pill_id: z.string(), + pcb_silkscreen_pill_id: getZodPrefixedIdWithDefault("pcb_silkscreen_pill"), pcb_component_id: z.string(), center: point, - width: distance, - height: distance, - layer: visible_layer, + width: length, + height: length, + layer: layer_ref, }) .describe("Defines a silkscreen pill on the PCB") -export type PcbSilkscreenPill = z.infer export type PcbSilkscreenPillInput = z.input +type InferredPcbSilkscreenPill = z.infer + +/** + * Defines a silkscreen pill on the PCB + */ +export interface PcbSilkscreenPill { + type: "pcb_silkscreen_pill" + pcb_silkscreen_pill_id: string + pcb_component_id: string + center: Point + width: Length + height: Length + layer: LayerRef +} + +/** + * @deprecated use PcbSilkscreenPill + */ +export type PcbSilkscreenPillDeprecated = PcbSilkscreenPill + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_rect.ts b/src/pcb/pcb_silkscreen_rect.ts index d1ae153..37dc9f3 100644 --- a/src/pcb/pcb_silkscreen_rect.ts +++ b/src/pcb/pcb_silkscreen_rect.ts @@ -1,19 +1,40 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref, visible_layer } from "./properties/layer_ref" -import { point } from "src/common/point" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_rect = z .object({ type: z.literal("pcb_silkscreen_rect"), - pcb_silkscreen_rect_id: z.string(), + pcb_silkscreen_rect_id: getZodPrefixedIdWithDefault("pcb_silkscreen_rect"), pcb_component_id: z.string(), center: point, - width: distance, - height: distance, - layer: visible_layer, + width: length, + height: length, + layer: layer_ref, }) .describe("Defines a silkscreen rect on the PCB") -export type PcbSilkscreenRect = z.infer export type PcbSilkscreenRectInput = z.input +type InferredPcbSilkscreenRect = z.infer + +/** + * Defines a silkscreen rect on the PCB + */ +export interface PcbSilkscreenRect { + type: "pcb_silkscreen_rect" + pcb_silkscreen_rect_id: string + pcb_component_id: string + center: Point + width: Length + height: Length + layer: LayerRef +} + +/** + * @deprecated use PcbSilkscreenRect + */ +export type PcbSilkscreenRectOld = PcbSilkscreenRect + +expectTypesMatch(true) diff --git a/src/pcb/pcb_silkscreen_text.ts b/src/pcb/pcb_silkscreen_text.ts index 93ee5c4..8ebf1c6 100644 --- a/src/pcb/pcb_silkscreen_text.ts +++ b/src/pcb/pcb_silkscreen_text.ts @@ -1,16 +1,18 @@ import { z } from "zod" -import { visible_layer } from "./properties/layer_ref" -import { point } from "src/common" -import { distance } from "src/units" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { distance, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_silkscreen_text = z .object({ type: z.literal("pcb_silkscreen_text"), + pcb_silkscreen_text_id: getZodPrefixedIdWithDefault("pcb_silkscreen_text"), font: z.literal("tscircuit2024").default("tscircuit2024"), font_size: distance.default("0.2mm"), pcb_component_id: z.string(), text: z.string(), - layer: visible_layer, + layer: layer_ref, anchor_position: point.default({ x: 0, y: 0 }), anchor_alignment: z .enum(["center", "top_left", "top_right", "bottom_left", "bottom_right"]) @@ -18,5 +20,27 @@ export const pcb_silkscreen_text = z }) .describe("Defines silkscreen text on the PCB") -export type PcbSilkscreenText = z.infer export type PcbSilkscreenTextInput = z.input +type InferredPcbSilkscreenText = z.infer + +/** + * Defines silkscreen text on the PCB + */ +export interface PcbSilkscreenText { + type: "pcb_silkscreen_text" + pcb_silkscreen_text_id: string + font: "tscircuit2024" + font_size: Length + pcb_component_id: string + text: string + layer: LayerRef + anchor_position: Point + anchor_alignment: "center" | "top_left" | "top_right" | "bottom_left" | "bottom_right" +} + +/** + * @deprecated use PcbSilkscreenText + */ +export type PCBSilkscreenText = PcbSilkscreenText + +expectTypesMatch(true) diff --git a/src/pcb/pcb_smtpad.ts b/src/pcb/pcb_smtpad.ts index b0955da..940ec27 100644 --- a/src/pcb/pcb_smtpad.ts +++ b/src/pcb/pcb_smtpad.ts @@ -1,36 +1,61 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref } from "./properties/layer_ref" +import { distance, type Distance, getZodPrefixedIdWithDefault } from "src/units" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { expectTypesMatch } from "src/utils/expect-types-match" -export const pcb_smtpad = z - .union([ - z.object({ - pcb_smtpad_id: z.string(), - type: z.literal("pcb_smtpad"), - shape: z.literal("circle"), - x: distance, - y: distance, - radius: z.number(), - layer: layer_ref, - port_hints: z.array(z.string()).optional(), - pcb_component_id: z.string().optional(), - pcb_port_id: z.string().optional(), - }), - z.object({ - pcb_smtpad_id: z.string(), - type: z.literal("pcb_smtpad"), - shape: z.literal("rect"), - x: distance, - y: distance, - width: z.number(), - height: z.number(), - layer: layer_ref, - port_hints: z.array(z.string()).optional(), - pcb_component_id: z.string().optional(), - pcb_port_id: z.string().optional(), - }), - ]) +export const pcb_smtpad = z.union([ + z.object({ + pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"), + type: z.literal("pcb_smtpad"), + shape: z.literal("circle"), + x: distance, + y: distance, + radius: z.number(), + layer: layer_ref, + port_hints: z.array(z.string()).optional(), + pcb_component_id: z.string().optional(), + pcb_port_id: z.string().optional(), + }), + z.object({ + pcb_smtpad_id: getZodPrefixedIdWithDefault("pcb_smtpad"), + type: z.literal("pcb_smtpad"), + shape: z.literal("rect"), + x: distance, + y: distance, + width: z.number(), + height: z.number(), + layer: layer_ref, + port_hints: z.array(z.string()).optional(), + pcb_component_id: z.string().optional(), + pcb_port_id: z.string().optional(), + }), +]) .describe("Defines an SMT pad on the PCB") export type PCBSMTPadInput = z.input -export type PCBSMTPad = z.infer +type InferredPCBSMTPad = z.infer + +/** + * Defines an SMT pad on the PCB + */ +export interface PcbSmtPad { + pcb_smtpad_id: string + type: "pcb_smtpad" + shape: "circle" | "rect" + x: Distance + y: Distance + radius?: number + width?: number + height?: number + layer: LayerRef + port_hints?: string[] + pcb_component_id?: string + pcb_port_id?: string +} + +/** + * @deprecated use PcbSmtPad + */ +export type PCBSMTPad = PcbSmtPad + +expectTypesMatch(true) diff --git a/src/pcb/pcb_text.ts b/src/pcb/pcb_text.ts index 965b933..1bf5109 100644 --- a/src/pcb/pcb_text.ts +++ b/src/pcb/pcb_text.ts @@ -1,18 +1,44 @@ import { z } from "zod" -import { distance } from "../units" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { length, type Length } from "src/units" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_text = z .object({ type: z.literal("pcb_text"), + pcb_text_id: getZodPrefixedIdWithDefault("pcb_text"), text: z.string(), - x: distance, - y: distance, - align: z.enum(["bottom-left"]), - width: distance, - height: distance, + center: point, + layer: layer_ref, + width: length, + height: length, lines: z.number(), + align: z.enum(["bottom-left"]), }) .describe("Defines text on the PCB") -export type PCBTextInput = z.input -export type PCBText = z.infer +export type PcbTextInput = z.input +type InferredPcbText = z.infer + +/** + * Defines text on the PCB + */ +export interface PcbText { + type: "pcb_text" + pcb_text_id: string + text: string + center: Point + layer: LayerRef + width: Length + height: Length + lines: number + align: "bottom-left" +} + +/** + * @deprecated use PcbText + */ +export type PCBText = PcbText + +expectTypesMatch(true) diff --git a/src/pcb/pcb_trace.ts b/src/pcb/pcb_trace.ts index 434552a..24338a4 100644 --- a/src/pcb/pcb_trace.ts +++ b/src/pcb/pcb_trace.ts @@ -1,38 +1,83 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref } from "./properties/layer_ref" +import { distance, type Distance, getZodPrefixedIdWithDefault } from "src/units" +import { layer_ref, type LayerRef } from "src/properties/layer_ref" +import { expectTypesMatch } from "src/utils/expect-types-match" -export const pcb_trace = z.object({ - type: z.literal("pcb_trace"), - source_trace_id: z.string().optional(), - pcb_component_id: z.string().optional(), - pcb_trace_id: z.string(), - route_thickness_mode: z - .enum(["constant", "interpolated"]) - .default("constant") - .optional(), - should_round_corners: z.boolean().optional(), - route: z.array( - z.union([ - z.object({ - route_type: z.literal("wire"), - x: distance, - y: distance, - width: distance, - start_pcb_port_id: z.string().optional(), - end_pcb_port_id: z.string().optional(), - layer: layer_ref, - }), - z.object({ - route_type: z.literal("via"), - x: distance, - y: distance, - from_layer: z.string(), - to_layer: z.string(), - }), - ]), - ), -}) +export const pcb_trace = z + .object({ + type: z.literal("pcb_trace"), + source_trace_id: z.string().optional(), + pcb_component_id: z.string().optional(), + pcb_trace_id: getZodPrefixedIdWithDefault("pcb_trace"), + route_thickness_mode: z + .enum(["constant", "interpolated"]) + .default("constant") + .optional(), + should_round_corners: z.boolean().optional(), + route: z.array( + z.union([ + z.object({ + route_type: z.literal("wire"), + x: distance, + y: distance, + width: distance, + start_pcb_port_id: z.string().optional(), + end_pcb_port_id: z.string().optional(), + layer: layer_ref, + }), + z.object({ + route_type: z.literal("via"), + x: distance, + y: distance, + from_layer: z.string(), + to_layer: z.string(), + }), + ]), + ), + }) + .describe("Defines a trace on the PCB") -export type PCBTraceInput = z.input -export type PCBTrace = z.output +export type PcbTraceInput = z.input +type InferredPcbTrace = z.infer + +/** + * Defines a trace on the PCB + */ +export interface PcbTrace { + type: "pcb_trace" + source_trace_id?: string + pcb_component_id?: string + pcb_trace_id: string + route_thickness_mode?: "constant" | "interpolated" + should_round_corners?: boolean + route: Array< + | { + route_type: "wire" + x: Distance + y: Distance + width: Distance + start_pcb_port_id?: string + end_pcb_port_id?: string + layer: LayerRef + } + | { + route_type: "via" + x: Distance + y: Distance + from_layer: string + to_layer: string + } + > +} + +/** + * @deprecated use PcbTrace + */ +export type PCBTrace = PcbTrace + +/** + * @deprecated use PcbTraceInput + */ +export type PCBTraceInput = PcbTraceInput + +expectTypesMatch(true) diff --git a/src/pcb/pcb_trace_error.ts b/src/pcb/pcb_trace_error.ts index f609011..101ac5f 100644 --- a/src/pcb/pcb_trace_error.ts +++ b/src/pcb/pcb_trace_error.ts @@ -1,10 +1,11 @@ -import { point } from "src/common" import { z } from "zod" +import { point, type Point, getZodPrefixedIdWithDefault } from "src/common" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_trace_error = z .object({ - pcb_error_id: z.string(), - type: z.literal("pcb_error"), + type: z.literal("pcb_trace_error"), + pcb_trace_error_id: getZodPrefixedIdWithDefault("pcb_trace_error"), error_type: z.literal("pcb_trace_error"), message: z.string(), center: point.optional(), @@ -15,5 +16,27 @@ export const pcb_trace_error = z }) .describe("Defines a trace error on the PCB") -export type PCBTraceErrorInput = z.input -export type PCBTraceError = z.infer +export type PcbTraceErrorInput = z.input +type InferredPcbTraceError = z.infer + +/** + * Defines a trace error on the PCB + */ +export interface PcbTraceError { + type: "pcb_trace_error" + pcb_trace_error_id: string + error_type: "pcb_trace_error" + message: string + center?: Point + pcb_trace_id: string + source_trace_id: string + pcb_component_ids: string[] + pcb_port_ids: string[] +} + +/** + * @deprecated use PcbTraceError + */ +export type PCBTraceError = PcbTraceError + +expectTypesMatch(true) diff --git a/src/pcb/pcb_trace_hint.ts b/src/pcb/pcb_trace_hint.ts index 387ff44..4edda7f 100644 --- a/src/pcb/pcb_trace_hint.ts +++ b/src/pcb/pcb_trace_hint.ts @@ -1,16 +1,34 @@ import { z } from "zod" -import { distance } from "../units" -import { route_hint_point } from "./index" +import { getZodPrefixedIdWithDefault } from "src/common" +import { route_hint_point, type RouteHintPoint } from "src/pcb" + +/** + * A hint that can be used to generate a PCB trace. + */ +export interface PcbTraceHint { + type: "pcb_trace_hint" + pcb_trace_hint_id: string + pcb_port_id: string + pcb_component_id: string + route: RouteHintPoint[] +} export const pcb_trace_hint = z .object({ - pcb_trace_hint_id: z.string(), type: z.literal("pcb_trace_hint"), + pcb_trace_hint_id: getZodPrefixedIdWithDefault("pcb_trace_hint"), pcb_port_id: z.string(), pcb_component_id: z.string(), route: z.array(route_hint_point.optional()), }) .describe("A hint that can be used to generate a PCB trace") -export type PcbTraceHint = z.infer export type PcbTraceHintInput = z.input +type InferredPcbTraceHint = z.infer + +/** + * @deprecated use PcbTraceHint + */ +export type PCBTraceHint = PcbTraceHint + +expectTypesMatch(true) diff --git a/src/pcb/pcb_via.ts b/src/pcb/pcb_via.ts index 6dcf6bc..7eecc1f 100644 --- a/src/pcb/pcb_via.ts +++ b/src/pcb/pcb_via.ts @@ -1,10 +1,12 @@ import { z } from "zod" -import { distance } from "../units" -import { layer_ref } from "./properties/layer_ref" +import { distance, type Distance } from "src/units" +import { layer_ref, type LayerRef, getZodPrefixedIdWithDefault } from "src/properties/layer_ref" +import { expectTypesMatch } from "src/utils/expect-types-match" export const pcb_via = z .object({ type: z.literal("pcb_via"), + pcb_via_id: getZodPrefixedIdWithDefault("pcb_via"), x: distance, y: distance, outer_diameter: distance.default("0.6mm"), @@ -17,5 +19,29 @@ export const pcb_via = z }) .describe("Defines a via on the PCB") -export type PCBViaInput = z.input -export type PCBVia = z.infer +export type PcbViaInput = z.input +type InferredPcbVia = z.infer + +/** + * Defines a via on the PCB + */ +export interface PcbVia { + type: "pcb_via" + pcb_via_id: string + x: Distance + y: Distance + outer_diameter: Distance + hole_diameter: Distance + /** @deprecated */ + from_layer?: LayerRef + /** @deprecated */ + to_layer?: LayerRef + layers: LayerRef[] +} + +/** + * @deprecated use PcbVia + */ +export type PCBVia = PcbVia + +expectTypesMatch(true)