altium-to-circuit-json 0.0.93 → 0.0.95

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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as circuit_json from 'circuit-json';
2
- import { LayerRef, SourceSimpleChip, SourcePort, AnyCircuitElement, SourceNet, SourceTrace } from 'circuit-json';
3
- import { AltiumPcbDocument, AltiumPrjPcb, AltiumRecord, AltiumPadRecord, AltiumSchDoc } from 'altiumts';
2
+ import { LayerRef, SourceSimpleChip, SourcePort, AnyCircuitElement, SourceNet, SourceTrace, SchematicPort } from 'circuit-json';
3
+ import { AltiumPcbDocument, AltiumPrjPcb, AltiumRecord, AltiumPadRecord, AltiumPoint, AltiumSchDoc } from 'altiumts';
4
4
  import * as zod from 'zod';
5
5
 
6
6
  declare class PcbCopperLayerMap {
@@ -45,7 +45,16 @@ interface PcbConversionContext {
45
45
  options: ConvertAltiumPcbDocOptions;
46
46
  }
47
47
 
48
+ interface ConvertedPort {
49
+ isSchematicVisible: boolean;
50
+ point: AltiumPoint;
51
+ record: AltiumRecord;
52
+ schematicPort: SchematicPort;
53
+ sourcePort: SourcePort;
54
+ }
55
+
48
56
  interface SchematicConversionContext extends SchematicContext {
57
+ convertedPorts: ConvertedPort[];
49
58
  elements: AnyCircuitElement[];
50
59
  handledRecords: Set<AltiumRecord>;
51
60
  options: ConvertAltiumSchDocOptions;
package/dist/index.js CHANGED
@@ -1644,6 +1644,34 @@ function renderSchematicPolylineRecord({
1644
1644
  ];
1645
1645
  }
1646
1646
 
1647
+ // lib/schematic/geometry/getRoundedRectangleCircle.ts
1648
+ function getRoundedRectangleCircle(record) {
1649
+ if (record.recordKind !== "10") return void 0;
1650
+ const bounds = getRectangle(record);
1651
+ if (!bounds) return void 0;
1652
+ const width = bounds.maxX - bounds.minX;
1653
+ const height = bounds.maxY - bounds.minY;
1654
+ if (width <= 0 || Math.abs(width - height) > 1e-4) return void 0;
1655
+ const radiusX = getCoordinateOrFallback({
1656
+ record,
1657
+ key: "CORNERXRADIUS",
1658
+ fallback: 0
1659
+ });
1660
+ const radiusY = getCoordinateOrFallback({
1661
+ record,
1662
+ key: "CORNERYRADIUS",
1663
+ fallback: radiusX
1664
+ });
1665
+ if (radiusX < width / 2 || radiusY < height / 2) return void 0;
1666
+ return {
1667
+ center: {
1668
+ x: (bounds.minX + bounds.maxX) / 2,
1669
+ y: (bounds.minY + bounds.maxY) / 2
1670
+ },
1671
+ radius: width / 2
1672
+ };
1673
+ }
1674
+
1647
1675
  // lib/schematic/rendering/renderSchematicRectangleRecord.ts
1648
1676
  function renderSchematicRectangleRecord({
1649
1677
  color,
@@ -1655,6 +1683,26 @@ function renderSchematicRectangleRecord({
1655
1683
  if (record.recordKind !== "10" && record.recordKind !== "14") return void 0;
1656
1684
  const rectangle = getRectangle(record);
1657
1685
  if (!rectangle) return [];
1686
+ const circle = getRoundedRectangleCircle(record);
1687
+ if (circle) {
1688
+ return [
1689
+ {
1690
+ type: "schematic_circle",
1691
+ schematic_circle_id: `schematic_circle_altium_${index}`,
1692
+ schematic_sheet_id: SCHEMATIC_SHEET_ID,
1693
+ center: scalePoint(circle.center, context.scale),
1694
+ radius: scaleLength(circle.radius, context.scale),
1695
+ stroke_width: strokeWidth,
1696
+ color,
1697
+ is_filled: record.getBoolean("ISSOLID") === true,
1698
+ fill_color: altiumColorToCss(
1699
+ record.getCaseInsensitive("AREACOLOR"),
1700
+ "#ffffff"
1701
+ ),
1702
+ is_dashed: false
1703
+ }
1704
+ ];
1705
+ }
1658
1706
  return [
1659
1707
  {
1660
1708
  type: "schematic_rect",
@@ -1957,6 +2005,27 @@ function convertSchematicRecord({
1957
2005
  return [];
1958
2006
  }
1959
2007
 
2008
+ // lib/schematic/rendering/associateNoErcMarkerWithPortAtAnchor.ts
2009
+ function associateNoErcMarkerWithPortAtAnchor({
2010
+ convertedPorts,
2011
+ markerAnchor,
2012
+ markerElements,
2013
+ schematicUnitScale
2014
+ }) {
2015
+ const markerLine = markerElements.find(
2016
+ (element) => element.type === "schematic_line"
2017
+ );
2018
+ if (!markerLine) return markerElements;
2019
+ const matchingPort = convertedPorts.find(
2020
+ ({ point, schematicPort }) => schematicPort.schematic_sheet_id === markerLine.schematic_sheet_id && pointsEqual(scalePoint(point, schematicUnitScale), markerAnchor)
2021
+ );
2022
+ const schematicComponentId = matchingPort?.schematicPort.schematic_component_id;
2023
+ if (!schematicComponentId) return markerElements;
2024
+ return markerElements.map(
2025
+ (element) => element.type === "schematic_line" ? { ...element, schematic_component_id: schematicComponentId } : element
2026
+ );
2027
+ }
2028
+
1960
2029
  // lib/schematic/document/shouldRenderSchematicRecord.ts
1961
2030
  function shouldRenderSchematicRecord(record, context) {
1962
2031
  let ownerPartId = record.getNumber("OWNERPARTID");
@@ -1987,11 +2056,18 @@ function convertRemainingSchematicRecords(context) {
1987
2056
  for (const [recordIndex, record] of context.records.entries()) {
1988
2057
  if (context.handledRecords.has(record)) continue;
1989
2058
  if (!shouldRenderSchematicRecord(record, context)) continue;
2059
+ const convertedElements = convertSchematicRecord(
2060
+ { record, index: recordIndex, options: context.options },
2061
+ context
2062
+ );
2063
+ const noErcMarkerLocation = record.recordKind === "22" ? getLocation(record) : void 0;
1990
2064
  context.elements.push(
1991
- ...convertSchematicRecord(
1992
- { record, index: recordIndex, options: context.options },
1993
- context
1994
- )
2065
+ ...noErcMarkerLocation ? associateNoErcMarkerWithPortAtAnchor({
2066
+ convertedPorts: context.convertedPorts,
2067
+ markerAnchor: scalePoint(noErcMarkerLocation, context.scale),
2068
+ markerElements: convertedElements,
2069
+ schematicUnitScale: context.scale
2070
+ }) : convertedElements
1995
2071
  );
1996
2072
  }
1997
2073
  }
@@ -3320,7 +3396,9 @@ import {
3320
3396
  AltiumSchEllipticalArcRecord,
3321
3397
  AltiumSchLineRecord,
3322
3398
  AltiumSchPolygonRecord,
3323
- AltiumSchPolylineRecord
3399
+ AltiumSchPolylineRecord,
3400
+ AltiumSchRectangleRecord,
3401
+ AltiumSchRoundedRectangleRecord
3324
3402
  } from "altiumts";
3325
3403
 
3326
3404
  // lib/schematic/components/convertOwnedComponentRecords.ts
@@ -3443,7 +3521,16 @@ function convertOwnedCustomComponentBody({
3443
3521
  const bodyPrimitiveCount = records.filter(
3444
3522
  (record) => record instanceof AltiumSchEllipseRecord || record instanceof AltiumSchArcRecord || record instanceof AltiumSchEllipticalArcRecord || record instanceof AltiumSchLineRecord || record instanceof AltiumSchPolygonRecord || record instanceof AltiumSchPolylineRecord
3445
3523
  ).length;
3446
- if (bodyPrimitiveCount < 3 || bodyPrimitiveKinds.size < 2) return void 0;
3524
+ const hasCircularShape = records.some(
3525
+ (record) => record instanceof AltiumSchEllipseRecord || getRoundedRectangleCircle(record) !== void 0
3526
+ );
3527
+ const hasOtherBodyShape = records.some(
3528
+ (record) => record instanceof AltiumSchRectangleRecord || record instanceof AltiumSchRoundedRectangleRecord && getRoundedRectangleCircle(record) === void 0 || record instanceof AltiumSchArcRecord || record instanceof AltiumSchEllipticalArcRecord || record instanceof AltiumSchLineRecord || record instanceof AltiumSchPolygonRecord || record instanceof AltiumSchPolylineRecord
3529
+ );
3530
+ const hasSimpleCircularBody = hasCircularShape && !hasOtherBodyShape;
3531
+ if (!hasSimpleCircularBody && (bodyPrimitiveCount < 3 || bodyPrimitiveKinds.size < 2)) {
3532
+ return void 0;
3533
+ }
3447
3534
  const ownedElements = convertOwnedComponentRecords(
3448
3535
  {
3449
3536
  ownedRecords: records,
@@ -3700,12 +3787,12 @@ function convertOwnedSingleInputGateBody({
3700
3787
  import {
3701
3788
  AltiumSchEllipseRecord as AltiumSchEllipseRecord2,
3702
3789
  AltiumSchPinRecord as AltiumSchPinRecord4,
3703
- AltiumSchRectangleRecord,
3790
+ AltiumSchRectangleRecord as AltiumSchRectangleRecord2,
3704
3791
  getSchematicRecordPoints as getSchematicRecordPoints6
3705
3792
  } from "altiumts";
3706
3793
  function getComponentBodyBounds(records, portPoints) {
3707
3794
  const rectangles = records.filter(
3708
- (record) => record instanceof AltiumSchRectangleRecord
3795
+ (record) => record instanceof AltiumSchRectangleRecord2
3709
3796
  ).flatMap((record) => {
3710
3797
  const rectangle = getRectangle(record);
3711
3798
  return rectangle ? [rectangle] : [];
@@ -4485,7 +4572,7 @@ function convertSemanticSchematic(document, options) {
4485
4572
  semanticNetGraph,
4486
4573
  options
4487
4574
  });
4488
- return { elements, handledRecords };
4575
+ return { convertedPorts, elements, handledRecords };
4489
4576
  }
4490
4577
 
4491
4578
  // lib/schematic/document/convertSchematicSemantics.ts
@@ -4495,6 +4582,7 @@ function convertSchematicSemantics(context) {
4495
4582
  scale: context.scale,
4496
4583
  schematicSheetId: SCHEMATIC_SHEET_ID
4497
4584
  });
4585
+ context.convertedPorts.push(...conversion.convertedPorts);
4498
4586
  context.elements.push(...conversion.elements);
4499
4587
  for (const record of conversion.handledRecords) {
4500
4588
  if (record instanceof AltiumSchImageRecord3) continue;
@@ -4523,6 +4611,7 @@ function createSchematicConversionContext({
4523
4611
  throw new RangeError("schematicUnitScale must be a positive finite number");
4524
4612
  }
4525
4613
  return {
4614
+ convertedPorts: [],
4526
4615
  document,
4527
4616
  elements: [],
4528
4617
  handledRecords: /* @__PURE__ */ new Set(),