altium-to-circuit-json 0.0.65 → 0.0.67

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 CHANGED
@@ -1580,7 +1580,7 @@ function convertRemainingSchematicRecords(context) {
1580
1580
  }
1581
1581
 
1582
1582
  // lib/schematic/document/convertSchematicSemantics.ts
1583
- import { AltiumSchImageRecord as AltiumSchImageRecord2 } from "altiumts";
1583
+ import { AltiumSchImageRecord as AltiumSchImageRecord3 } from "altiumts";
1584
1584
 
1585
1585
  // lib/schematic/components/createComponentText.ts
1586
1586
  function createComponentText({
@@ -1643,7 +1643,7 @@ function addComponentFallbackText({
1643
1643
  // lib/schematic/components/convertComponent.ts
1644
1644
  import {
1645
1645
  AltiumSchLabelRecord,
1646
- AltiumSchPinRecord as AltiumSchPinRecord2
1646
+ AltiumSchPinRecord as AltiumSchPinRecord3
1647
1647
  } from "altiumts";
1648
1648
 
1649
1649
  // lib/schematic/symbols/applyNativeSymbolPortGeometry.ts
@@ -2828,6 +2828,7 @@ function convertComponentPin({
2828
2828
  side_of_component: directionToSide(direction),
2829
2829
  source_port_id: sourcePortId,
2830
2830
  true_ccw_index: pinIndex,
2831
+ ...pin.getNumber("SYMBOL_OUTEREDGE") === 1 ? { is_drawn_with_inversion_circle: true } : {},
2831
2832
  ...pinNumber === void 0 ? {} : { pin_number: pinNumber },
2832
2833
  ...electricalType === 0 || electricalType === 1 ? { has_input_arrow: true } : {},
2833
2834
  ...electricalType === 1 || electricalType === 2 ? { has_output_arrow: true } : {}
@@ -2841,6 +2842,135 @@ function convertComponentPin({
2841
2842
  };
2842
2843
  }
2843
2844
 
2845
+ // lib/schematic/components/convertOwnedComponentRecords.ts
2846
+ import {
2847
+ AltiumSchImageRecord as AltiumSchImageRecord2,
2848
+ AltiumSchPinRecord
2849
+ } from "altiumts";
2850
+ function convertOwnedComponentRecords({
2851
+ ownedRecords,
2852
+ schematicComponentId
2853
+ }, context) {
2854
+ const records = context.document.records;
2855
+ const renderingContext = {
2856
+ document: context.document,
2857
+ records,
2858
+ scale: context.options.scale,
2859
+ sheetRecord: records.find((record) => record.recordKind === "31")
2860
+ };
2861
+ return ownedRecords.flatMap((record) => {
2862
+ if (record instanceof AltiumSchImageRecord2) return [];
2863
+ const index = records.indexOf(record);
2864
+ if (index < 0) return [];
2865
+ const elements = convertSchematicRecord(
2866
+ {
2867
+ index,
2868
+ options: {
2869
+ includeHidden: context.options.includeHidden,
2870
+ includeText: record instanceof AltiumSchPinRecord ? false : context.options.includeText
2871
+ },
2872
+ record
2873
+ },
2874
+ renderingContext
2875
+ );
2876
+ return elements.map(
2877
+ (element) => element.type === "schematic_text" ? element : {
2878
+ ...element,
2879
+ schematic_component_id: schematicComponentId
2880
+ }
2881
+ );
2882
+ });
2883
+ }
2884
+
2885
+ // lib/schematic/components/getComponentBodyBounds.ts
2886
+ import {
2887
+ AltiumSchEllipseRecord,
2888
+ AltiumSchPinRecord as AltiumSchPinRecord2,
2889
+ AltiumSchRectangleRecord,
2890
+ getSchematicRecordPoints as getSchematicRecordPoints6
2891
+ } from "altiumts";
2892
+ function getComponentBodyBounds(records, portPoints) {
2893
+ const rectangles = records.filter(
2894
+ (record) => record instanceof AltiumSchRectangleRecord
2895
+ ).flatMap((record) => {
2896
+ const rectangle = getRectangle(record);
2897
+ return rectangle ? [rectangle] : [];
2898
+ });
2899
+ if (rectangles.length > 0) return mergeBounds(rectangles);
2900
+ const points = [];
2901
+ for (const record of records) {
2902
+ if (record instanceof AltiumSchPinRecord2) continue;
2903
+ const location = getLocation(record);
2904
+ const corner = getCorner(record);
2905
+ if (location && corner) points.push(location, corner);
2906
+ points.push(...getSchematicRecordPoints6(record));
2907
+ if (record instanceof AltiumSchEllipseRecord && location) {
2908
+ const radiusX = Math.abs(
2909
+ getCoordinateOrFallback({ record, key: "RADIUS", fallback: 0 })
2910
+ );
2911
+ const radiusY = Math.abs(
2912
+ getCoordinateOrFallback({
2913
+ record,
2914
+ key: "SECONDARYRADIUS",
2915
+ fallback: radiusX
2916
+ })
2917
+ );
2918
+ points.push(
2919
+ { x: location.x - radiusX, y: location.y - radiusY },
2920
+ { x: location.x + radiusX, y: location.y + radiusY }
2921
+ );
2922
+ }
2923
+ }
2924
+ if (points.length > 0) return getBoundsForPoints(points);
2925
+ const bounds = getBoundsForPoints(portPoints);
2926
+ if (bounds.minX === bounds.maxX) {
2927
+ bounds.minX -= 2;
2928
+ bounds.maxX += 2;
2929
+ }
2930
+ if (bounds.minY === bounds.maxY) {
2931
+ bounds.minY -= 2;
2932
+ bounds.maxY += 2;
2933
+ }
2934
+ return bounds;
2935
+ }
2936
+
2937
+ // lib/schematic/components/convertPinlessComponent.ts
2938
+ function convertPinlessComponent({
2939
+ identity,
2940
+ ownedRecords
2941
+ }, context) {
2942
+ const bodyBounds = getComponentBodyBounds(ownedRecords, []);
2943
+ const { elements, options } = context;
2944
+ elements.push(
2945
+ {
2946
+ type: "schematic_component",
2947
+ center: scalePoint(getBoundsCenter(bodyBounds), options.scale),
2948
+ is_box_with_pins: false,
2949
+ schematic_component_id: identity.schematicComponentId,
2950
+ schematic_sheet_id: options.schematicSheetId,
2951
+ size: {
2952
+ height: Math.max(
2953
+ scaleLength(bodyBounds.maxY - bodyBounds.minY, options.scale),
2954
+ 0.4
2955
+ ),
2956
+ width: Math.max(
2957
+ scaleLength(bodyBounds.maxX - bodyBounds.minX, options.scale),
2958
+ 0.4
2959
+ )
2960
+ },
2961
+ source_component_id: identity.sourceComponentId,
2962
+ symbol_display_value: identity.displayText
2963
+ },
2964
+ ...convertOwnedComponentRecords(
2965
+ {
2966
+ ownedRecords,
2967
+ schematicComponentId: identity.schematicComponentId
2968
+ },
2969
+ context
2970
+ )
2971
+ );
2972
+ }
2973
+
2844
2974
  // lib/schematic/components/createAlphanumericPinDesignatorText.ts
2845
2975
  var EDGE_VECTOR_BY_SIDE = {
2846
2976
  bottom: { x: 0, y: 1 },
@@ -2880,6 +3010,80 @@ function createAlphanumericPinDesignatorText({
2880
3010
  };
2881
3011
  }
2882
3012
 
3013
+ // lib/schematic/components/createPinClockSymbol.ts
3014
+ var EDGE_VECTOR_BY_SIDE2 = {
3015
+ bottom: { x: 0, y: 1 },
3016
+ left: { x: 1, y: 0 },
3017
+ right: { x: -1, y: 0 },
3018
+ top: { x: 0, y: -1 }
3019
+ };
3020
+ function createPinClockSymbol({
3021
+ pin,
3022
+ recordIndex,
3023
+ scale: scale5,
3024
+ schematicPort
3025
+ }) {
3026
+ const side = schematicPort.side_of_component;
3027
+ if (pin.getNumber("SYMBOL_INNEREDGE") !== 3 || !side) return void 0;
3028
+ const edgeVector = EDGE_VECTOR_BY_SIDE2[side];
3029
+ const pinLength = schematicPort.distance_from_component_edge ?? 0.4;
3030
+ const bodyPosition = {
3031
+ x: schematicPort.center.x + edgeVector.x * pinLength,
3032
+ y: schematicPort.center.y + edgeVector.y * pinLength
3033
+ };
3034
+ const clockDepth = scaleLength(4, scale5);
3035
+ const clockHalfWidth = scaleLength(2, scale5);
3036
+ const perpendicularVector = { x: -edgeVector.y, y: edgeVector.x };
3037
+ const clockTip = {
3038
+ x: bodyPosition.x + edgeVector.x * clockDepth,
3039
+ y: bodyPosition.y + edgeVector.y * clockDepth
3040
+ };
3041
+ const clockBaseStart = {
3042
+ x: bodyPosition.x + perpendicularVector.x * clockHalfWidth,
3043
+ y: bodyPosition.y + perpendicularVector.y * clockHalfWidth
3044
+ };
3045
+ const clockBaseEnd = {
3046
+ x: bodyPosition.x - perpendicularVector.x * clockHalfWidth,
3047
+ y: bodyPosition.y - perpendicularVector.y * clockHalfWidth
3048
+ };
3049
+ return {
3050
+ type: "schematic_path",
3051
+ fill_color: "transparent",
3052
+ is_dashed: false,
3053
+ is_filled: false,
3054
+ points: [clockTip, clockBaseStart, clockBaseEnd, clockTip],
3055
+ schematic_component_id: schematicPort.schematic_component_id,
3056
+ schematic_path_id: `schematic_pin_clock_altium_${recordIndex}`,
3057
+ schematic_sheet_id: schematicPort.schematic_sheet_id,
3058
+ stroke_color: "#a90000",
3059
+ stroke_width: 0.02
3060
+ };
3061
+ }
3062
+
3063
+ // lib/schematic/components/createComponentPinEdgeElements.ts
3064
+ function createComponentPinEdgeElements({
3065
+ componentPorts,
3066
+ pins
3067
+ }, context) {
3068
+ return componentPorts.flatMap(
3069
+ ({ isSchematicVisible, schematicPort }, pinIndex) => {
3070
+ if (!isSchematicVisible) return [];
3071
+ const pin = pins[pinIndex];
3072
+ if (!pin) return [];
3073
+ const edgeElementParameters = {
3074
+ pin,
3075
+ recordIndex: context.document.records.indexOf(pin),
3076
+ scale: context.options.scale,
3077
+ schematicPort
3078
+ };
3079
+ return [
3080
+ createAlphanumericPinDesignatorText(edgeElementParameters),
3081
+ createPinClockSymbol(edgeElementParameters)
3082
+ ].filter((element) => element !== void 0);
3083
+ }
3084
+ );
3085
+ }
3086
+
2883
3087
  // lib/schematic/components/createSourceComponent.ts
2884
3088
  import {
2885
3089
  source_simple_capacitor,
@@ -2999,58 +3203,6 @@ function createSourceComponent({
2999
3203
  };
3000
3204
  }
3001
3205
 
3002
- // lib/schematic/components/getComponentBodyBounds.ts
3003
- import {
3004
- AltiumSchEllipseRecord,
3005
- AltiumSchPinRecord,
3006
- AltiumSchRectangleRecord,
3007
- getSchematicRecordPoints as getSchematicRecordPoints6
3008
- } from "altiumts";
3009
- function getComponentBodyBounds(records, portPoints) {
3010
- const rectangles = records.filter(
3011
- (record) => record instanceof AltiumSchRectangleRecord
3012
- ).flatMap((record) => {
3013
- const rectangle = getRectangle(record);
3014
- return rectangle ? [rectangle] : [];
3015
- });
3016
- if (rectangles.length > 0) return mergeBounds(rectangles);
3017
- const points = [];
3018
- for (const record of records) {
3019
- if (record instanceof AltiumSchPinRecord) continue;
3020
- const location = getLocation(record);
3021
- const corner = getCorner(record);
3022
- if (location && corner) points.push(location, corner);
3023
- points.push(...getSchematicRecordPoints6(record));
3024
- if (record instanceof AltiumSchEllipseRecord && location) {
3025
- const radiusX = Math.abs(
3026
- getCoordinateOrFallback({ record, key: "RADIUS", fallback: 0 })
3027
- );
3028
- const radiusY = Math.abs(
3029
- getCoordinateOrFallback({
3030
- record,
3031
- key: "SECONDARYRADIUS",
3032
- fallback: radiusX
3033
- })
3034
- );
3035
- points.push(
3036
- { x: location.x - radiusX, y: location.y - radiusY },
3037
- { x: location.x + radiusX, y: location.y + radiusY }
3038
- );
3039
- }
3040
- }
3041
- if (points.length > 0) return getBoundsForPoints(points);
3042
- const bounds = getBoundsForPoints(portPoints);
3043
- if (bounds.minX === bounds.maxX) {
3044
- bounds.minX -= 2;
3045
- bounds.maxX += 2;
3046
- }
3047
- if (bounds.minY === bounds.maxY) {
3048
- bounds.minY -= 2;
3049
- bounds.maxY += 2;
3050
- }
3051
- return bounds;
3052
- }
3053
-
3054
3206
  // lib/schematic/components/findOwnedDesignator.ts
3055
3207
  import { AltiumSchDesignatorRecord } from "altiumts";
3056
3208
  function findOwnedDesignator(records) {
@@ -3127,16 +3279,7 @@ function convertComponent({
3127
3279
  (record) => isOwnedRecordVisible(record, currentPartId)
3128
3280
  );
3129
3281
  const pins = visibleOwnedRecords.filter(
3130
- (record) => record instanceof AltiumSchPinRecord2 && (!isPinHidden(record) || options.includeHidden === true)
3131
- );
3132
- if (pins.length === 0) return;
3133
- const visibleSymbolLabels = new Set(
3134
- visibleOwnedRecords.filter(
3135
- (record) => record instanceof AltiumSchLabelRecord
3136
- ).flatMap((record) => {
3137
- const text = record.text?.trim().toUpperCase();
3138
- return text ? [text] : [];
3139
- })
3282
+ (record) => record instanceof AltiumSchPinRecord3 && (!isPinHidden(record) || options.includeHidden === true)
3140
3283
  );
3141
3284
  const identity = getComponentIdentity(
3142
3285
  { componentIndex, componentRecord, ownedRecords },
@@ -3154,6 +3297,21 @@ function convertComponent({
3154
3297
  })
3155
3298
  );
3156
3299
  }
3300
+ if (pins.length === 0) {
3301
+ convertPinlessComponent(
3302
+ { identity, ownedRecords: visibleOwnedRecords },
3303
+ context
3304
+ );
3305
+ return;
3306
+ }
3307
+ const visibleSymbolLabels = new Set(
3308
+ visibleOwnedRecords.filter(
3309
+ (record) => record instanceof AltiumSchLabelRecord
3310
+ ).flatMap((record) => {
3311
+ const text = record.text?.trim().toUpperCase();
3312
+ return text ? [text] : [];
3313
+ })
3314
+ );
3157
3315
  const componentPorts = pins.map(
3158
3316
  (pin, pinIndex) => convertComponentPin({
3159
3317
  document,
@@ -3188,19 +3346,9 @@ function convertComponent({
3188
3346
  if (symbolSelection) {
3189
3347
  applyNativeSymbolPortGeometry({ center, selection: symbolSelection });
3190
3348
  }
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
- }
3349
+ const pinEdgeElements = createComponentPinEdgeElements(
3350
+ { componentPorts, pins },
3351
+ context
3204
3352
  );
3205
3353
  convertedPorts.push(...componentPorts);
3206
3354
  elements.push(
@@ -3210,7 +3358,7 @@ function convertComponent({
3210
3358
  ...isSchematicVisible ? [schematicPort] : []
3211
3359
  ]
3212
3360
  ),
3213
- ...pinDesignatorTexts
3361
+ ...pinEdgeElements
3214
3362
  );
3215
3363
  const schematicComponent = {
3216
3364
  type: "schematic_component",
@@ -3514,7 +3662,7 @@ function convertSchematicSemantics(context) {
3514
3662
  });
3515
3663
  context.elements.push(...conversion.elements);
3516
3664
  for (const record of conversion.handledRecords) {
3517
- if (record instanceof AltiumSchImageRecord2) continue;
3665
+ if (record instanceof AltiumSchImageRecord3) continue;
3518
3666
  context.handledRecords.add(record);
3519
3667
  }
3520
3668
  }