circuit-json-to-kicad 0.0.40 → 0.0.41
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 +63 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -101,6 +101,50 @@ function extractReferencePrefix(name) {
|
|
|
101
101
|
const match = name.match(/^([A-Za-z]+)/);
|
|
102
102
|
return match?.[1]?.toUpperCase() ?? "U";
|
|
103
103
|
}
|
|
104
|
+
var referencePrefixByFtype = {
|
|
105
|
+
simple_resistor: "R",
|
|
106
|
+
simple_capacitor: "C",
|
|
107
|
+
simple_inductor: "L",
|
|
108
|
+
simple_diode: "D",
|
|
109
|
+
simple_led: "D",
|
|
110
|
+
simple_chip: "U",
|
|
111
|
+
simple_transistor: "Q",
|
|
112
|
+
simple_mosfet: "Q",
|
|
113
|
+
simple_fuse: "F",
|
|
114
|
+
simple_switch: "SW",
|
|
115
|
+
simple_push_button: "SW",
|
|
116
|
+
simple_potentiometer: "RV",
|
|
117
|
+
simple_crystal: "Y",
|
|
118
|
+
simple_resonator: "Y",
|
|
119
|
+
simple_pin_header: "J",
|
|
120
|
+
simple_pinout: "J",
|
|
121
|
+
simple_test_point: "TP",
|
|
122
|
+
simple_battery: "BT"
|
|
123
|
+
};
|
|
124
|
+
var referenceDesignatorPattern = /^[A-Za-z]+\\d+$/;
|
|
125
|
+
function isReferenceDesignator(value) {
|
|
126
|
+
if (!value) return false;
|
|
127
|
+
return referenceDesignatorPattern.test(value.trim());
|
|
128
|
+
}
|
|
129
|
+
function getReferencePrefixForComponent(sourceComponent) {
|
|
130
|
+
const name = sourceComponent?.name;
|
|
131
|
+
if (isReferenceDesignator(name)) {
|
|
132
|
+
return extractReferencePrefix(name);
|
|
133
|
+
}
|
|
134
|
+
const ftype = sourceComponent?.ftype;
|
|
135
|
+
if (ftype && referencePrefixByFtype[ftype]) {
|
|
136
|
+
return referencePrefixByFtype[ftype];
|
|
137
|
+
}
|
|
138
|
+
return extractReferencePrefix(name);
|
|
139
|
+
}
|
|
140
|
+
function getReferenceDesignator(sourceComponent) {
|
|
141
|
+
const name = sourceComponent?.name;
|
|
142
|
+
if (isReferenceDesignator(name)) {
|
|
143
|
+
return name.trim();
|
|
144
|
+
}
|
|
145
|
+
const prefix = getReferencePrefixForComponent(sourceComponent);
|
|
146
|
+
return `${prefix}?`;
|
|
147
|
+
}
|
|
104
148
|
|
|
105
149
|
// lib/schematic/getLibraryId.ts
|
|
106
150
|
import { symbols } from "schematic-symbols";
|
|
@@ -127,7 +171,7 @@ function getLibraryId(sourceComp, schematicComp, cadComponent) {
|
|
|
127
171
|
sourceComp,
|
|
128
172
|
cadComponent
|
|
129
173
|
);
|
|
130
|
-
const refPrefix =
|
|
174
|
+
const refPrefix = getReferencePrefixForComponent(sourceComp);
|
|
131
175
|
return `Device:${refPrefix}_${ergonomicName}`;
|
|
132
176
|
}
|
|
133
177
|
|
|
@@ -197,7 +241,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
197
241
|
description: this.getDescription(sourceComp),
|
|
198
242
|
keywords: this.getKeywords(sourceComp),
|
|
199
243
|
fpFilters: this.getFpFilters(sourceComp),
|
|
200
|
-
footprintRef: footprintName ? `tscircuit:${footprintName}` : ""
|
|
244
|
+
footprintRef: footprintName ? `tscircuit:${footprintName}` : "",
|
|
245
|
+
referencePrefix: getReferencePrefixForComponent(sourceComp)
|
|
201
246
|
});
|
|
202
247
|
}
|
|
203
248
|
/**
|
|
@@ -220,7 +265,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
220
265
|
schematicComponent: void 0,
|
|
221
266
|
description: isPower ? "Power net label" : isGround ? "Ground net label" : "Net symbol",
|
|
222
267
|
keywords: isPower ? "power net" : isGround ? "ground net" : "net",
|
|
223
|
-
fpFilters: ""
|
|
268
|
+
fpFilters: "",
|
|
269
|
+
referencePrefix: libId.split(":")[1]?.[0] || "U"
|
|
224
270
|
});
|
|
225
271
|
}
|
|
226
272
|
/**
|
|
@@ -280,7 +326,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
280
326
|
description,
|
|
281
327
|
keywords,
|
|
282
328
|
fpFilters,
|
|
283
|
-
footprintRef = ""
|
|
329
|
+
footprintRef = "",
|
|
330
|
+
referencePrefix
|
|
284
331
|
}) {
|
|
285
332
|
const symbol = new SchematicSymbol({
|
|
286
333
|
libraryId: libId,
|
|
@@ -300,7 +347,8 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
300
347
|
description,
|
|
301
348
|
keywords,
|
|
302
349
|
fpFilters,
|
|
303
|
-
footprintRef
|
|
350
|
+
footprintRef,
|
|
351
|
+
referencePrefix
|
|
304
352
|
});
|
|
305
353
|
const drawingSymbol = this.createDrawingSubsymbol({
|
|
306
354
|
libId,
|
|
@@ -327,9 +375,10 @@ var AddLibrarySymbolsStage = class extends ConverterStage {
|
|
|
327
375
|
description,
|
|
328
376
|
keywords,
|
|
329
377
|
fpFilters,
|
|
330
|
-
footprintRef = ""
|
|
378
|
+
footprintRef = "",
|
|
379
|
+
referencePrefix
|
|
331
380
|
}) {
|
|
332
|
-
const refPrefix = libId.split(":")[1]?.[0] || "U";
|
|
381
|
+
const refPrefix = referencePrefix || libId.split(":")[1]?.[0] || "U";
|
|
333
382
|
const properties = [
|
|
334
383
|
{
|
|
335
384
|
key: "Reference",
|
|
@@ -794,43 +843,44 @@ var AddSchematicSymbolsStage = class extends ConverterStage {
|
|
|
794
843
|
*/
|
|
795
844
|
getComponentMetadata(sourceComp) {
|
|
796
845
|
const name = sourceComp.name || "?";
|
|
846
|
+
const reference = getReferenceDesignator(sourceComp);
|
|
797
847
|
if (sourceComp.ftype === "simple_resistor") {
|
|
798
848
|
return {
|
|
799
|
-
reference
|
|
849
|
+
reference,
|
|
800
850
|
value: sourceComp.display_resistance || "R",
|
|
801
851
|
description: "Resistor"
|
|
802
852
|
};
|
|
803
853
|
}
|
|
804
854
|
if (sourceComp.ftype === "simple_capacitor") {
|
|
805
855
|
return {
|
|
806
|
-
reference
|
|
856
|
+
reference,
|
|
807
857
|
value: sourceComp.display_capacitance || "C",
|
|
808
858
|
description: "Capacitor"
|
|
809
859
|
};
|
|
810
860
|
}
|
|
811
861
|
if (sourceComp.ftype === "simple_inductor") {
|
|
812
862
|
return {
|
|
813
|
-
reference
|
|
863
|
+
reference,
|
|
814
864
|
value: sourceComp.display_inductance || "L",
|
|
815
865
|
description: "Inductor"
|
|
816
866
|
};
|
|
817
867
|
}
|
|
818
868
|
if (sourceComp.ftype === "simple_diode") {
|
|
819
869
|
return {
|
|
820
|
-
reference
|
|
870
|
+
reference,
|
|
821
871
|
value: "D",
|
|
822
872
|
description: "Diode"
|
|
823
873
|
};
|
|
824
874
|
}
|
|
825
875
|
if (sourceComp.ftype === "simple_chip") {
|
|
826
876
|
return {
|
|
827
|
-
reference
|
|
877
|
+
reference,
|
|
828
878
|
value: name,
|
|
829
879
|
description: "Integrated Circuit"
|
|
830
880
|
};
|
|
831
881
|
}
|
|
832
882
|
return {
|
|
833
|
-
reference
|
|
883
|
+
reference,
|
|
834
884
|
value: name,
|
|
835
885
|
description: "Component"
|
|
836
886
|
};
|