diff --git a/bun.lockb b/bun.lockb index e8e13bc..bd3722b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/components/base-components/NormalComponent.ts b/lib/components/base-components/NormalComponent.ts index 7de4b96..9c45217 100644 --- a/lib/components/base-components/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent.ts @@ -19,6 +19,7 @@ import { createComponentsFromSoup } from "lib/utils/createComponentsFromSoup" import { Net } from "../primitive-components/Net" import { createNetsFromProps } from "lib/utils/components/createNetsFromProps" import { getBoundsOfPcbComponents } from "lib/utils/get-bounds-of-pcb-components" +import type { CadModelProp } from "@tscircuit/props" export type PortMap = { [K in T]: Port @@ -416,4 +417,33 @@ export class NormalComponent< this.add(newPort) } } + + doInitialCadModelRender(): void { + const { db } = this.root! + const { _parsedProps: props } = this + + if (props.cadModel) { + // Use post-layout bounds + const bounds = this._getPcbCircuitJsonBounds() + + const cadModel: CadModelProp = props.cadModel + + if (typeof cadModel === "string") { + throw new Error("String cadModel not yet implemented") + } + + const cad_model = db.cad_component.insert({ + // TODO z maybe depends on layer + position: { x: bounds.center.x, y: bounds.center.y, z: 0 }, + pcb_component_id: this.pcb_component_id!, + source_component_id: this.source_component_id!, + model_stl_url: "stlUrl" in cadModel ? cadModel.stlUrl : undefined, + model_obj_url: "objUrl" in cadModel ? cadModel.objUrl : undefined, + model_jscad: "jscad" in cadModel ? cadModel.jscad : undefined, + + // TODO + // footprinter_string: + }) + } + } } diff --git a/package.json b/package.json index 4b208a8..0e892ee 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@lume/kiwi": "^0.4.3", "@tscircuit/infgrid-ijump-astar": "^0.0.21", "@tscircuit/math-utils": "^0.0.4", - "@tscircuit/props": "^0.0.63", + "@tscircuit/props": "^0.0.64", "@tscircuit/soup": "^0.0.73", "@tscircuit/soup-util": "^0.0.28", "circuit-json": "^0.0.77",