altium-to-circuit-json 0.0.84 → 0.0.85
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 +2 -1
- package/dist/index.js +85 -3
- 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
|
|
2
|
+
import { AltiumPcbDocument, AltiumPrjPcb, AltiumRecord, AltiumPadRecord, AltiumSchDoc } from 'altiumts';
|
|
3
3
|
|
|
4
4
|
declare class PcbCopperLayerMap {
|
|
5
5
|
readonly layers: LayerRef[];
|
|
@@ -19,6 +19,7 @@ interface ConvertAltiumPcbDocOptions {
|
|
|
19
19
|
includeSilkscreen?: boolean;
|
|
20
20
|
includeTraces?: boolean;
|
|
21
21
|
includeVias?: boolean;
|
|
22
|
+
project?: AltiumPrjPcb;
|
|
22
23
|
}
|
|
23
24
|
interface PcbNetContext {
|
|
24
25
|
elements: Array<SourceNet | SourceTrace>;
|
package/dist/index.js
CHANGED
|
@@ -6028,16 +6028,98 @@ function convertPcbMechanicalText({
|
|
|
6028
6028
|
};
|
|
6029
6029
|
}
|
|
6030
6030
|
|
|
6031
|
+
// lib/pcb/text/getProjectTextReplacements.ts
|
|
6032
|
+
function getProjectTextReplacements(project) {
|
|
6033
|
+
const replacements = [];
|
|
6034
|
+
for (const section of project.sections) {
|
|
6035
|
+
if (/^PARAMETER\d+$/iu.test(section.name)) {
|
|
6036
|
+
const name = section.entries.find(
|
|
6037
|
+
(entry) => entry.key.toUpperCase() === "NAME"
|
|
6038
|
+
)?.value;
|
|
6039
|
+
const text = section.entries.find(
|
|
6040
|
+
(entry) => entry.key.toUpperCase() === "VALUE"
|
|
6041
|
+
)?.value;
|
|
6042
|
+
if (name && text !== void 0 && text !== "*") {
|
|
6043
|
+
replacements.push({ name, text });
|
|
6044
|
+
}
|
|
6045
|
+
continue;
|
|
6046
|
+
}
|
|
6047
|
+
if (!/^PARAMETERS?$/iu.test(section.name)) continue;
|
|
6048
|
+
for (const entry of section.entries) {
|
|
6049
|
+
const separatorIndex = entry.value.indexOf("=");
|
|
6050
|
+
if (separatorIndex <= 0) continue;
|
|
6051
|
+
const name = entry.value.slice(0, separatorIndex).trim();
|
|
6052
|
+
const text = entry.value.slice(separatorIndex + 1);
|
|
6053
|
+
if (name && text !== "*") replacements.push({ name, text });
|
|
6054
|
+
}
|
|
6055
|
+
}
|
|
6056
|
+
return replacements;
|
|
6057
|
+
}
|
|
6058
|
+
|
|
6059
|
+
// lib/pcb/text/escapeRegularExpression.ts
|
|
6060
|
+
function escapeRegularExpression(text) {
|
|
6061
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
// lib/pcb/text/replaceMatchingSpecialString.ts
|
|
6065
|
+
function replaceMatchingSpecialString({
|
|
6066
|
+
isQuoted,
|
|
6067
|
+
replacement,
|
|
6068
|
+
text
|
|
6069
|
+
}) {
|
|
6070
|
+
const escapedName = escapeRegularExpression(replacement.name);
|
|
6071
|
+
const quotedExpression = new RegExp(`'\\.${escapedName}'`, "giu");
|
|
6072
|
+
if (isQuoted) {
|
|
6073
|
+
return text.replace(quotedExpression, () => replacement.text);
|
|
6074
|
+
}
|
|
6075
|
+
const exactReference = `.${replacement.name}`.toLowerCase();
|
|
6076
|
+
return text.split("'").map(
|
|
6077
|
+
(segment, index) => index % 2 === 0 && segment.toLowerCase() === exactReference ? replacement.text : segment
|
|
6078
|
+
).join("'");
|
|
6079
|
+
}
|
|
6080
|
+
|
|
6081
|
+
// lib/pcb/text/resolvePcbProjectSpecialStrings.ts
|
|
6082
|
+
function resolvePcbProjectSpecialStrings({
|
|
6083
|
+
project,
|
|
6084
|
+
text
|
|
6085
|
+
}) {
|
|
6086
|
+
if (!project || !text.includes(".")) return text;
|
|
6087
|
+
let resolvedText = text;
|
|
6088
|
+
const replacements = getProjectTextReplacements(project).sort(
|
|
6089
|
+
(first, second) => second.name.length - first.name.length
|
|
6090
|
+
);
|
|
6091
|
+
for (const replacement of replacements) {
|
|
6092
|
+
resolvedText = replaceMatchingSpecialString({
|
|
6093
|
+
isQuoted: false,
|
|
6094
|
+
replacement,
|
|
6095
|
+
text: resolvedText
|
|
6096
|
+
});
|
|
6097
|
+
}
|
|
6098
|
+
for (const replacement of replacements) {
|
|
6099
|
+
resolvedText = replaceMatchingSpecialString({
|
|
6100
|
+
isQuoted: true,
|
|
6101
|
+
replacement,
|
|
6102
|
+
text: resolvedText
|
|
6103
|
+
});
|
|
6104
|
+
}
|
|
6105
|
+
return resolvedText;
|
|
6106
|
+
}
|
|
6107
|
+
|
|
6031
6108
|
// lib/pcb/silkscreen/convertPcbSilkscreenText.ts
|
|
6032
6109
|
function convertPcbSilkscreenText({
|
|
6033
|
-
|
|
6110
|
+
context,
|
|
6034
6111
|
record,
|
|
6035
6112
|
recordIndex
|
|
6036
6113
|
}) {
|
|
6037
6114
|
if (!record.position || !record.text) return void 0;
|
|
6115
|
+
const { document, options } = context;
|
|
6038
6116
|
const component = document.getComponentForRecord(record);
|
|
6039
6117
|
const specialString = record.text.trim().toLowerCase();
|
|
6040
|
-
const
|
|
6118
|
+
const componentText = specialString === ".designator" ? component?.designator : specialString === ".comment" ? component?.comment : record.text;
|
|
6119
|
+
const text = resolvePcbProjectSpecialStrings({
|
|
6120
|
+
project: options.project,
|
|
6121
|
+
text: componentText ?? ""
|
|
6122
|
+
});
|
|
6041
6123
|
if (!text) return void 0;
|
|
6042
6124
|
return {
|
|
6043
6125
|
type: "pcb_silkscreen_text",
|
|
@@ -6527,7 +6609,7 @@ function convertPcbRecords(context) {
|
|
|
6527
6609
|
if (isOverlayLayer(record.layer)) {
|
|
6528
6610
|
if (options.includeSilkscreen === false) continue;
|
|
6529
6611
|
if (isHiddenPcbComponentText({ document, record })) continue;
|
|
6530
|
-
const text = convertPcbSilkscreenText({
|
|
6612
|
+
const text = convertPcbSilkscreenText({ context, record, recordIndex });
|
|
6531
6613
|
if (text) elements.push(text);
|
|
6532
6614
|
} else {
|
|
6533
6615
|
const text = convertPcbCopperText({ layerMap, record, recordIndex });
|