Skip to content

Commit

Permalink
initial implementation of cad model render
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 21, 2024
1 parent d038c19 commit 2afd91a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
30 changes: 30 additions & 0 deletions lib/components/base-components/NormalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string> = {
[K in T]: Port
Expand Down Expand Up @@ -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:
})
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2afd91a

Please sign in to comment.