Skip to content
Draft
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
28 changes: 21 additions & 7 deletions lib/components/base-components/NormalComponent/NormalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ export class NormalComponent<
const { db } = this.root!
const { boardThickness = 0 } = this._getBoard() ?? {}
const cadModelProp = this._parsedProps.cadModel
const cadModel =
let cadModel =
cadModelProp === undefined ? this._asyncFootprintCadModel : cadModelProp
const footprintString = this.getFootprinterString() ?? undefined

Expand All @@ -1778,8 +1778,19 @@ export class NormalComponent<
// Use post-layout bounds
const bounds = this._getPcbCircuitJsonBounds()

let cadModelFootprinterString: string | undefined
if (typeof cadModel === "string") {
throw new Error("String cadModel not yet implemented")
if (
parseLibraryFootprintRef(cadModel) ||
isHttpUrl(cadModel) ||
isStaticAssetPath(cadModel)
) {
throw new Error(
`${this.getString()} cadModel string must be a Footprinter string, received "${cadModel}"`,
)
}
cadModelFootprinterString = cadModel
cadModel = undefined
}

const sourceRotationOffset =
Expand Down Expand Up @@ -1824,7 +1835,11 @@ export class NormalComponent<
: preLayoutRotation
const isBottomLayer = computedLayer === "bottom"

if (!cadModel && !footprintIsFootprinterString) {
if (
!cadModel &&
!cadModelFootprinterString &&
!footprintIsFootprinterString
) {
const cad_component = db.cad_component.insert({
position: {
x: bounds.center.x,
Expand Down Expand Up @@ -1852,10 +1867,9 @@ export class NormalComponent<

const rotationWithOffset = totalRotation + (rotationOffset.z ?? 0)
const cadRotationZ = normalizeDegrees(rotationWithOffset)
let footprinterStringForCadComponent: string | undefined
if (!cadModel && footprintIsFootprinterString) {
footprinterStringForCadComponent = footprintString
}
const footprinterStringForCadComponent =
cadModelFootprinterString ??
(!cadModel && footprintIsFootprinterString ? footprintString : undefined)

const cad_model = db.cad_component.insert({
// TODO z maybe depends on layer
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { expect, test } from "bun:test"
import { Chip } from "lib/components/normal-components/Chip"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test('cadModel="soic8" generates CAD independently of the PCB footprint', async () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<chip name="U1" cadModel="soic8">
<footprint>
<smtpad
portHints={["1"]}
pcbX={0}
pcbY={0}
width="1mm"
height="1mm"
shape="rect"
/>
</footprint>
</chip>
</board>,
)

const chip = circuit.selectOne("chip") as Chip
chip._asyncFootprintCadModel = {
glbUrl: "https://example.com/library-model.glb",
}

circuit.render()

const cadComponents = circuit.db.cad_component.list()
expect(cadComponents).toHaveLength(1)
expect(cadComponents[0]).toMatchObject({
footprinter_string: "soic8",
})
expect(cadComponents[0]?.show_as_bounding_box).toBeUndefined()
expect(cadComponents[0]?.model_glb_url).toBeUndefined()

await expect(circuit).toMatchSimple3dSnapshot(import.meta.path)
})
Loading