From 9c5e4772a36f008a3a60a31e88c81fd554997323 Mon Sep 17 00:00:00 2001 From: seveibar Date: Fri, 28 Jun 2024 20:35:25 -0700 Subject: [PATCH] cad components initial --- package-lock.json | 4 ++-- src/any_soup_element.ts | 2 ++ src/cad/cad_component_model.ts | 27 +++++++++++++++++++++++++++ src/cad/index.ts | 1 + src/common/index.ts | 1 + src/common/point3.ts | 12 ++++++++++++ src/index.ts | 1 + 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/cad/cad_component_model.ts create mode 100644 src/cad/index.ts create mode 100644 src/common/point3.ts diff --git a/package-lock.json b/package-lock.json index 6242f1a..60436c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tscircuit/soup", - "version": "0.0.28", + "version": "0.0.36", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tscircuit/soup", - "version": "0.0.28", + "version": "0.0.36", "license": "ISC", "dependencies": { "convert-units": "^2.3.4", diff --git a/src/any_soup_element.ts b/src/any_soup_element.ts index 029c5aa..8cb2858 100644 --- a/src/any_soup_element.ts +++ b/src/any_soup_element.ts @@ -2,6 +2,7 @@ import { z } from "zod" import * as pcb from "./pcb" import * as sch from "./schematic" import * as src from "./source" +import * as cad from "./cad" export const any_soup_element = z.union([ // TODO source_group @@ -50,6 +51,7 @@ export const any_soup_element = z.union([ sch.schematic_path, sch.schematic_error, sch.schematic_net_label, + cad.cad_component, ]) export type AnySoupElement = z.infer diff --git a/src/cad/cad_component_model.ts b/src/cad/cad_component_model.ts new file mode 100644 index 0000000..d0d65fc --- /dev/null +++ b/src/cad/cad_component_model.ts @@ -0,0 +1,27 @@ +import { z } from "zod" +import { point3 } from "../common" +import { rotation, length } from "../units" +import { layer_ref } from "src/pcb" + +export const cad_component = z + .object({ + type: z.literal("cad_component"), + cad_component_id: z.string(), + pcb_component_id: z.string(), + source_component_id: z.string(), + position: point3, + rotation: point3.optional(), + size: point3.optional(), + layer: layer_ref.optional(), + + // These are all ways to generate/load the 3d model + footprinter_string: z.string().optional(), + model_obj_url: z.string().optional(), + model_stl_url: z.string().optional(), + model_3mf_url: z.string().optional(), + model_jscad: z.array(z.any()).optional(), + }) + .describe("Defines a component on the PCB") + +export type CadComponentInput = z.input +export type CadComponent = z.infer diff --git a/src/cad/index.ts b/src/cad/index.ts new file mode 100644 index 0000000..58fce84 --- /dev/null +++ b/src/cad/index.ts @@ -0,0 +1 @@ +export * from "./cad_component_model" diff --git a/src/common/index.ts b/src/common/index.ts index 373d53c..1257025 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -1,2 +1,3 @@ export * from "./point" +export * from "./point3" export * from "./size" diff --git a/src/common/point3.ts b/src/common/point3.ts new file mode 100644 index 0000000..6053512 --- /dev/null +++ b/src/common/point3.ts @@ -0,0 +1,12 @@ +import { z } from "zod" +import { distance } from "../units" + +export const point3 = z.object({ + x: distance, + y: distance, + z: distance, +}) + +export const position3 = point3 + +export type Point3 = z.infer diff --git a/src/index.ts b/src/index.ts index efbf355..490297c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,4 +3,5 @@ export * from "./common" export * from "./source" export * from "./schematic" export * from "./pcb" +export * from "./cad" export * from "./any_soup_element"