circuit-json-to-kicad 0.0.10 → 0.0.11
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 +107 -66
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ function getLibraryId(sourceComp, schematicComp) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// lib/schematic/stages/AddLibrarySymbolsStage.ts
|
|
108
|
+
import { applyToPoint, scale as createScaleMatrix } from "transformation-matrix";
|
|
108
109
|
var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
109
110
|
_step() {
|
|
110
111
|
const { kicadSch, db } = this.ctx;
|
|
@@ -131,12 +132,11 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
131
132
|
continue;
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
const libSymbol = this.createLibrarySymbolFromSchematicSymbol(
|
|
135
|
-
symbolName,
|
|
135
|
+
const libSymbol = this.createLibrarySymbolFromSchematicSymbol({
|
|
136
136
|
symbolData,
|
|
137
137
|
sourceComp,
|
|
138
138
|
schematicComponent
|
|
139
|
-
);
|
|
139
|
+
});
|
|
140
140
|
librarySymbols.push(libSymbol);
|
|
141
141
|
}
|
|
142
142
|
libSymbols.symbols = librarySymbols;
|
|
@@ -184,8 +184,12 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
184
184
|
/**
|
|
185
185
|
* Convert schematic-symbols data to KiCad library symbol
|
|
186
186
|
*/
|
|
187
|
-
createLibrarySymbolFromSchematicSymbol(
|
|
188
|
-
|
|
187
|
+
createLibrarySymbolFromSchematicSymbol({
|
|
188
|
+
symbolData,
|
|
189
|
+
sourceComp,
|
|
190
|
+
schematicComponent
|
|
191
|
+
}) {
|
|
192
|
+
const libId = getLibraryId(sourceComp, schematicComponent);
|
|
189
193
|
const symbol = new SchematicSymbol({
|
|
190
194
|
libraryId: libId,
|
|
191
195
|
excludeFromSim: false,
|
|
@@ -200,9 +204,18 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
200
204
|
symbol._sxPinNames = pinNames;
|
|
201
205
|
this.addSymbolProperties(symbol, libId, sourceComp);
|
|
202
206
|
const isChip = sourceComp?.ftype === "simple_chip";
|
|
203
|
-
const drawingSymbol = this.createDrawingSubsymbol(
|
|
207
|
+
const drawingSymbol = this.createDrawingSubsymbol({
|
|
208
|
+
libId,
|
|
209
|
+
symbolData,
|
|
210
|
+
isChip
|
|
211
|
+
});
|
|
204
212
|
symbol.subSymbols.push(drawingSymbol);
|
|
205
|
-
const pinSymbol = this.createPinSubsymbol(
|
|
213
|
+
const pinSymbol = this.createPinSubsymbol({
|
|
214
|
+
libId,
|
|
215
|
+
symbolData,
|
|
216
|
+
isChip,
|
|
217
|
+
schematicComponent
|
|
218
|
+
});
|
|
206
219
|
symbol.subSymbols.push(pinSymbol);
|
|
207
220
|
symbol._sxEmbeddedFonts = new EmbeddedFonts(false);
|
|
208
221
|
return symbol;
|
|
@@ -291,7 +304,11 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
291
304
|
* Create the drawing subsymbol (primitives, no pins)
|
|
292
305
|
* Converts schematic-symbols primitives to KiCad drawing elements
|
|
293
306
|
*/
|
|
294
|
-
createDrawingSubsymbol(
|
|
307
|
+
createDrawingSubsymbol({
|
|
308
|
+
libId,
|
|
309
|
+
symbolData,
|
|
310
|
+
isChip
|
|
311
|
+
}) {
|
|
295
312
|
const drawingSymbol = new SchematicSymbol({
|
|
296
313
|
libraryId: `${libId.split(":")[1]}_0_1`
|
|
297
314
|
});
|
|
@@ -299,11 +316,12 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
299
316
|
for (const primitive of symbolData.primitives || []) {
|
|
300
317
|
if (primitive.type === "path" && primitive.points) {
|
|
301
318
|
const fillType = isChip ? "background" : "none";
|
|
302
|
-
const polyline = this.createPolylineFromPoints(
|
|
303
|
-
primitive.points,
|
|
304
|
-
symbolScale,
|
|
319
|
+
const polyline = this.createPolylineFromPoints({
|
|
320
|
+
points: primitive.points,
|
|
321
|
+
scale: symbolScale,
|
|
322
|
+
center: symbolData.center,
|
|
305
323
|
fillType
|
|
306
|
-
);
|
|
324
|
+
});
|
|
307
325
|
drawingSymbol.polylines.push(polyline);
|
|
308
326
|
}
|
|
309
327
|
}
|
|
@@ -312,9 +330,20 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
312
330
|
/**
|
|
313
331
|
* Create a KiCad polyline from points
|
|
314
332
|
*/
|
|
315
|
-
createPolylineFromPoints(
|
|
333
|
+
createPolylineFromPoints({
|
|
334
|
+
points,
|
|
335
|
+
scale: scale3,
|
|
336
|
+
center,
|
|
337
|
+
fillType
|
|
338
|
+
}) {
|
|
316
339
|
const polyline = new SymbolPolyline();
|
|
317
|
-
const
|
|
340
|
+
const cx = center?.x ?? 0;
|
|
341
|
+
const cy = center?.y ?? 0;
|
|
342
|
+
const scaleMatrix = createScaleMatrix(scale3, scale3);
|
|
343
|
+
const xyPoints = points.map((p) => {
|
|
344
|
+
const translated = applyToPoint(scaleMatrix, { x: p.x - cx, y: p.y - cy });
|
|
345
|
+
return new Xy(translated.x, translated.y);
|
|
346
|
+
});
|
|
318
347
|
const pts = new Pts(xyPoints);
|
|
319
348
|
polyline.points = pts;
|
|
320
349
|
const stroke = new Stroke();
|
|
@@ -329,7 +358,12 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
329
358
|
/**
|
|
330
359
|
* Create the pin subsymbol
|
|
331
360
|
*/
|
|
332
|
-
createPinSubsymbol(
|
|
361
|
+
createPinSubsymbol({
|
|
362
|
+
libId,
|
|
363
|
+
symbolData,
|
|
364
|
+
isChip,
|
|
365
|
+
schematicComponent
|
|
366
|
+
}) {
|
|
333
367
|
const pinSymbol = new SchematicSymbol({
|
|
334
368
|
libraryId: `${libId.split(":")[1]}_1_1`
|
|
335
369
|
});
|
|
@@ -342,7 +376,9 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
342
376
|
port,
|
|
343
377
|
symbolData.center,
|
|
344
378
|
symbolData.size,
|
|
345
|
-
isChip
|
|
379
|
+
isChip,
|
|
380
|
+
i,
|
|
381
|
+
schematicComponent
|
|
346
382
|
);
|
|
347
383
|
pin.at = [x, y, angle];
|
|
348
384
|
pin.length = isChip ? 6 : 1.27;
|
|
@@ -367,12 +403,37 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
367
403
|
* Calculate KiCad pin position and rotation from schematic-symbols port
|
|
368
404
|
* Scale pins to match the c2kMatSch transformation scale
|
|
369
405
|
*/
|
|
370
|
-
calculatePinPosition(port, center, size, isChip) {
|
|
406
|
+
calculatePinPosition(port, center, size, isChip, portIndex, schematicComponent) {
|
|
371
407
|
const symbolScale = this.ctx.c2kMatSch?.a || 15;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
let
|
|
375
|
-
|
|
408
|
+
let portX = port.x ?? 0;
|
|
409
|
+
let portY = port.y ?? 0;
|
|
410
|
+
let usingCircuitJsonPort = false;
|
|
411
|
+
if (portIndex !== void 0 && schematicComponent) {
|
|
412
|
+
const schematicPorts = this.ctx.db.schematic_port.list().filter(
|
|
413
|
+
(p) => p.schematic_component_id === schematicComponent.schematic_component_id
|
|
414
|
+
).sort((a, b) => (a.pin_number || 0) - (b.pin_number || 0));
|
|
415
|
+
if (schematicPorts[portIndex]) {
|
|
416
|
+
const schPort = schematicPorts[portIndex];
|
|
417
|
+
portX = schPort.center.x - schematicComponent.center.x;
|
|
418
|
+
portY = schPort.center.y - schematicComponent.center.y;
|
|
419
|
+
usingCircuitJsonPort = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
let dx;
|
|
423
|
+
let dy;
|
|
424
|
+
if (usingCircuitJsonPort) {
|
|
425
|
+
dx = portX;
|
|
426
|
+
dy = portY;
|
|
427
|
+
} else {
|
|
428
|
+
const cx = center?.x ?? 0;
|
|
429
|
+
const cy = center?.y ?? 0;
|
|
430
|
+
dx = portX - cx;
|
|
431
|
+
dy = portY - cy;
|
|
432
|
+
}
|
|
433
|
+
const scaleMatrix = createScaleMatrix(symbolScale, symbolScale);
|
|
434
|
+
const scaled = applyToPoint(scaleMatrix, { x: dx, y: dy });
|
|
435
|
+
let x = scaled.x;
|
|
436
|
+
let y = scaled.y;
|
|
376
437
|
const chipPinLength = 6;
|
|
377
438
|
if (isChip && size) {
|
|
378
439
|
const halfWidth = size.width / 2 * symbolScale;
|
|
@@ -453,7 +514,7 @@ import {
|
|
|
453
514
|
TextEffectsFont as TextEffectsFont2,
|
|
454
515
|
TextEffectsJustify
|
|
455
516
|
} from "kicadts";
|
|
456
|
-
import { applyToPoint } from "transformation-matrix";
|
|
517
|
+
import { applyToPoint as applyToPoint2 } from "transformation-matrix";
|
|
457
518
|
import { symbols as symbols2 } from "schematic-symbols";
|
|
458
519
|
var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
459
520
|
_step() {
|
|
@@ -468,7 +529,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
468
529
|
const sourceComponent = schematicComponent.source_component_id ? db.source_component.get(schematicComponent.source_component_id) : null;
|
|
469
530
|
if (!sourceComponent) continue;
|
|
470
531
|
if (!this.ctx.c2kMatSch) continue;
|
|
471
|
-
const { x, y } =
|
|
532
|
+
const { x, y } = applyToPoint2(this.ctx.c2kMatSch, {
|
|
472
533
|
x: schematicComponent.center.x,
|
|
473
534
|
y: schematicComponent.center.y
|
|
474
535
|
});
|
|
@@ -567,7 +628,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
567
628
|
) || [];
|
|
568
629
|
const refText = schematicTexts.find((t) => t.text && t.text.length > 0);
|
|
569
630
|
if (refText && this.ctx.c2kMatSch) {
|
|
570
|
-
const refTextPos2 =
|
|
631
|
+
const refTextPos2 = applyToPoint2(this.ctx.c2kMatSch, {
|
|
571
632
|
x: refText.position.x,
|
|
572
633
|
y: refText.position.y
|
|
573
634
|
});
|
|
@@ -593,37 +654,17 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
593
654
|
}
|
|
594
655
|
}
|
|
595
656
|
}
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
657
|
+
const symbolCenter = symbol.center || { x: 0, y: 0 };
|
|
658
|
+
const refTextPos = refTextPrimitive && this.ctx.c2kMatSch ? applyToPoint2(this.ctx.c2kMatSch, {
|
|
659
|
+
x: schematicComponent.center.x + (refTextPrimitive.x - symbolCenter.x),
|
|
660
|
+
y: schematicComponent.center.y + (refTextPrimitive.y - symbolCenter.y)
|
|
599
661
|
}) : { x: symbolKicadPos.x, y: symbolKicadPos.y - 6 };
|
|
600
|
-
const valTextPos = valTextPrimitive && this.ctx.c2kMatSch ?
|
|
601
|
-
x: schematicComponent.center.x + valTextPrimitive.x,
|
|
602
|
-
y: schematicComponent.center.y + valTextPrimitive.y
|
|
662
|
+
const valTextPos = valTextPrimitive && this.ctx.c2kMatSch ? applyToPoint2(this.ctx.c2kMatSch, {
|
|
663
|
+
x: schematicComponent.center.x + (valTextPrimitive.x - symbolCenter.x),
|
|
664
|
+
y: schematicComponent.center.y + (valTextPrimitive.y - symbolCenter.y)
|
|
603
665
|
}) : { x: symbolKicadPos.x, y: symbolKicadPos.y + 6 };
|
|
604
666
|
return { refTextPos, valTextPos };
|
|
605
667
|
}
|
|
606
|
-
/**
|
|
607
|
-
* Get KiCad library ID for a component
|
|
608
|
-
*/
|
|
609
|
-
getLibraryId(sourceComp) {
|
|
610
|
-
if (sourceComp.ftype === "simple_resistor") {
|
|
611
|
-
return "Device:R";
|
|
612
|
-
}
|
|
613
|
-
if (sourceComp.ftype === "simple_capacitor") {
|
|
614
|
-
return "Device:C";
|
|
615
|
-
}
|
|
616
|
-
if (sourceComp.ftype === "simple_inductor") {
|
|
617
|
-
return "Device:L";
|
|
618
|
-
}
|
|
619
|
-
if (sourceComp.ftype === "simple_diode") {
|
|
620
|
-
return "Device:D";
|
|
621
|
-
}
|
|
622
|
-
if (sourceComp.ftype === "simple_chip") {
|
|
623
|
-
return "Device:U";
|
|
624
|
-
}
|
|
625
|
-
return "Device:Component";
|
|
626
|
-
}
|
|
627
668
|
/**
|
|
628
669
|
* Get component metadata (reference, value, description)
|
|
629
670
|
*/
|
|
@@ -694,7 +735,7 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
694
735
|
|
|
695
736
|
// lib/schematic/stages/AddSchematicTracesStage.ts
|
|
696
737
|
import { Wire, Pts as Pts2, Xy as Xy2, Stroke as Stroke2, Junction } from "kicadts";
|
|
697
|
-
import { applyToPoint as
|
|
738
|
+
import { applyToPoint as applyToPoint3 } from "transformation-matrix";
|
|
698
739
|
var AddSchematicTracesStage = class extends ConverterStage {
|
|
699
740
|
_step() {
|
|
700
741
|
const { kicadSch, db } = this.ctx;
|
|
@@ -732,11 +773,11 @@ var AddSchematicTracesStage = class extends ConverterStage {
|
|
|
732
773
|
"Schematic transformation matrix not initialized in context"
|
|
733
774
|
);
|
|
734
775
|
}
|
|
735
|
-
const from =
|
|
776
|
+
const from = applyToPoint3(this.ctx.c2kMatSch, {
|
|
736
777
|
x: edge.from.x,
|
|
737
778
|
y: edge.from.y
|
|
738
779
|
});
|
|
739
|
-
const to =
|
|
780
|
+
const to = applyToPoint3(this.ctx.c2kMatSch, {
|
|
740
781
|
x: edge.to.x,
|
|
741
782
|
y: edge.to.y
|
|
742
783
|
});
|
|
@@ -762,7 +803,7 @@ var AddSchematicTracesStage = class extends ConverterStage {
|
|
|
762
803
|
"Schematic transformation matrix not initialized in context"
|
|
763
804
|
);
|
|
764
805
|
}
|
|
765
|
-
const { x, y } =
|
|
806
|
+
const { x, y } = applyToPoint3(this.ctx.c2kMatSch, {
|
|
766
807
|
x: junction.x,
|
|
767
808
|
y: junction.y
|
|
768
809
|
});
|
|
@@ -1018,7 +1059,7 @@ var AddNetsStage = class extends ConverterStage {
|
|
|
1018
1059
|
|
|
1019
1060
|
// lib/pcb/stages/AddFootprintsStage.ts
|
|
1020
1061
|
import { Footprint, FpText, FootprintPad } from "kicadts";
|
|
1021
|
-
import { applyToPoint as
|
|
1062
|
+
import { applyToPoint as applyToPoint4 } from "transformation-matrix";
|
|
1022
1063
|
var AddFootprintsStage = class extends ConverterStage {
|
|
1023
1064
|
componentsProcessed = 0;
|
|
1024
1065
|
pcbComponents = [];
|
|
@@ -1042,7 +1083,7 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1042
1083
|
const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
|
|
1043
1084
|
const footprintName = sourceComponent?.ftype || "Unknown";
|
|
1044
1085
|
const componentName = sourceComponent?.name || `Component_${this.componentsProcessed}`;
|
|
1045
|
-
const transformedPos =
|
|
1086
|
+
const transformedPos = applyToPoint4(c2kMatPcb, {
|
|
1046
1087
|
x: component.center.x,
|
|
1047
1088
|
y: component.center.y
|
|
1048
1089
|
});
|
|
@@ -1123,7 +1164,7 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1123
1164
|
|
|
1124
1165
|
// lib/pcb/stages/AddTracesStage.ts
|
|
1125
1166
|
import { Segment, SegmentNet } from "kicadts";
|
|
1126
|
-
import { applyToPoint as
|
|
1167
|
+
import { applyToPoint as applyToPoint5 } from "transformation-matrix";
|
|
1127
1168
|
var AddTracesStage = class extends ConverterStage {
|
|
1128
1169
|
tracesProcessed = 0;
|
|
1129
1170
|
pcbTraces = [];
|
|
@@ -1151,11 +1192,11 @@ var AddTracesStage = class extends ConverterStage {
|
|
|
1151
1192
|
for (let i = 0; i < trace.route.length - 1; i++) {
|
|
1152
1193
|
const startPoint = trace.route[i];
|
|
1153
1194
|
const endPoint = trace.route[i + 1];
|
|
1154
|
-
const transformedStart =
|
|
1195
|
+
const transformedStart = applyToPoint5(c2kMatPcb, {
|
|
1155
1196
|
x: startPoint.x,
|
|
1156
1197
|
y: startPoint.y
|
|
1157
1198
|
});
|
|
1158
|
-
const transformedEnd =
|
|
1199
|
+
const transformedEnd = applyToPoint5(c2kMatPcb, {
|
|
1159
1200
|
x: endPoint.x,
|
|
1160
1201
|
y: endPoint.y
|
|
1161
1202
|
});
|
|
@@ -1189,7 +1230,7 @@ var AddTracesStage = class extends ConverterStage {
|
|
|
1189
1230
|
|
|
1190
1231
|
// lib/pcb/stages/AddViasStage.ts
|
|
1191
1232
|
import { Via, ViaNet } from "kicadts";
|
|
1192
|
-
import { applyToPoint as
|
|
1233
|
+
import { applyToPoint as applyToPoint6 } from "transformation-matrix";
|
|
1193
1234
|
var AddViasStage = class extends ConverterStage {
|
|
1194
1235
|
viasProcessed = 0;
|
|
1195
1236
|
pcbVias = [];
|
|
@@ -1210,7 +1251,7 @@ var AddViasStage = class extends ConverterStage {
|
|
|
1210
1251
|
return;
|
|
1211
1252
|
}
|
|
1212
1253
|
const via = this.pcbVias[this.viasProcessed];
|
|
1213
|
-
const transformedPos =
|
|
1254
|
+
const transformedPos = applyToPoint6(c2kMatPcb, {
|
|
1214
1255
|
x: via.x,
|
|
1215
1256
|
y: via.y
|
|
1216
1257
|
});
|
|
@@ -1237,7 +1278,7 @@ var AddViasStage = class extends ConverterStage {
|
|
|
1237
1278
|
|
|
1238
1279
|
// lib/pcb/stages/AddGraphicsStage.ts
|
|
1239
1280
|
import { GrLine } from "kicadts";
|
|
1240
|
-
import { applyToPoint as
|
|
1281
|
+
import { applyToPoint as applyToPoint7 } from "transformation-matrix";
|
|
1241
1282
|
var AddGraphicsStage = class extends ConverterStage {
|
|
1242
1283
|
_step() {
|
|
1243
1284
|
const { kicadPcb, c2kMatPcb } = this.ctx;
|
|
@@ -1254,11 +1295,11 @@ var AddGraphicsStage = class extends ConverterStage {
|
|
|
1254
1295
|
const startPoint = path.route[i];
|
|
1255
1296
|
const endPoint = path.route[i + 1];
|
|
1256
1297
|
if (!startPoint || !endPoint) continue;
|
|
1257
|
-
const transformedStart =
|
|
1298
|
+
const transformedStart = applyToPoint7(c2kMatPcb, {
|
|
1258
1299
|
x: startPoint.x,
|
|
1259
1300
|
y: startPoint.y
|
|
1260
1301
|
});
|
|
1261
|
-
const transformedEnd =
|
|
1302
|
+
const transformedEnd = applyToPoint7(c2kMatPcb, {
|
|
1262
1303
|
x: endPoint.x,
|
|
1263
1304
|
y: endPoint.y
|
|
1264
1305
|
});
|
|
@@ -1299,7 +1340,7 @@ var AddGraphicsStage = class extends ConverterStage {
|
|
|
1299
1340
|
];
|
|
1300
1341
|
}
|
|
1301
1342
|
const transformedCorners = corners.map(
|
|
1302
|
-
(corner) =>
|
|
1343
|
+
(corner) => applyToPoint7(c2kMatPcb, corner)
|
|
1303
1344
|
);
|
|
1304
1345
|
for (let i = 0; i < transformedCorners.length; i++) {
|
|
1305
1346
|
const start = transformedCorners[i];
|
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.
|
|
4
|
+
"version": "0.0.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"schematic-symbols": "^0.0.202",
|
|
25
25
|
"sharp": "^0.34.4",
|
|
26
26
|
"transformation-matrix": "^3.1.0",
|
|
27
|
-
"tscircuit": "^0.0.
|
|
27
|
+
"tscircuit": "^0.0.713",
|
|
28
28
|
"tsup": "^8.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|