altium-to-circuit-json 0.0.84 → 0.0.86

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,5 +1,5 @@
1
1
  import { LayerRef, SourceSimpleChip, SourcePort, AnyCircuitElement, SourceNet, SourceTrace } from 'circuit-json';
2
- import { AltiumPcbDocument, AltiumRecord, AltiumPadRecord, AltiumSchDoc, AltiumPrjPcb } from 'altiumts';
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
@@ -3305,12 +3305,19 @@ function convertOwnedComponentRecords({
3305
3305
  },
3306
3306
  renderingContext
3307
3307
  );
3308
- return elements.map(
3309
- (element) => element.type === "schematic_text" ? element : {
3308
+ return elements.map((element) => {
3309
+ const preparedElement = record instanceof AltiumSchPinRecord && element.type === "schematic_line" ? {
3310
3310
  ...element,
3311
+ stroke_width: Math.max(
3312
+ scaleLength(1, renderingContext.scale),
3313
+ 0.05
3314
+ )
3315
+ } : element;
3316
+ return preparedElement.type === "schematic_text" ? preparedElement : {
3317
+ ...preparedElement,
3311
3318
  schematic_component_id: schematicComponentId
3312
- }
3313
- );
3319
+ };
3320
+ });
3314
3321
  });
3315
3322
  }
3316
3323
 
@@ -6028,16 +6035,98 @@ function convertPcbMechanicalText({
6028
6035
  };
6029
6036
  }
6030
6037
 
6038
+ // lib/pcb/text/getProjectTextReplacements.ts
6039
+ function getProjectTextReplacements(project) {
6040
+ const replacements = [];
6041
+ for (const section of project.sections) {
6042
+ if (/^PARAMETER\d+$/iu.test(section.name)) {
6043
+ const name = section.entries.find(
6044
+ (entry) => entry.key.toUpperCase() === "NAME"
6045
+ )?.value;
6046
+ const text = section.entries.find(
6047
+ (entry) => entry.key.toUpperCase() === "VALUE"
6048
+ )?.value;
6049
+ if (name && text !== void 0 && text !== "*") {
6050
+ replacements.push({ name, text });
6051
+ }
6052
+ continue;
6053
+ }
6054
+ if (!/^PARAMETERS?$/iu.test(section.name)) continue;
6055
+ for (const entry of section.entries) {
6056
+ const separatorIndex = entry.value.indexOf("=");
6057
+ if (separatorIndex <= 0) continue;
6058
+ const name = entry.value.slice(0, separatorIndex).trim();
6059
+ const text = entry.value.slice(separatorIndex + 1);
6060
+ if (name && text !== "*") replacements.push({ name, text });
6061
+ }
6062
+ }
6063
+ return replacements;
6064
+ }
6065
+
6066
+ // lib/pcb/text/escapeRegularExpression.ts
6067
+ function escapeRegularExpression(text) {
6068
+ return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
6069
+ }
6070
+
6071
+ // lib/pcb/text/replaceMatchingSpecialString.ts
6072
+ function replaceMatchingSpecialString({
6073
+ isQuoted,
6074
+ replacement,
6075
+ text
6076
+ }) {
6077
+ const escapedName = escapeRegularExpression(replacement.name);
6078
+ const quotedExpression = new RegExp(`'\\.${escapedName}'`, "giu");
6079
+ if (isQuoted) {
6080
+ return text.replace(quotedExpression, () => replacement.text);
6081
+ }
6082
+ const exactReference = `.${replacement.name}`.toLowerCase();
6083
+ return text.split("'").map(
6084
+ (segment, index) => index % 2 === 0 && segment.toLowerCase() === exactReference ? replacement.text : segment
6085
+ ).join("'");
6086
+ }
6087
+
6088
+ // lib/pcb/text/resolvePcbProjectSpecialStrings.ts
6089
+ function resolvePcbProjectSpecialStrings({
6090
+ project,
6091
+ text
6092
+ }) {
6093
+ if (!project || !text.includes(".")) return text;
6094
+ let resolvedText = text;
6095
+ const replacements = getProjectTextReplacements(project).sort(
6096
+ (first, second) => second.name.length - first.name.length
6097
+ );
6098
+ for (const replacement of replacements) {
6099
+ resolvedText = replaceMatchingSpecialString({
6100
+ isQuoted: false,
6101
+ replacement,
6102
+ text: resolvedText
6103
+ });
6104
+ }
6105
+ for (const replacement of replacements) {
6106
+ resolvedText = replaceMatchingSpecialString({
6107
+ isQuoted: true,
6108
+ replacement,
6109
+ text: resolvedText
6110
+ });
6111
+ }
6112
+ return resolvedText;
6113
+ }
6114
+
6031
6115
  // lib/pcb/silkscreen/convertPcbSilkscreenText.ts
6032
6116
  function convertPcbSilkscreenText({
6033
- document,
6117
+ context,
6034
6118
  record,
6035
6119
  recordIndex
6036
6120
  }) {
6037
6121
  if (!record.position || !record.text) return void 0;
6122
+ const { document, options } = context;
6038
6123
  const component = document.getComponentForRecord(record);
6039
6124
  const specialString = record.text.trim().toLowerCase();
6040
- const text = specialString === ".designator" ? component?.designator : specialString === ".comment" ? component?.comment : record.text;
6125
+ const componentText = specialString === ".designator" ? component?.designator : specialString === ".comment" ? component?.comment : record.text;
6126
+ const text = resolvePcbProjectSpecialStrings({
6127
+ project: options.project,
6128
+ text: componentText ?? ""
6129
+ });
6041
6130
  if (!text) return void 0;
6042
6131
  return {
6043
6132
  type: "pcb_silkscreen_text",
@@ -6527,7 +6616,7 @@ function convertPcbRecords(context) {
6527
6616
  if (isOverlayLayer(record.layer)) {
6528
6617
  if (options.includeSilkscreen === false) continue;
6529
6618
  if (isHiddenPcbComponentText({ document, record })) continue;
6530
- const text = convertPcbSilkscreenText({ document, record, recordIndex });
6619
+ const text = convertPcbSilkscreenText({ context, record, recordIndex });
6531
6620
  if (text) elements.push(text);
6532
6621
  } else {
6533
6622
  const text = convertPcbCopperText({ layerMap, record, recordIndex });