altium-to-circuit-json 0.0.63 → 0.0.65
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 +93 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2730,6 +2730,39 @@ function selectCircuitJsonSymbol({
|
|
|
2730
2730
|
)[0];
|
|
2731
2731
|
}
|
|
2732
2732
|
|
|
2733
|
+
// lib/schematic/components/parseAltiumPinLabel.ts
|
|
2734
|
+
function parseAltiumPinLabel(name) {
|
|
2735
|
+
if (!name.includes("\\")) return { displayText: name };
|
|
2736
|
+
if (name.startsWith("\\")) {
|
|
2737
|
+
const displayText = name.replaceAll("\\", "");
|
|
2738
|
+
return {
|
|
2739
|
+
displayText,
|
|
2740
|
+
textParts: [{ is_overlined: true, text: displayText }]
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2743
|
+
const textParts = [];
|
|
2744
|
+
const characters = [...name];
|
|
2745
|
+
for (let index = 0; index < characters.length; index += 1) {
|
|
2746
|
+
const character = characters[index] ?? "";
|
|
2747
|
+
if (character === "\\") continue;
|
|
2748
|
+
const isOverlined = characters[index + 1] === "\\";
|
|
2749
|
+
if (isOverlined) index += 1;
|
|
2750
|
+
const previousTextPart = textParts.at(-1);
|
|
2751
|
+
if (previousTextPart && Boolean(previousTextPart.is_overlined) === isOverlined) {
|
|
2752
|
+
previousTextPart.text += character;
|
|
2753
|
+
} else {
|
|
2754
|
+
textParts.push({
|
|
2755
|
+
...isOverlined ? { is_overlined: true } : {},
|
|
2756
|
+
text: character
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
return {
|
|
2761
|
+
displayText: textParts.map((textPart) => textPart.text).join(""),
|
|
2762
|
+
textParts
|
|
2763
|
+
};
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2733
2766
|
// lib/schematic/components/parsePinNumber.ts
|
|
2734
2767
|
function parsePinNumber(pinDesignator) {
|
|
2735
2768
|
const parsed = Number(pinDesignator);
|
|
@@ -2760,6 +2793,7 @@ function convertComponentPin({
|
|
|
2760
2793
|
const designator = pin.designator ?? `${pinIndex + 1}`;
|
|
2761
2794
|
const pinNumber = parsePinNumber(designator);
|
|
2762
2795
|
const name = pin.name ?? designator;
|
|
2796
|
+
const parsedPinLabel = parseAltiumPinLabel(name);
|
|
2763
2797
|
const sourcePortId = `source_port_altium_${recordIndex}`;
|
|
2764
2798
|
const schematicPortId = `schematic_port_altium_${recordIndex}`;
|
|
2765
2799
|
const sourcePort = {
|
|
@@ -2781,7 +2815,10 @@ function convertComponentPin({
|
|
|
2781
2815
|
const schematicPort = {
|
|
2782
2816
|
type: "schematic_port",
|
|
2783
2817
|
center: scalePoint(terminalPoint, options.scale),
|
|
2784
|
-
...showName && name ? {
|
|
2818
|
+
...showName && name ? {
|
|
2819
|
+
display_pin_label: parsedPinLabel.displayText,
|
|
2820
|
+
...parsedPinLabel.textParts ? { display_pin_label_text_parts: parsedPinLabel.textParts } : {}
|
|
2821
|
+
} : {},
|
|
2785
2822
|
distance_from_component_edge: scaleLength(pinLength, options.scale),
|
|
2786
2823
|
facing_direction: direction,
|
|
2787
2824
|
is_connected: false,
|
|
@@ -2804,6 +2841,45 @@ function convertComponentPin({
|
|
|
2804
2841
|
};
|
|
2805
2842
|
}
|
|
2806
2843
|
|
|
2844
|
+
// lib/schematic/components/createAlphanumericPinDesignatorText.ts
|
|
2845
|
+
var EDGE_VECTOR_BY_SIDE = {
|
|
2846
|
+
bottom: { x: 0, y: 1 },
|
|
2847
|
+
left: { x: 1, y: 0 },
|
|
2848
|
+
right: { x: -1, y: 0 },
|
|
2849
|
+
top: { x: 0, y: -1 }
|
|
2850
|
+
};
|
|
2851
|
+
function createAlphanumericPinDesignatorText({
|
|
2852
|
+
pin,
|
|
2853
|
+
recordIndex,
|
|
2854
|
+
scale: scale5,
|
|
2855
|
+
schematicPort
|
|
2856
|
+
}) {
|
|
2857
|
+
const designator = pin.designator;
|
|
2858
|
+
if (!designator || parsePinNumber(designator) !== void 0) return void 0;
|
|
2859
|
+
const pinConglomerate = pin.pinConglomerate;
|
|
2860
|
+
const isDesignatorVisible = pinConglomerate === void 0 || (pinConglomerate & 16) !== 0;
|
|
2861
|
+
const side = schematicPort.side_of_component;
|
|
2862
|
+
if (!isDesignatorVisible || !side) return void 0;
|
|
2863
|
+
const edgeVector = EDGE_VECTOR_BY_SIDE[side];
|
|
2864
|
+
const halfPinLength = (schematicPort.distance_from_component_edge ?? 0.4) / 2;
|
|
2865
|
+
const position = {
|
|
2866
|
+
x: schematicPort.center.x + edgeVector.x * halfPinLength,
|
|
2867
|
+
y: schematicPort.center.y + edgeVector.y * halfPinLength
|
|
2868
|
+
};
|
|
2869
|
+
return {
|
|
2870
|
+
type: "schematic_text",
|
|
2871
|
+
anchor: "bottom_center",
|
|
2872
|
+
color: "#a90000",
|
|
2873
|
+
font_size: Math.max(scaleLength(1.5, scale5), 0.15),
|
|
2874
|
+
position,
|
|
2875
|
+
rotation: side === "top" || side === "bottom" ? -90 : 0,
|
|
2876
|
+
schematic_component_id: schematicPort.schematic_component_id,
|
|
2877
|
+
schematic_sheet_id: schematicPort.schematic_sheet_id,
|
|
2878
|
+
schematic_text_id: `schematic_pin_designator_altium_${recordIndex}`,
|
|
2879
|
+
text: designator
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2807
2883
|
// lib/schematic/components/createSourceComponent.ts
|
|
2808
2884
|
import {
|
|
2809
2885
|
source_simple_capacitor,
|
|
@@ -3112,6 +3188,20 @@ function convertComponent({
|
|
|
3112
3188
|
if (symbolSelection) {
|
|
3113
3189
|
applyNativeSymbolPortGeometry({ center, selection: symbolSelection });
|
|
3114
3190
|
}
|
|
3191
|
+
const pinDesignatorTexts = componentPorts.flatMap(
|
|
3192
|
+
({ isSchematicVisible, schematicPort }, pinIndex) => {
|
|
3193
|
+
if (!isSchematicVisible) return [];
|
|
3194
|
+
const pin = pins[pinIndex];
|
|
3195
|
+
if (!pin) return [];
|
|
3196
|
+
const pinDesignatorText = createAlphanumericPinDesignatorText({
|
|
3197
|
+
pin,
|
|
3198
|
+
recordIndex: document.records.indexOf(pin),
|
|
3199
|
+
scale: options.scale,
|
|
3200
|
+
schematicPort
|
|
3201
|
+
});
|
|
3202
|
+
return pinDesignatorText ? [pinDesignatorText] : [];
|
|
3203
|
+
}
|
|
3204
|
+
);
|
|
3115
3205
|
convertedPorts.push(...componentPorts);
|
|
3116
3206
|
elements.push(
|
|
3117
3207
|
...componentPorts.flatMap(
|
|
@@ -3119,7 +3209,8 @@ function convertComponent({
|
|
|
3119
3209
|
sourcePort,
|
|
3120
3210
|
...isSchematicVisible ? [schematicPort] : []
|
|
3121
3211
|
]
|
|
3122
|
-
)
|
|
3212
|
+
),
|
|
3213
|
+
...pinDesignatorTexts
|
|
3123
3214
|
);
|
|
3124
3215
|
const schematicComponent = {
|
|
3125
3216
|
type: "schematic_component",
|