circuit-json-to-kicad 0.0.5 → 0.0.7
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 +37 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -74,6 +74,37 @@ import {
|
|
|
74
74
|
Xy
|
|
75
75
|
} from "kicadts";
|
|
76
76
|
import { symbols } from "schematic-symbols";
|
|
77
|
+
|
|
78
|
+
// lib/schematic/schematic-utils.ts
|
|
79
|
+
function getLibraryId(sourceComp, schematicComp) {
|
|
80
|
+
if (sourceComp.type !== "source_component") {
|
|
81
|
+
if (schematicComp.symbol_name) {
|
|
82
|
+
return `Custom:${schematicComp.symbol_name}`;
|
|
83
|
+
}
|
|
84
|
+
return "Device:Component";
|
|
85
|
+
}
|
|
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
|
+
if (schematicComp.symbol_name) {
|
|
102
|
+
return `Custom:${schematicComp.symbol_name}`;
|
|
103
|
+
}
|
|
104
|
+
return `Device:Component_${sourceComp.source_component_id}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// lib/schematic/stages/AddLibrarySymbolsStage.ts
|
|
77
108
|
var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
78
109
|
_step() {
|
|
79
110
|
const { kicadSch, db } = this.ctx;
|
|
@@ -122,7 +153,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
122
153
|
const libSymbol = this.createLibrarySymbolFromSchematicSymbol(
|
|
123
154
|
symbolName,
|
|
124
155
|
symbolData,
|
|
125
|
-
sourceComp
|
|
156
|
+
sourceComp,
|
|
157
|
+
exampleComp
|
|
126
158
|
);
|
|
127
159
|
librarySymbols.push(libSymbol);
|
|
128
160
|
}
|
|
@@ -171,8 +203,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
171
203
|
/**
|
|
172
204
|
* Convert schematic-symbols data to KiCad library symbol
|
|
173
205
|
*/
|
|
174
|
-
createLibrarySymbolFromSchematicSymbol(symbolName, symbolData, sourceComp) {
|
|
175
|
-
const libId =
|
|
206
|
+
createLibrarySymbolFromSchematicSymbol(symbolName, symbolData, sourceComp, schematicComp) {
|
|
207
|
+
const libId = getLibraryId(sourceComp, schematicComp);
|
|
176
208
|
const symbol = new SchematicSymbol({
|
|
177
209
|
libraryId: libId,
|
|
178
210
|
excludeFromSim: false,
|
|
@@ -194,21 +226,6 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
194
226
|
symbol._sxEmbeddedFonts = new EmbeddedFonts(false);
|
|
195
227
|
return symbol;
|
|
196
228
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Get KiCad library ID for a symbol
|
|
199
|
-
*/
|
|
200
|
-
getLibraryId(symbolName, sourceComp) {
|
|
201
|
-
if (sourceComp?.ftype === "simple_resistor") {
|
|
202
|
-
return "Device:R";
|
|
203
|
-
}
|
|
204
|
-
if (sourceComp?.ftype === "simple_capacitor") {
|
|
205
|
-
return "Device:C";
|
|
206
|
-
}
|
|
207
|
-
if (sourceComp?.ftype === "simple_chip") {
|
|
208
|
-
return "Device:U";
|
|
209
|
-
}
|
|
210
|
-
return `Custom:${symbolName}`;
|
|
211
|
-
}
|
|
212
229
|
/**
|
|
213
230
|
* Add properties to the library symbol
|
|
214
231
|
*/
|
|
@@ -485,7 +502,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
485
502
|
uuid,
|
|
486
503
|
fieldsAutoplaced: true
|
|
487
504
|
});
|
|
488
|
-
const libId =
|
|
505
|
+
const libId = getLibraryId(sourceComponent, schematicComponent);
|
|
489
506
|
const symLibId = new SymbolLibId(libId);
|
|
490
507
|
symbol._sxLibId = symLibId;
|
|
491
508
|
const { reference, value, description } = this.getComponentMetadata(sourceComponent);
|
|
@@ -1338,7 +1355,6 @@ var CircuitJsonToKicadPcbConverter = class {
|
|
|
1338
1355
|
|
|
1339
1356
|
// lib/project/CircuitJsonToKicadProConverter.ts
|
|
1340
1357
|
import { cju as cju3 } from "@tscircuit/circuit-json-util";
|
|
1341
|
-
import { randomUUID } from "crypto";
|
|
1342
1358
|
var CircuitJsonToKicadProConverter = class {
|
|
1343
1359
|
ctx;
|
|
1344
1360
|
project;
|
|
@@ -1405,7 +1421,7 @@ var CircuitJsonToKicadProConverter = class {
|
|
|
1405
1421
|
},
|
|
1406
1422
|
last_opened_board: pcbFilename
|
|
1407
1423
|
},
|
|
1408
|
-
sheets: [[
|
|
1424
|
+
sheets: [[Math.random().toString(36).substring(2, 15), "Root"]]
|
|
1409
1425
|
};
|
|
1410
1426
|
}
|
|
1411
1427
|
runUntilFinished() {
|