circuit-json-to-kicad 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +61 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -155,6 +155,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
155
155
  if (!symbolData) return null;
156
156
  const libId = getLibraryId(sourceComp, schematicComponent);
157
157
  const isChip = sourceComp.ftype === "simple_chip";
158
+ const footprintName = sourceComp.ftype || "";
158
159
  return this.createLibrarySymbol({
159
160
  libId,
160
161
  symbolData,
@@ -162,7 +163,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
162
163
  schematicComponent,
163
164
  description: this.getDescription(sourceComp),
164
165
  keywords: this.getKeywords(sourceComp),
165
- fpFilters: this.getFpFilters(sourceComp)
166
+ fpFilters: this.getFpFilters(sourceComp),
167
+ footprintRef: footprintName ? `tscircuit:${footprintName}` : ""
166
168
  });
167
169
  }
168
170
  /**
@@ -244,7 +246,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
244
246
  schematicComponent,
245
247
  description,
246
248
  keywords,
247
- fpFilters
249
+ fpFilters,
250
+ footprintRef = ""
248
251
  }) {
249
252
  const symbol = new SchematicSymbol({
250
253
  libraryId: libId,
@@ -263,7 +266,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
263
266
  libId,
264
267
  description,
265
268
  keywords,
266
- fpFilters
269
+ fpFilters,
270
+ footprintRef
267
271
  });
268
272
  const drawingSymbol = this.createDrawingSubsymbol({
269
273
  libId,
@@ -289,7 +293,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
289
293
  libId,
290
294
  description,
291
295
  keywords,
292
- fpFilters
296
+ fpFilters,
297
+ footprintRef = ""
293
298
  }) {
294
299
  const refPrefix = libId.split(":")[1]?.[0] || "U";
295
300
  const properties = [
@@ -303,7 +308,7 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
303
308
  { key: "Value", value: refPrefix, id: 1, at: [0, 0, 90], hide: false },
304
309
  {
305
310
  key: "Footprint",
306
- value: "",
311
+ value: footprintRef,
307
312
  id: 2,
308
313
  at: [-1.778, 0, 90],
309
314
  hide: true
@@ -1398,7 +1403,7 @@ var AddNetsStage = class extends ConverterStage {
1398
1403
  };
1399
1404
 
1400
1405
  // lib/pcb/stages/AddFootprintsStage.ts
1401
- import { Footprint } from "kicadts";
1406
+ import { Footprint, FootprintModel } from "kicadts";
1402
1407
  import { applyToPoint as applyToPoint9 } from "transformation-matrix";
1403
1408
 
1404
1409
  // lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
@@ -1781,6 +1786,44 @@ var AddFootprintsStage = class extends ConverterStage {
1781
1786
  if (!connectivityKey) return void 0;
1782
1787
  return this.ctx.pcbNetMap?.get(connectivityKey);
1783
1788
  }
1789
+ /**
1790
+ * Gets the cad_component associated with a pcb_component
1791
+ */
1792
+ getCadComponentForPcbComponent(pcbComponentId) {
1793
+ const cadComponents = this.ctx.db.cad_component?.list() || [];
1794
+ return cadComponents.find(
1795
+ (cad) => cad.pcb_component_id === pcbComponentId
1796
+ );
1797
+ }
1798
+ /**
1799
+ * Creates FootprintModel instances from a cad_component's 3D model URLs
1800
+ */
1801
+ create3DModelsFromCadComponent(cadComponent, componentCenter) {
1802
+ const models = [];
1803
+ const modelUrl = cadComponent.model_step_url || cadComponent.model_wrl_url;
1804
+ if (!modelUrl) return models;
1805
+ const model = new FootprintModel(modelUrl);
1806
+ if (cadComponent.position) {
1807
+ model.offset = {
1808
+ x: (cadComponent.position.x || 0) - componentCenter.x,
1809
+ y: -((cadComponent.position.y || 0) - componentCenter.y),
1810
+ z: cadComponent.position.z || 0
1811
+ };
1812
+ }
1813
+ if (cadComponent.rotation) {
1814
+ model.rotate = {
1815
+ x: cadComponent.rotation.x || 0,
1816
+ y: cadComponent.rotation.y || 0,
1817
+ z: cadComponent.rotation.z || 0
1818
+ };
1819
+ }
1820
+ if (cadComponent.model_unit_to_mm_scale_factor) {
1821
+ const scale4 = cadComponent.model_unit_to_mm_scale_factor;
1822
+ model.scale = { x: scale4, y: scale4, z: scale4 };
1823
+ }
1824
+ models.push(model);
1825
+ return models;
1826
+ }
1784
1827
  constructor(input, ctx) {
1785
1828
  super(input, ctx);
1786
1829
  this.pcbComponents = this.ctx.db.pcb_component.list();
@@ -1876,6 +1919,18 @@ var AddFootprintsStage = class extends ConverterStage {
1876
1919
  }
1877
1920
  }
1878
1921
  footprint.fpPads = fpPads;
1922
+ const cadComponent = this.getCadComponentForPcbComponent(
1923
+ component.pcb_component_id
1924
+ );
1925
+ if (cadComponent) {
1926
+ const models = this.create3DModelsFromCadComponent(
1927
+ cadComponent,
1928
+ component.center
1929
+ );
1930
+ if (models.length > 0) {
1931
+ footprint.models = models;
1932
+ }
1933
+ }
1879
1934
  const footprints = kicadPcb.footprints;
1880
1935
  footprints.push(footprint);
1881
1936
  kicadPcb.footprints = footprints;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-kicad",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.27",
4
+ "version": "0.0.29",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"