altium-to-circuit-json 0.0.76 → 0.0.78
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 +6 -1
- package/dist/index.js +162 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayerRef, SourceSimpleChip, SourcePort, AnyCircuitElement, SourceNet, SourceTrace } from 'circuit-json';
|
|
2
|
-
import { AltiumPcbDocument, AltiumRecord, AltiumPadRecord, AltiumSchDoc } from 'altiumts';
|
|
2
|
+
import { AltiumPcbDocument, AltiumRecord, AltiumPadRecord, AltiumSchDoc, AltiumPrjPcb } from 'altiumts';
|
|
3
3
|
|
|
4
4
|
declare class PcbCopperLayerMap {
|
|
5
5
|
readonly layers: LayerRef[];
|
|
@@ -110,9 +110,14 @@ declare function convertAltiumPcbDocToCircuitJson(document: AltiumPcbDocument, o
|
|
|
110
110
|
|
|
111
111
|
interface ConvertAltiumSchDocOptions {
|
|
112
112
|
centerOnSchematicSheet?: boolean;
|
|
113
|
+
currentDate?: string;
|
|
114
|
+
currentTime?: string;
|
|
115
|
+
documentName?: string;
|
|
113
116
|
includeHidden?: boolean;
|
|
114
117
|
includeSheetBorder?: boolean;
|
|
115
118
|
includeText?: boolean;
|
|
119
|
+
project?: AltiumPrjPcb;
|
|
120
|
+
projectName?: string;
|
|
116
121
|
schematicUnitScale?: number;
|
|
117
122
|
sheetName?: string;
|
|
118
123
|
}
|
package/dist/index.js
CHANGED
|
@@ -837,6 +837,28 @@ function getFontFamily(record, context) {
|
|
|
837
837
|
return context.sheetRecord?.getDecoded(`FONTNAME${fontId}`) ?? "Arial";
|
|
838
838
|
}
|
|
839
839
|
|
|
840
|
+
// lib/schematic/text/resolveSchematicText.ts
|
|
841
|
+
import {
|
|
842
|
+
resolveSchematicParameterReferenceWithContext
|
|
843
|
+
} from "altiumts";
|
|
844
|
+
function resolveSchematicText({
|
|
845
|
+
document,
|
|
846
|
+
options,
|
|
847
|
+
record,
|
|
848
|
+
reference
|
|
849
|
+
}) {
|
|
850
|
+
return resolveSchematicParameterReferenceWithContext({
|
|
851
|
+
currentDate: options.currentDate,
|
|
852
|
+
currentTime: options.currentTime,
|
|
853
|
+
document,
|
|
854
|
+
documentName: options.documentName,
|
|
855
|
+
project: options.project,
|
|
856
|
+
projectName: options.projectName,
|
|
857
|
+
record,
|
|
858
|
+
reference
|
|
859
|
+
}) ?? reference;
|
|
860
|
+
}
|
|
861
|
+
|
|
840
862
|
// lib/schematic/text/wrapSchematicText.ts
|
|
841
863
|
function wrapSchematicText({
|
|
842
864
|
text,
|
|
@@ -879,12 +901,18 @@ function renderTextRecord({
|
|
|
879
901
|
}) {
|
|
880
902
|
const kind = record.recordKind;
|
|
881
903
|
const scale5 = context.scale;
|
|
882
|
-
if (kind === "4" || kind === "25" || kind === "34" || kind === "41") {
|
|
904
|
+
if (kind === "4" || kind === "25" || kind === "32" || kind === "33" || kind === "34" || kind === "41") {
|
|
883
905
|
if (options.includeText === false) return [];
|
|
884
906
|
if (record.getBoolean("ISHIDDEN") && !options.includeHidden) return [];
|
|
885
|
-
const
|
|
907
|
+
const reference = record.getDecoded("TEXT") ?? record.getDecoded("NAME") ?? record.getDecoded("DESIGNATOR");
|
|
886
908
|
const location = getLocation(record);
|
|
887
|
-
if (!
|
|
909
|
+
if (!reference || !location) return [];
|
|
910
|
+
const text = resolveSchematicText({
|
|
911
|
+
document: context.document,
|
|
912
|
+
options,
|
|
913
|
+
record,
|
|
914
|
+
reference
|
|
915
|
+
});
|
|
888
916
|
return [createText({ record, index, text, location, color, context })];
|
|
889
917
|
}
|
|
890
918
|
if (kind === "28") {
|
|
@@ -1633,6 +1661,124 @@ function renderSchematicImageRecord({
|
|
|
1633
1661
|
];
|
|
1634
1662
|
}
|
|
1635
1663
|
|
|
1664
|
+
// lib/schematic/rendering/renderSheetEntry.ts
|
|
1665
|
+
function renderSheetEntry({
|
|
1666
|
+
context,
|
|
1667
|
+
index,
|
|
1668
|
+
options,
|
|
1669
|
+
record
|
|
1670
|
+
}) {
|
|
1671
|
+
const sheetSymbol = context.document.getParent(record);
|
|
1672
|
+
const sheetLocation = sheetSymbol ? getLocation(sheetSymbol) : void 0;
|
|
1673
|
+
if (!sheetSymbol || sheetSymbol.recordKind !== "15" || !sheetLocation) {
|
|
1674
|
+
return [];
|
|
1675
|
+
}
|
|
1676
|
+
const sheetWidth = Math.max(
|
|
1677
|
+
getCoordinateOrFallback({ record: sheetSymbol, key: "XSIZE", fallback: 1 }),
|
|
1678
|
+
1
|
|
1679
|
+
);
|
|
1680
|
+
const sheetHeight = Math.max(
|
|
1681
|
+
getCoordinateOrFallback({ record: sheetSymbol, key: "YSIZE", fallback: 1 }),
|
|
1682
|
+
1
|
|
1683
|
+
);
|
|
1684
|
+
const distance = Math.max(record.getNumber("DISTANCEFROMTOP") ?? 0, 0) * 10;
|
|
1685
|
+
const rawSide = Math.round(record.getNumber("SIDE") ?? 0);
|
|
1686
|
+
const side = rawSide === 1 || rawSide === 2 || rawSide === 3 ? rawSide : 0;
|
|
1687
|
+
const point = side === 1 ? { x: sheetLocation.x + sheetWidth, y: sheetLocation.y - distance } : side === 2 ? { x: sheetLocation.x + distance, y: sheetLocation.y } : side === 3 ? {
|
|
1688
|
+
x: sheetLocation.x + distance,
|
|
1689
|
+
y: sheetLocation.y - sheetHeight
|
|
1690
|
+
} : { x: sheetLocation.x, y: sheetLocation.y - distance };
|
|
1691
|
+
const points = side === 1 ? [
|
|
1692
|
+
{ x: point.x, y: point.y + 4 },
|
|
1693
|
+
{ x: point.x - 7, y: point.y },
|
|
1694
|
+
{ x: point.x, y: point.y - 4 }
|
|
1695
|
+
] : side === 2 ? [
|
|
1696
|
+
{ x: point.x - 4, y: point.y },
|
|
1697
|
+
{ x: point.x, y: point.y - 7 },
|
|
1698
|
+
{ x: point.x + 4, y: point.y }
|
|
1699
|
+
] : side === 3 ? [
|
|
1700
|
+
{ x: point.x - 4, y: point.y },
|
|
1701
|
+
{ x: point.x, y: point.y + 7 },
|
|
1702
|
+
{ x: point.x + 4, y: point.y }
|
|
1703
|
+
] : [
|
|
1704
|
+
{ x: point.x, y: point.y + 4 },
|
|
1705
|
+
{ x: point.x + 7, y: point.y },
|
|
1706
|
+
{ x: point.x, y: point.y - 4 }
|
|
1707
|
+
];
|
|
1708
|
+
const elements = [
|
|
1709
|
+
{
|
|
1710
|
+
type: "schematic_path",
|
|
1711
|
+
schematic_path_id: `schematic_sheet_entry_altium_${index}`,
|
|
1712
|
+
schematic_sheet_id: SCHEMATIC_SHEET_ID,
|
|
1713
|
+
points: points.map((entryPoint) => scalePoint(entryPoint, context.scale)),
|
|
1714
|
+
stroke_width: Math.max(scaleLength(1, context.scale), 0.05),
|
|
1715
|
+
stroke_color: "#840000",
|
|
1716
|
+
fill_color: "#ffffc2",
|
|
1717
|
+
is_filled: true,
|
|
1718
|
+
is_dashed: false
|
|
1719
|
+
}
|
|
1720
|
+
];
|
|
1721
|
+
const name = record.getDecoded("NAME");
|
|
1722
|
+
if (!name || options.includeText === false) return elements;
|
|
1723
|
+
const fontId = Math.max(Math.round(record.getNumber("TEXTFONTID") ?? 1), 1);
|
|
1724
|
+
const fontSize = Math.max(
|
|
1725
|
+
Number(context.sheetRecord?.getCaseInsensitive(`SIZE${fontId}`) ?? 9),
|
|
1726
|
+
1
|
|
1727
|
+
);
|
|
1728
|
+
const textLocation = side === 0 ? { x: point.x + 9, y: point.y } : side === 1 ? { x: point.x - 9, y: point.y } : side === 2 ? { x: point.x, y: point.y - 9 } : { x: point.x, y: point.y + 9 };
|
|
1729
|
+
const anchor = side === 0 ? "center_left" : side === 1 ? "center_right" : side === 2 ? "top_center" : "bottom_center";
|
|
1730
|
+
elements.push(
|
|
1731
|
+
createDirectText({
|
|
1732
|
+
id: `schematic_sheet_entry_text_altium_${index}`,
|
|
1733
|
+
text: name,
|
|
1734
|
+
location: textLocation,
|
|
1735
|
+
fontSize,
|
|
1736
|
+
color: "#840000",
|
|
1737
|
+
scale: context.scale,
|
|
1738
|
+
ccwRotationDegrees: 0,
|
|
1739
|
+
anchor
|
|
1740
|
+
})
|
|
1741
|
+
);
|
|
1742
|
+
return elements;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// lib/schematic/rendering/renderSheetSymbol.ts
|
|
1746
|
+
function renderSheetSymbol({
|
|
1747
|
+
context,
|
|
1748
|
+
index,
|
|
1749
|
+
record
|
|
1750
|
+
}) {
|
|
1751
|
+
const location = getLocation(record);
|
|
1752
|
+
if (!location) return [];
|
|
1753
|
+
const width = Math.max(
|
|
1754
|
+
getCoordinateOrFallback({ record, key: "XSIZE", fallback: 1 }),
|
|
1755
|
+
1
|
|
1756
|
+
);
|
|
1757
|
+
const height = Math.max(
|
|
1758
|
+
getCoordinateOrFallback({ record, key: "YSIZE", fallback: 1 }),
|
|
1759
|
+
1
|
|
1760
|
+
);
|
|
1761
|
+
return [
|
|
1762
|
+
{
|
|
1763
|
+
type: "schematic_rect",
|
|
1764
|
+
schematic_rect_id: `schematic_sheet_symbol_altium_${index}`,
|
|
1765
|
+
schematic_sheet_id: SCHEMATIC_SHEET_ID,
|
|
1766
|
+
center: scalePoint(
|
|
1767
|
+
{ x: location.x + width / 2, y: location.y - height / 2 },
|
|
1768
|
+
context.scale
|
|
1769
|
+
),
|
|
1770
|
+
width: scaleLength(width, context.scale),
|
|
1771
|
+
height: scaleLength(height, context.scale),
|
|
1772
|
+
rotation: 0,
|
|
1773
|
+
stroke_width: Math.max(scaleLength(1, context.scale), 0.05),
|
|
1774
|
+
color: "#840000",
|
|
1775
|
+
is_filled: true,
|
|
1776
|
+
fill_color: "#ffffc2",
|
|
1777
|
+
is_dashed: false
|
|
1778
|
+
}
|
|
1779
|
+
];
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1636
1782
|
// lib/schematic/rendering/convertSchematicRecord.ts
|
|
1637
1783
|
function convertSchematicRecord({
|
|
1638
1784
|
record,
|
|
@@ -1649,6 +1795,10 @@ function convertSchematicRecord({
|
|
|
1649
1795
|
if (record instanceof AltiumSchImageRecord) {
|
|
1650
1796
|
return renderSchematicImageRecord({ context, index, record });
|
|
1651
1797
|
}
|
|
1798
|
+
if (kind === "15") return renderSheetSymbol({ context, index, record });
|
|
1799
|
+
if (kind === "16") {
|
|
1800
|
+
return renderSheetEntry({ context, index, options, record });
|
|
1801
|
+
}
|
|
1652
1802
|
const primitive = renderPrimitiveRecord({
|
|
1653
1803
|
record,
|
|
1654
1804
|
index,
|
|
@@ -3100,7 +3250,7 @@ function convertOwnedComponentRecords({
|
|
|
3100
3250
|
{
|
|
3101
3251
|
index,
|
|
3102
3252
|
options: {
|
|
3103
|
-
|
|
3253
|
+
...context.options,
|
|
3104
3254
|
includeText: record instanceof AltiumSchPinRecord ? false : context.options.includeText
|
|
3105
3255
|
},
|
|
3106
3256
|
record
|
|
@@ -3621,7 +3771,13 @@ function getComponentIdentity({
|
|
|
3621
3771
|
ownedRecords
|
|
3622
3772
|
}, context) {
|
|
3623
3773
|
const designator = findOwnedDesignator(ownedRecords) ?? componentRecord.designator ?? `U${componentIndex}`;
|
|
3624
|
-
const
|
|
3774
|
+
const displayTextReference = findOwnedParameterText(ownedRecords, "Value")?.trim() || findOwnedParameterText(ownedRecords, "Comment")?.trim() || componentRecord.comment?.trim() || componentRecord.designItemId?.trim() || componentRecord.libraryReference?.trim() || "";
|
|
3775
|
+
const displayText = resolveSchematicText({
|
|
3776
|
+
document: context.document,
|
|
3777
|
+
options: context.options,
|
|
3778
|
+
record: componentRecord,
|
|
3779
|
+
reference: displayTextReference
|
|
3780
|
+
}).trim();
|
|
3625
3781
|
const libraryReference = componentRecord.libraryReference ?? componentRecord.designItemId ?? designator;
|
|
3626
3782
|
const manufacturerPartNumber = findOwnedParameterText(
|
|
3627
3783
|
ownedRecords,
|
|
@@ -4071,8 +4227,7 @@ function convertSemanticSchematic(document, options) {
|
|
|
4071
4227
|
// lib/schematic/document/convertSchematicSemantics.ts
|
|
4072
4228
|
function convertSchematicSemantics(context) {
|
|
4073
4229
|
const conversion = convertSemanticSchematic(context.document, {
|
|
4074
|
-
|
|
4075
|
-
includeText: context.options.includeText,
|
|
4230
|
+
...context.options,
|
|
4076
4231
|
scale: context.scale,
|
|
4077
4232
|
schematicSheetId: SCHEMATIC_SHEET_ID
|
|
4078
4233
|
});
|