circuit-json-to-kicad 0.0.30 → 0.0.32
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.
- package/dist/index.js +57 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75,33 +75,50 @@ import {
|
|
|
75
75
|
} from "kicadts";
|
|
76
76
|
import { symbols } from "schematic-symbols";
|
|
77
77
|
|
|
78
|
+
// lib/utils/getKicadCompatibleComponentName.ts
|
|
79
|
+
function getKicadCompatibleComponentName(sourceComponent, cadComponent) {
|
|
80
|
+
if (sourceComponent.manufacturer_part_number) {
|
|
81
|
+
return sanitizeName(sourceComponent.manufacturer_part_number);
|
|
82
|
+
}
|
|
83
|
+
const cleanType = getCleanTypeName(sourceComponent.ftype);
|
|
84
|
+
const footprinterString = cadComponent?.footprinter_string;
|
|
85
|
+
if (footprinterString) {
|
|
86
|
+
return sanitizeName(`${cleanType}_${footprinterString}`);
|
|
87
|
+
}
|
|
88
|
+
return sanitizeName(cleanType);
|
|
89
|
+
}
|
|
90
|
+
function getCleanTypeName(ftype) {
|
|
91
|
+
if (!ftype) return "component";
|
|
92
|
+
let cleanName = ftype.replace(/^simple_/, "");
|
|
93
|
+
if (!cleanName) return "component";
|
|
94
|
+
return cleanName;
|
|
95
|
+
}
|
|
96
|
+
function sanitizeName(name) {
|
|
97
|
+
return name.replace(/[\\\/:\s]+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").trim() || "component";
|
|
98
|
+
}
|
|
99
|
+
function extractReferencePrefix(name) {
|
|
100
|
+
if (!name) return "U";
|
|
101
|
+
const match = name.match(/^([A-Za-z]+)/);
|
|
102
|
+
return match?.[1]?.toUpperCase() ?? "U";
|
|
103
|
+
}
|
|
104
|
+
|
|
78
105
|
// lib/schematic/getLibraryId.ts
|
|
79
|
-
function getLibraryId(sourceComp, schematicComp) {
|
|
106
|
+
function getLibraryId(sourceComp, schematicComp, cadComponent) {
|
|
80
107
|
if (sourceComp.type !== "source_component") {
|
|
81
108
|
if (schematicComp.symbol_name) {
|
|
82
109
|
return `Custom:${schematicComp.symbol_name}`;
|
|
83
110
|
}
|
|
84
111
|
return "Device:Component";
|
|
85
112
|
}
|
|
86
|
-
if (sourceComp.ftype === "simple_resistor") {
|
|
87
|
-
return `Device:R_${sourceComp.source_component_id}`;
|
|
88
|
-
}
|
|
89
|
-
if (sourceComp.ftype === "simple_capacitor") {
|
|
90
|
-
return `Device:C_${sourceComp.source_component_id}`;
|
|
91
|
-
}
|
|
92
|
-
if (sourceComp.ftype === "simple_inductor") {
|
|
93
|
-
return `Device:L_${sourceComp.source_component_id}`;
|
|
94
|
-
}
|
|
95
|
-
if (sourceComp.ftype === "simple_diode") {
|
|
96
|
-
return `Device:D_${sourceComp.source_component_id}`;
|
|
97
|
-
}
|
|
98
|
-
if (sourceComp.ftype === "simple_chip") {
|
|
99
|
-
return `Device:U_${sourceComp.source_component_id}`;
|
|
100
|
-
}
|
|
101
113
|
if (schematicComp.symbol_name) {
|
|
102
114
|
return `Custom:${schematicComp.symbol_name}`;
|
|
103
115
|
}
|
|
104
|
-
|
|
116
|
+
const ergonomicName = getKicadCompatibleComponentName(
|
|
117
|
+
sourceComp,
|
|
118
|
+
cadComponent
|
|
119
|
+
);
|
|
120
|
+
const refPrefix = extractReferencePrefix(sourceComp.name);
|
|
121
|
+
return `Device:${refPrefix}_${ergonomicName}`;
|
|
105
122
|
}
|
|
106
123
|
|
|
107
124
|
// lib/schematic/stages/AddLibrarySymbolsStage.ts
|
|
@@ -149,13 +166,19 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
149
166
|
const { db } = this.ctx;
|
|
150
167
|
const sourceComp = schematicComponent.source_component_id ? db.source_component.get(schematicComponent.source_component_id) : null;
|
|
151
168
|
if (!sourceComp) return null;
|
|
169
|
+
const cadComponent = db.cad_component?.list()?.find(
|
|
170
|
+
(cad) => cad.source_component_id === sourceComp.source_component_id
|
|
171
|
+
);
|
|
152
172
|
const symbolName = schematicComponent.symbol_name || (sourceComp.ftype === "simple_chip" ? `generic_chip_${schematicComponent.source_component_id}` : null);
|
|
153
173
|
if (!symbolName) return null;
|
|
154
174
|
const symbolData = this.getSymbolData(symbolName, schematicComponent);
|
|
155
175
|
if (!symbolData) return null;
|
|
156
|
-
const libId = getLibraryId(sourceComp, schematicComponent);
|
|
176
|
+
const libId = getLibraryId(sourceComp, schematicComponent, cadComponent);
|
|
157
177
|
const isChip = sourceComp.ftype === "simple_chip";
|
|
158
|
-
const footprintName =
|
|
178
|
+
const footprintName = getKicadCompatibleComponentName(
|
|
179
|
+
sourceComp,
|
|
180
|
+
cadComponent
|
|
181
|
+
);
|
|
159
182
|
return this.createLibrarySymbol({
|
|
160
183
|
libId,
|
|
161
184
|
symbolData,
|
|
@@ -626,7 +649,14 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
626
649
|
uuid,
|
|
627
650
|
fieldsAutoplaced: true
|
|
628
651
|
});
|
|
629
|
-
const
|
|
652
|
+
const cadComponent = db.cad_component?.list()?.find(
|
|
653
|
+
(cad) => cad.source_component_id === sourceComponent.source_component_id
|
|
654
|
+
);
|
|
655
|
+
const libId = getLibraryId(
|
|
656
|
+
sourceComponent,
|
|
657
|
+
schematicComponent,
|
|
658
|
+
cadComponent
|
|
659
|
+
);
|
|
630
660
|
const symLibId = new SymbolLibId(libId);
|
|
631
661
|
symbol._sxLibId = symLibId;
|
|
632
662
|
const { reference, value, description } = this.getComponentMetadata(sourceComponent);
|
|
@@ -1842,7 +1872,13 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1842
1872
|
}
|
|
1843
1873
|
const component = this.pcbComponents[this.componentsProcessed];
|
|
1844
1874
|
const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
|
|
1845
|
-
const
|
|
1875
|
+
const cadComponent = this.getCadComponentForPcbComponent(
|
|
1876
|
+
component.pcb_component_id
|
|
1877
|
+
);
|
|
1878
|
+
const footprintName = sourceComponent ? getKicadCompatibleComponentName(
|
|
1879
|
+
sourceComponent,
|
|
1880
|
+
cadComponent
|
|
1881
|
+
) : "Unknown";
|
|
1846
1882
|
const transformedPos = applyToPoint9(c2kMatPcb, {
|
|
1847
1883
|
x: component.center.x,
|
|
1848
1884
|
y: component.center.y
|
|
@@ -1919,9 +1955,6 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1919
1955
|
}
|
|
1920
1956
|
}
|
|
1921
1957
|
footprint.fpPads = fpPads;
|
|
1922
|
-
const cadComponent = this.getCadComponentForPcbComponent(
|
|
1923
|
-
component.pcb_component_id
|
|
1924
|
-
);
|
|
1925
1958
|
if (cadComponent) {
|
|
1926
1959
|
const models = this.create3DModelsFromCadComponent(
|
|
1927
1960
|
cadComponent,
|