altium-to-circuit-json 0.0.71 → 0.0.73
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 +153 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2911,6 +2911,46 @@ function selectCircuitJsonSymbol({
|
|
|
2911
2911
|
)[0];
|
|
2912
2912
|
}
|
|
2913
2913
|
|
|
2914
|
+
// lib/schematic/components/getAltiumPinNameFontSize.ts
|
|
2915
|
+
var DEFAULT_SCHEMATIC_FONT_ID = 0;
|
|
2916
|
+
var DEFAULT_SCHEMATIC_FONT_SIZE = 10;
|
|
2917
|
+
var PIN_CUSTOM_FONT_ID_FLAG = 16;
|
|
2918
|
+
var readSchematicInteger = (raw, fallback) => {
|
|
2919
|
+
const parsed = Number(raw);
|
|
2920
|
+
return Number.isFinite(parsed) ? Math.round(parsed) : fallback;
|
|
2921
|
+
};
|
|
2922
|
+
function getAltiumPinNameFontSize({
|
|
2923
|
+
pin,
|
|
2924
|
+
sheetRecord
|
|
2925
|
+
}) {
|
|
2926
|
+
const systemFontId = readSchematicInteger(
|
|
2927
|
+
sheetRecord?.getCaseInsensitive("SYSTEMFONT"),
|
|
2928
|
+
DEFAULT_SCHEMATIC_FONT_ID
|
|
2929
|
+
);
|
|
2930
|
+
const namePositionFlags = readSchematicInteger(
|
|
2931
|
+
pin.getCaseInsensitive("PINNAME_POSITIONCONGLOMERATE"),
|
|
2932
|
+
0
|
|
2933
|
+
);
|
|
2934
|
+
const hasCustomNameFont = (namePositionFlags & PIN_CUSTOM_FONT_ID_FLAG) !== 0;
|
|
2935
|
+
const recordFontId = readSchematicInteger(
|
|
2936
|
+
pin.getCaseInsensitive("FONTID"),
|
|
2937
|
+
systemFontId
|
|
2938
|
+
);
|
|
2939
|
+
const isLegacyPin = pin.getCaseInsensitive("PINNAME_POSITIONCONGLOMERATE") === void 0 && pin.getCaseInsensitive("PINDESIGNATOR_POSITIONCONGLOMERATE") === void 0;
|
|
2940
|
+
const hasLegacyFont = sheetRecord?.getCaseInsensitive(`SIZE${recordFontId}`) !== void 0;
|
|
2941
|
+
const inheritedFontId = isLegacyPin && hasLegacyFont ? recordFontId : systemFontId;
|
|
2942
|
+
const requestedFontId = hasCustomNameFont ? readSchematicInteger(
|
|
2943
|
+
pin.getCaseInsensitive("NAME_CUSTOMFONTID"),
|
|
2944
|
+
systemFontId
|
|
2945
|
+
) : inheritedFontId;
|
|
2946
|
+
const fontId = requestedFontId > 0 ? requestedFontId : systemFontId;
|
|
2947
|
+
const selectedSize = readSchematicInteger(
|
|
2948
|
+
sheetRecord?.getCaseInsensitive(`SIZE${fontId}`),
|
|
2949
|
+
DEFAULT_SCHEMATIC_FONT_SIZE
|
|
2950
|
+
);
|
|
2951
|
+
return selectedSize > 0 ? selectedSize : DEFAULT_SCHEMATIC_FONT_SIZE;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2914
2954
|
// lib/schematic/components/parseAltiumPinLabel.ts
|
|
2915
2955
|
function parseAltiumPinLabel(name) {
|
|
2916
2956
|
if (!name.includes("\\")) return { displayText: name };
|
|
@@ -2957,6 +2997,7 @@ function convertComponentPin({
|
|
|
2957
2997
|
pin,
|
|
2958
2998
|
pinIndex,
|
|
2959
2999
|
schematicComponentId,
|
|
3000
|
+
sheetRecord,
|
|
2960
3001
|
sourceComponentId,
|
|
2961
3002
|
visibleSymbolLabels
|
|
2962
3003
|
}) {
|
|
@@ -2998,6 +3039,10 @@ function convertComponentPin({
|
|
|
2998
3039
|
center: scalePoint(terminalPoint, options.scale),
|
|
2999
3040
|
...showName && name ? {
|
|
3000
3041
|
display_pin_label: parsedPinLabel.displayText,
|
|
3042
|
+
display_pin_label_font_size: scaleLength(
|
|
3043
|
+
getAltiumPinNameFontSize({ pin, sheetRecord }),
|
|
3044
|
+
options.scale
|
|
3045
|
+
),
|
|
3001
3046
|
...parsedPinLabel.textParts ? { display_pin_label_text_parts: parsedPinLabel.textParts } : {}
|
|
3002
3047
|
} : {},
|
|
3003
3048
|
distance_from_component_edge: scaleLength(pinLength, options.scale),
|
|
@@ -3023,6 +3068,54 @@ function convertComponentPin({
|
|
|
3023
3068
|
};
|
|
3024
3069
|
}
|
|
3025
3070
|
|
|
3071
|
+
// lib/schematic/components/convertOwnedCustomComponentBody.ts
|
|
3072
|
+
import {
|
|
3073
|
+
AltiumSchEllipseRecord,
|
|
3074
|
+
AltiumSchEllipticalArcRecord,
|
|
3075
|
+
AltiumSchPolygonRecord,
|
|
3076
|
+
AltiumSchPolylineRecord
|
|
3077
|
+
} from "altiumts";
|
|
3078
|
+
|
|
3079
|
+
// lib/schematic/components/convertOwnedComponentRecords.ts
|
|
3080
|
+
import {
|
|
3081
|
+
AltiumSchImageRecord as AltiumSchImageRecord2,
|
|
3082
|
+
AltiumSchPinRecord
|
|
3083
|
+
} from "altiumts";
|
|
3084
|
+
function convertOwnedComponentRecords({
|
|
3085
|
+
ownedRecords,
|
|
3086
|
+
schematicComponentId
|
|
3087
|
+
}, context) {
|
|
3088
|
+
const records = context.document.records;
|
|
3089
|
+
const renderingContext = {
|
|
3090
|
+
document: context.document,
|
|
3091
|
+
records,
|
|
3092
|
+
scale: context.options.scale,
|
|
3093
|
+
sheetRecord: records.find((record) => record.recordKind === "31")
|
|
3094
|
+
};
|
|
3095
|
+
return ownedRecords.flatMap((record) => {
|
|
3096
|
+
if (record instanceof AltiumSchImageRecord2) return [];
|
|
3097
|
+
const index = records.indexOf(record);
|
|
3098
|
+
if (index < 0) return [];
|
|
3099
|
+
const elements = convertSchematicRecord(
|
|
3100
|
+
{
|
|
3101
|
+
index,
|
|
3102
|
+
options: {
|
|
3103
|
+
includeHidden: context.options.includeHidden,
|
|
3104
|
+
includeText: record instanceof AltiumSchPinRecord ? false : context.options.includeText
|
|
3105
|
+
},
|
|
3106
|
+
record
|
|
3107
|
+
},
|
|
3108
|
+
renderingContext
|
|
3109
|
+
);
|
|
3110
|
+
return elements.map(
|
|
3111
|
+
(element) => element.type === "schematic_text" ? element : {
|
|
3112
|
+
...element,
|
|
3113
|
+
schematic_component_id: schematicComponentId
|
|
3114
|
+
}
|
|
3115
|
+
);
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3026
3119
|
// lib/schematic/rendering/convertSchematicArcToPath.ts
|
|
3027
3120
|
import {
|
|
3028
3121
|
applyToPoint as applyToPoint7,
|
|
@@ -3064,46 +3157,42 @@ function convertSchematicArcToPath(schematicArc) {
|
|
|
3064
3157
|
};
|
|
3065
3158
|
}
|
|
3066
3159
|
|
|
3067
|
-
// lib/schematic/components/
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
}, context) {
|
|
3076
|
-
const records = context.document.records;
|
|
3077
|
-
const renderingContext = {
|
|
3078
|
-
document: context.document,
|
|
3079
|
-
records,
|
|
3080
|
-
scale: context.options.scale,
|
|
3081
|
-
sheetRecord: records.find((record) => record.recordKind === "31")
|
|
3082
|
-
};
|
|
3083
|
-
return ownedRecords.flatMap((record) => {
|
|
3084
|
-
if (record instanceof AltiumSchImageRecord2) return [];
|
|
3085
|
-
const index = records.indexOf(record);
|
|
3086
|
-
if (index < 0) return [];
|
|
3087
|
-
const elements = convertSchematicRecord(
|
|
3088
|
-
{
|
|
3089
|
-
index,
|
|
3090
|
-
options: {
|
|
3091
|
-
includeHidden: context.options.includeHidden,
|
|
3092
|
-
includeText: record instanceof AltiumSchPinRecord ? false : context.options.includeText
|
|
3093
|
-
},
|
|
3094
|
-
record
|
|
3095
|
-
},
|
|
3096
|
-
renderingContext
|
|
3097
|
-
);
|
|
3098
|
-
return elements.map(
|
|
3099
|
-
(element) => element.type === "schematic_text" ? element : {
|
|
3100
|
-
...element,
|
|
3101
|
-
schematic_component_id: schematicComponentId
|
|
3102
|
-
}
|
|
3103
|
-
);
|
|
3160
|
+
// lib/schematic/components/prepareOwnedComponentBodyElements.ts
|
|
3161
|
+
function prepareOwnedComponentBodyElements(elements) {
|
|
3162
|
+
return elements.map(
|
|
3163
|
+
(element) => element.type === "schematic_arc" ? convertSchematicArcToPath(element) : element
|
|
3164
|
+
).sort((left, right) => {
|
|
3165
|
+
const leftIsFilled = "is_filled" in left && left.is_filled === true ? 1 : 0;
|
|
3166
|
+
const rightIsFilled = "is_filled" in right && right.is_filled === true ? 1 : 0;
|
|
3167
|
+
return rightIsFilled - leftIsFilled;
|
|
3104
3168
|
});
|
|
3105
3169
|
}
|
|
3106
3170
|
|
|
3171
|
+
// lib/schematic/components/convertOwnedCustomComponentBody.ts
|
|
3172
|
+
function convertOwnedCustomComponentBody({
|
|
3173
|
+
identity,
|
|
3174
|
+
records
|
|
3175
|
+
}, context) {
|
|
3176
|
+
const hasEllipse = records.some(
|
|
3177
|
+
(record) => record instanceof AltiumSchEllipseRecord
|
|
3178
|
+
);
|
|
3179
|
+
const hasEllipticalArc = records.some(
|
|
3180
|
+
(record) => record instanceof AltiumSchEllipticalArcRecord
|
|
3181
|
+
);
|
|
3182
|
+
const hasPolygon = records.some(
|
|
3183
|
+
(record) => record instanceof AltiumSchPolygonRecord || record instanceof AltiumSchPolylineRecord
|
|
3184
|
+
);
|
|
3185
|
+
if (!hasEllipse || !hasEllipticalArc || !hasPolygon) return void 0;
|
|
3186
|
+
const ownedElements = convertOwnedComponentRecords(
|
|
3187
|
+
{
|
|
3188
|
+
ownedRecords: records,
|
|
3189
|
+
schematicComponentId: identity.schematicComponentId
|
|
3190
|
+
},
|
|
3191
|
+
context
|
|
3192
|
+
);
|
|
3193
|
+
return prepareOwnedComponentBodyElements(ownedElements);
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3107
3196
|
// lib/schematic/components/convertOwnedLogicGateBody.ts
|
|
3108
3197
|
function convertOwnedLogicGateBody({
|
|
3109
3198
|
identity,
|
|
@@ -3131,18 +3220,25 @@ function convertOwnedLogicGateBody({
|
|
|
3131
3220
|
if (!ownedElements.some((element) => element.type === "schematic_arc")) {
|
|
3132
3221
|
return void 0;
|
|
3133
3222
|
}
|
|
3134
|
-
return ownedElements
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3223
|
+
return prepareOwnedComponentBodyElements(ownedElements);
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
// lib/schematic/components/convertOwnedComponentBody.ts
|
|
3227
|
+
function convertOwnedComponentBody({
|
|
3228
|
+
identity,
|
|
3229
|
+
pins,
|
|
3230
|
+
records,
|
|
3231
|
+
visibleSymbolLabels
|
|
3232
|
+
}, context) {
|
|
3233
|
+
return convertOwnedLogicGateBody(
|
|
3234
|
+
{ identity, pins, records, visibleSymbolLabels },
|
|
3235
|
+
context
|
|
3236
|
+
) ?? convertOwnedCustomComponentBody({ identity, records }, context);
|
|
3141
3237
|
}
|
|
3142
3238
|
|
|
3143
3239
|
// lib/schematic/components/getComponentBodyBounds.ts
|
|
3144
3240
|
import {
|
|
3145
|
-
AltiumSchEllipseRecord,
|
|
3241
|
+
AltiumSchEllipseRecord as AltiumSchEllipseRecord2,
|
|
3146
3242
|
AltiumSchPinRecord as AltiumSchPinRecord2,
|
|
3147
3243
|
AltiumSchRectangleRecord,
|
|
3148
3244
|
getSchematicRecordPoints as getSchematicRecordPoints6
|
|
@@ -3162,7 +3258,7 @@ function getComponentBodyBounds(records, portPoints) {
|
|
|
3162
3258
|
const corner = getCorner(record);
|
|
3163
3259
|
if (location && corner) points.push(location, corner);
|
|
3164
3260
|
points.push(...getSchematicRecordPoints6(record));
|
|
3165
|
-
if (record instanceof
|
|
3261
|
+
if (record instanceof AltiumSchEllipseRecord2 && location) {
|
|
3166
3262
|
const radiusX = Math.abs(
|
|
3167
3263
|
getCoordinateOrFallback({ record, key: "RADIUS", fallback: 0 })
|
|
3168
3264
|
);
|
|
@@ -3624,6 +3720,7 @@ function convertComponent({
|
|
|
3624
3720
|
pin,
|
|
3625
3721
|
pinIndex,
|
|
3626
3722
|
schematicComponentId: identity.schematicComponentId,
|
|
3723
|
+
sheetRecord: context.sheetRecord,
|
|
3627
3724
|
sourceComponentId: identity.sourceComponentId,
|
|
3628
3725
|
visibleSymbolLabels
|
|
3629
3726
|
})
|
|
@@ -3637,11 +3734,11 @@ function convertComponent({
|
|
|
3637
3734
|
libraryReference: identity.libraryReference,
|
|
3638
3735
|
ports: componentPorts
|
|
3639
3736
|
});
|
|
3640
|
-
const
|
|
3737
|
+
const ownedComponentBody = symbolSelection ? void 0 : convertOwnedComponentBody(
|
|
3641
3738
|
{ identity, pins, records: visibleOwnedRecords, visibleSymbolLabels },
|
|
3642
3739
|
context
|
|
3643
3740
|
);
|
|
3644
|
-
const
|
|
3741
|
+
const hasOwnedComponentBody = ownedComponentBody !== void 0;
|
|
3645
3742
|
const center = scalePoint(getBoundsCenter(bodyBounds), options.scale);
|
|
3646
3743
|
const size = symbolSelection ? { ...symbolSelection.symbol.size } : {
|
|
3647
3744
|
height: Math.max(
|
|
@@ -3659,7 +3756,7 @@ function convertComponent({
|
|
|
3659
3756
|
const pinEdgeElements = createComponentPinEdgeElements(
|
|
3660
3757
|
{
|
|
3661
3758
|
componentPorts,
|
|
3662
|
-
includeNumericDesignators:
|
|
3759
|
+
includeNumericDesignators: hasOwnedComponentBody,
|
|
3663
3760
|
pins
|
|
3664
3761
|
},
|
|
3665
3762
|
context
|
|
@@ -3673,12 +3770,12 @@ function convertComponent({
|
|
|
3673
3770
|
]
|
|
3674
3771
|
),
|
|
3675
3772
|
...pinEdgeElements,
|
|
3676
|
-
...
|
|
3773
|
+
...ownedComponentBody ?? []
|
|
3677
3774
|
);
|
|
3678
3775
|
const schematicComponent = {
|
|
3679
3776
|
type: "schematic_component",
|
|
3680
3777
|
center,
|
|
3681
|
-
is_box_with_pins: !
|
|
3778
|
+
is_box_with_pins: !hasOwnedComponentBody,
|
|
3682
3779
|
schematic_component_id: identity.schematicComponentId,
|
|
3683
3780
|
schematic_sheet_id: options.schematicSheetId,
|
|
3684
3781
|
size,
|
|
@@ -3687,7 +3784,7 @@ function convertComponent({
|
|
|
3687
3784
|
...symbolSelection ? { symbol_name: symbolSelection.name } : {}
|
|
3688
3785
|
};
|
|
3689
3786
|
elements.push(schematicComponent);
|
|
3690
|
-
if (!symbolSelection && !
|
|
3787
|
+
if (!symbolSelection && !hasOwnedComponentBody && options.includeText !== false) {
|
|
3691
3788
|
addComponentFallbackText({
|
|
3692
3789
|
componentIndex,
|
|
3693
3790
|
designator: identity.designator,
|
|
@@ -3710,6 +3807,9 @@ function convertComponents({
|
|
|
3710
3807
|
options
|
|
3711
3808
|
}) {
|
|
3712
3809
|
const sourceComponentIdByDesignator = /* @__PURE__ */ new Map();
|
|
3810
|
+
const sheetRecord = document.records.find(
|
|
3811
|
+
(record) => record.recordKind === "31"
|
|
3812
|
+
);
|
|
3713
3813
|
for (const [componentIndex, componentRecord] of document.records.entries()) {
|
|
3714
3814
|
if (!(componentRecord instanceof AltiumSchComponentRecord)) continue;
|
|
3715
3815
|
convertComponent(
|
|
@@ -3720,6 +3820,7 @@ function convertComponents({
|
|
|
3720
3820
|
elements,
|
|
3721
3821
|
handledRecords,
|
|
3722
3822
|
options,
|
|
3823
|
+
sheetRecord,
|
|
3723
3824
|
sourceComponentIdByDesignator
|
|
3724
3825
|
}
|
|
3725
3826
|
);
|