From 793f4cb21d7ae58ffeb1489c84e1e76c7ca120c3 Mon Sep 17 00:00:00 2001 From: xqql <52337226+xiuqiang1995@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:53:57 +0800 Subject: [PATCH] fix: include components by default in STEP conversion --- README.md | 1 + lib/index.ts | 8 +++++--- site/index.html | 2 +- test/repros/kicad-step/kicad-step.test.ts | 12 ++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61a677c..2b32f6d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ const stepText = await circuitJsonToStep(circuitJson, { boardHeight: 15, boardThickness: 1.6, productName: "MyPCB", + // Components are included by default }) await Bun.write("output.step", stepText) ``` diff --git a/lib/index.ts b/lib/index.ts index b1e627f..1406d3f 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -55,7 +55,7 @@ export interface CircuitJsonToStepOptions { boardThickness?: number /** Product name (default: "PCB") */ productName?: string - /** Include component meshes (default: false) */ + /** Include component meshes (default: true) */ includeComponents?: boolean /** Include external model meshes from model_*_url fields (default: false). Only applicable when includeComponents is true. */ includeExternalMeshes?: boolean @@ -565,10 +565,12 @@ export async function circuitJsonToStep( // Array to hold all solids (board + optional components) const allSolids: Ref[] = [solid] + const includeComponents = options.includeComponents ?? true + let handledComponentIds = new Set() let handledPcbComponentIds = new Set() - if (options.includeComponents && options.includeExternalMeshes) { + if (includeComponents && options.includeExternalMeshes) { const mergeResult = await mergeExternalStepModels({ repo, circuitJson, @@ -582,7 +584,7 @@ export async function circuitJsonToStep( // Generate component mesh fallback if requested // Only call mesh generation if there are components that need it - if (options.includeComponents) { + if (includeComponents) { // Build set of pcb_component_ids covered by cad_components with model_step_url const pcbComponentIdsWithStepUrl = new Set() for (const item of circuitJson) { diff --git a/site/index.html b/site/index.html index 505ae66..8c23505 100644 --- a/site/index.html +++ b/site/index.html @@ -365,7 +365,7 @@

Circuit JSON to STEP Converter

Options

- +
diff --git a/test/repros/kicad-step/kicad-step.test.ts b/test/repros/kicad-step/kicad-step.test.ts index 605671f..4fe5661 100644 --- a/test/repros/kicad-step/kicad-step.test.ts +++ b/test/repros/kicad-step/kicad-step.test.ts @@ -90,6 +90,18 @@ test("kicad-step: switch fixture renders consistently", async () => { ) }, 30000) +test("kicad-step: includes component geometry by default", async () => { + const fsMap = await loadStepFilesFromCircuitJson(circuitJson) + const stepText = await circuitJsonToStep(circuitJson as any, { + includeExternalMeshes: true, + productName: "KiCadStepDefaultComponents", + fsMap, + }) + + const solidCount = (stepText.match(/MANIFOLD_SOLID_BREP/g) || []).length + expect(solidCount).toBeGreaterThanOrEqual(3) +}) + test("kicad-step: merges KiCad STEP models referenced via model_step_url", async () => { const fsMap = await loadStepFilesFromCircuitJson(circuitJson) const stepText = await circuitJsonToStep(circuitJson as any, {