circuit-json-to-kicad 0.0.15 → 0.0.16
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 +53 -19
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -823,7 +823,8 @@ import {
|
|
|
823
823
|
SymbolInstancePath as SymbolInstancePath2,
|
|
824
824
|
TextEffects as TextEffects3,
|
|
825
825
|
TextEffectsFont as TextEffectsFont3,
|
|
826
|
-
|
|
826
|
+
TextEffectsJustify as TextEffectsJustify2,
|
|
827
|
+
GlobalLabel
|
|
827
828
|
} from "kicadts";
|
|
828
829
|
import { applyToPoint as applyToPoint3 } from "transformation-matrix";
|
|
829
830
|
var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
@@ -839,7 +840,7 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
839
840
|
return;
|
|
840
841
|
}
|
|
841
842
|
const symbols3 = [];
|
|
842
|
-
const
|
|
843
|
+
const globalLabels = [];
|
|
843
844
|
for (const netLabel of netLabels) {
|
|
844
845
|
const labelText = netLabel.text || "";
|
|
845
846
|
const symbolName = netLabel.symbol_name;
|
|
@@ -853,9 +854,9 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
853
854
|
symbols3.push(symbol);
|
|
854
855
|
}
|
|
855
856
|
} else {
|
|
856
|
-
const label = this.
|
|
857
|
+
const label = this.createGlobalLabel(netLabel, labelText);
|
|
857
858
|
if (label) {
|
|
858
|
-
|
|
859
|
+
globalLabels.push(label);
|
|
859
860
|
}
|
|
860
861
|
}
|
|
861
862
|
}
|
|
@@ -863,20 +864,24 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
863
864
|
const existingSymbols = kicadSch.symbols || [];
|
|
864
865
|
kicadSch.symbols = [...existingSymbols, ...symbols3];
|
|
865
866
|
}
|
|
866
|
-
if (kicadSch &&
|
|
867
|
-
kicadSch.
|
|
867
|
+
if (kicadSch && globalLabels.length > 0) {
|
|
868
|
+
kicadSch.globalLabels = [
|
|
869
|
+
...kicadSch.globalLabels || [],
|
|
870
|
+
...globalLabels
|
|
871
|
+
];
|
|
868
872
|
}
|
|
869
873
|
this.finished = true;
|
|
870
874
|
}
|
|
871
875
|
/**
|
|
872
876
|
* Create a KiCad symbol instance from a net label with a symbol_name
|
|
873
|
-
* These are treated like
|
|
877
|
+
* These are treated like power/ground symbols (e.g., vcc_up, ground_down)
|
|
878
|
+
* Uses anchor_position as the primary coordinate source
|
|
874
879
|
*/
|
|
875
880
|
createSymbolFromNetLabel(netLabel, labelText, symbolName) {
|
|
876
881
|
if (!this.ctx.c2kMatSch) return null;
|
|
877
882
|
const { x, y } = applyToPoint3(this.ctx.c2kMatSch, {
|
|
878
|
-
x: netLabel.
|
|
879
|
-
y: netLabel.
|
|
883
|
+
x: netLabel.anchor_position?.x ?? netLabel.center?.x ?? 0,
|
|
884
|
+
y: netLabel.anchor_position?.y ?? netLabel.center?.y ?? 0
|
|
880
885
|
});
|
|
881
886
|
const uuid = crypto.randomUUID();
|
|
882
887
|
const symbol = new SchematicSymbol3({
|
|
@@ -954,21 +959,50 @@ var AddSchematicNetLabelsStage = class extends ConverterStage {
|
|
|
954
959
|
return symbol;
|
|
955
960
|
}
|
|
956
961
|
/**
|
|
957
|
-
* Create a KiCad label from a schematic_net_label without a
|
|
962
|
+
* Create a KiCad global label from a schematic_net_label without a symbol_name
|
|
963
|
+
* Uses anchor_position as the primary coordinate source for the arrow anchor point
|
|
958
964
|
*/
|
|
959
|
-
|
|
960
|
-
if (!this.ctx.c2kMatSch) return null;
|
|
965
|
+
createGlobalLabel(netLabel, labelText) {
|
|
966
|
+
if (!this.ctx.c2kMatSch || !this.ctx.kicadSch) return null;
|
|
961
967
|
const { x, y } = applyToPoint3(this.ctx.c2kMatSch, {
|
|
962
|
-
x: netLabel.
|
|
963
|
-
y: netLabel.
|
|
968
|
+
x: netLabel.anchor_position?.x ?? netLabel.center?.x ?? 0,
|
|
969
|
+
y: netLabel.anchor_position?.y ?? netLabel.center?.y ?? 0
|
|
964
970
|
});
|
|
965
|
-
const
|
|
971
|
+
const anchorSide = netLabel.anchor_side || "left";
|
|
972
|
+
const angleMap = {
|
|
973
|
+
left: 0,
|
|
974
|
+
// Anchor on left, arrow points right
|
|
975
|
+
right: 180,
|
|
976
|
+
// Anchor on right, arrow points left
|
|
977
|
+
top: 270,
|
|
978
|
+
// Anchor on top, arrow points down
|
|
979
|
+
bottom: 90
|
|
980
|
+
// Anchor on bottom, arrow points up
|
|
981
|
+
};
|
|
982
|
+
const angle = angleMap[anchorSide] || 0;
|
|
983
|
+
const justifyMap = {
|
|
984
|
+
left: { horizontal: "left" },
|
|
985
|
+
// Anchor on left, text on left
|
|
986
|
+
right: { horizontal: "right" },
|
|
987
|
+
// Anchor on right, text on right
|
|
988
|
+
top: { vertical: "top" },
|
|
989
|
+
// Anchor on top, text on top
|
|
990
|
+
bottom: { vertical: "bottom" }
|
|
991
|
+
// Anchor on bottom, text on bottom
|
|
992
|
+
};
|
|
993
|
+
const justify = justifyMap[anchorSide] || {};
|
|
994
|
+
const effects = this.createTextEffects(1.27, false);
|
|
995
|
+
if (Object.keys(justify).length > 0) {
|
|
996
|
+
effects.justify = new TextEffectsJustify2(justify);
|
|
997
|
+
}
|
|
998
|
+
const globalLabel = new GlobalLabel({
|
|
966
999
|
value: labelText,
|
|
967
|
-
at: [x, y,
|
|
968
|
-
effects
|
|
969
|
-
uuid: crypto.randomUUID()
|
|
1000
|
+
at: [x, y, angle],
|
|
1001
|
+
effects,
|
|
1002
|
+
uuid: crypto.randomUUID(),
|
|
1003
|
+
fieldsAutoplaced: true
|
|
970
1004
|
});
|
|
971
|
-
return
|
|
1005
|
+
return globalLabel;
|
|
972
1006
|
}
|
|
973
1007
|
/**
|
|
974
1008
|
* Creates text effects for properties and labels
|
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.16",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/bun": "latest",
|
|
21
21
|
"circuit-json": "^0.0.267",
|
|
22
22
|
"circuit-to-svg": "^0.0.208",
|
|
23
|
-
"kicadts": "^0.0.
|
|
23
|
+
"kicadts": "^0.0.10",
|
|
24
24
|
"schematic-symbols": "^0.0.202",
|
|
25
25
|
"sharp": "^0.34.4",
|
|
26
26
|
"transformation-matrix": "^3.1.0",
|