@tscircuit/core 0.0.2147 → 0.0.2149

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.
Files changed (2) hide show
  1. package/dist/index.js +105 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6553,6 +6553,66 @@ var getRouteForPcbPath = ({
6553
6553
  return route;
6554
6554
  };
6555
6555
 
6556
+ // lib/components/primitive-components/Trace/insert-pcb-path-via-policy-errors.ts
6557
+ var insertPcbPathViaPolicyErrors = ({
6558
+ trace,
6559
+ pcbTrace,
6560
+ path,
6561
+ ports,
6562
+ pathIndex
6563
+ }) => {
6564
+ const allowBlindAndBuriedVias = trace._getBoard()?.getInheritedProperty("allowBlindAndBuriedVias");
6565
+ if (allowBlindAndBuriedVias) {
6566
+ return;
6567
+ }
6568
+ const { db: db2 } = trace.root;
6569
+ const connection = db2.source_trace.get(trace.source_trace_id)?.display_name;
6570
+ const traceDescription = [trace._parsedProps.name ? trace.getDisplayName() : void 0, connection].filter(Boolean).join(", ") || "unnamed trace";
6571
+ const pathName = pathIndex === void 0 ? "pcbPath" : `pcbPaths[${pathIndex}]`;
6572
+ const viaPathEntryIndices = [];
6573
+ for (const [pathEntryIndex, point6] of path.entries()) {
6574
+ if (typeof point6 !== "string" && point6.via) {
6575
+ viaPathEntryIndices.push(pathEntryIndex);
6576
+ }
6577
+ }
6578
+ const pcbVias = db2.pcb_via.list({ pcb_trace_id: pcbTrace.pcb_trace_id });
6579
+ const viaDescriptions = [];
6580
+ const viaKinds = /* @__PURE__ */ new Set();
6581
+ let firstDisallowedVia;
6582
+ for (const [viaIndex, via] of pcbVias.entries()) {
6583
+ const reachesTop = via.layers.includes("top");
6584
+ const reachesBottom = via.layers.includes("bottom");
6585
+ if (reachesTop && reachesBottom) {
6586
+ continue;
6587
+ }
6588
+ const viaKind = reachesTop || reachesBottom ? "blind" : "buried";
6589
+ viaKinds.add(viaKind);
6590
+ const pathEntryIndex = viaPathEntryIndices[viaIndex];
6591
+ const pathEntry = `${pathName}[${pathEntryIndex}]`;
6592
+ const boardX = Number(via.x.toFixed(4));
6593
+ const boardY = Number(via.y.toFixed(4));
6594
+ firstDisallowedVia ??= via;
6595
+ viaDescriptions.push(
6596
+ `${pathEntry}: ${viaKind} via (fromLayer: "${via.from_layer}", toLayer: "${via.to_layer}") spanning [${via.layers.join(", ")}] at board (${boardX}, ${boardY}) mm`
6597
+ );
6598
+ }
6599
+ if (!firstDisallowedVia) {
6600
+ return;
6601
+ }
6602
+ const viaKindDescription = [...viaKinds].sort().join(" and ");
6603
+ db2.pcb_trace_error.insert({
6604
+ error_type: "pcb_trace_error",
6605
+ source_trace_id: trace.source_trace_id,
6606
+ pcb_trace_id: pcbTrace.pcb_trace_id,
6607
+ pcb_component_ids: [],
6608
+ pcb_port_ids: ports.map((port) => port.pcb_port_id).filter(Boolean),
6609
+ subcircuit_id: pcbTrace.subcircuit_id,
6610
+ center: { x: firstDisallowedVia.x, y: firstDisallowedVia.y },
6611
+ is_fatal: false,
6612
+ message: `${viaKindDescription} vias aren't allowed by allowBlindAndBuriedVias settings in ${pathName} (${traceDescription}): ${viaDescriptions.length} disallowed via${viaDescriptions.length === 1 ? "" : "s"}. Use top-to-bottom through vias (fromLayer: "top", toLayer: "bottom", or the reverse) and adjust the adjoining wire layers to match, or set allowBlindAndBuriedVias={true} on <board> if fabrication supports blind/buried vias. Saved copper has been preserved. Affected indices (zero-based): ${viaDescriptions.join("; ")}.`
6613
+ });
6614
+ };
6615
+
6556
6616
  // lib/components/primitive-components/Trace/render-pcb-paths.ts
6557
6617
  var renderPcbPaths = ({
6558
6618
  trace,
@@ -6617,6 +6677,7 @@ var renderPcbPaths = ({
6617
6677
  }
6618
6678
  insertPcbPathViaContactErrors({ trace, pcbTrace, ports, pathIndex });
6619
6679
  trace._insertErrorIfTraceIsOutsideBoard(route, ports);
6680
+ insertPcbPathViaPolicyErrors({ trace, pcbTrace, path, ports, pathIndex });
6620
6681
  }
6621
6682
  trace._portsRoutedOnPcb = ports;
6622
6683
  };
@@ -7007,6 +7068,12 @@ function Trace_doInitialPcbManualTraceRender(trace) {
7007
7068
  });
7008
7069
  }
7009
7070
  }
7071
+ insertPcbPathViaPolicyErrors({
7072
+ trace,
7073
+ pcbTrace: pcb_trace,
7074
+ path: props.pcbPath,
7075
+ ports
7076
+ });
7010
7077
  trace._portsRoutedOnPcb = ports;
7011
7078
  trace.pcb_trace_id = pcb_trace.pcb_trace_id;
7012
7079
  insertPcbPathViaContactErrors({ trace, pcbTrace: pcb_trace, ports });
@@ -118369,14 +118436,42 @@ function getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps) {
118369
118436
  ...phaseProps.connections ?? []
118370
118437
  ];
118371
118438
  }
118372
- function traceHasEndpointMatchingConnectionSelector(trace, connectionSelectorEndpointKey) {
118439
+ function traceHasEndpointMatchingConnectionSelector(trace, connectionSelector) {
118440
+ const connectionSelectorEndpointKey = convertPortSelectorToEndpointKey(connectionSelector);
118373
118441
  if (trace.getTracePortPathSelectors().some(
118374
118442
  (selector) => convertPortSelectorToEndpointKey(selector) === connectionSelectorEndpointKey
118375
118443
  ))
118376
118444
  return true;
118377
- const port = trace.getSubcircuit().selectOne(connectionSelectorEndpointKey, { type: "port" });
118445
+ const port = trace.getSubcircuit().selectOne(connectionSelector, { type: "port" });
118378
118446
  return port !== null && (trace._findConnectedPorts().ports?.includes(port) ?? false);
118379
118447
  }
118448
+ function resolvePhaseConnectionTraces(group, traces, phaseProps) {
118449
+ const resolvedTraces = /* @__PURE__ */ new Set();
118450
+ const phaseName = phaseProps.name ?? "unnamed phase";
118451
+ for (const rawSelector of getConnectionSelectorsFromAutoroutingPhaseProps(
118452
+ phaseProps
118453
+ )) {
118454
+ const selector = rawSelector.trim();
118455
+ const explicitlySelectsTrace = selector.startsWith("trace.");
118456
+ const namedTraces = explicitlySelectsTrace ? group.selectAll(selector).filter((trace) => traces.includes(trace)) : traces.filter((trace) => trace.name === selector);
118457
+ const endpointTraces = explicitlySelectsTrace ? [] : traces.filter(
118458
+ (trace) => traceHasEndpointMatchingConnectionSelector(trace, selector)
118459
+ );
118460
+ if (namedTraces.length > 1 || namedTraces.length > 0 && endpointTraces.length > 0) {
118461
+ throw new Error(
118462
+ `Autorouting phase "${phaseName}": connection "${rawSelector}" is ambiguous. Use a unique trace name qualified as "trace.DDR_D0" or a port such as ".U1 > .A1".`
118463
+ );
118464
+ }
118465
+ const matches = namedTraces.length > 0 ? namedTraces : endpointTraces;
118466
+ if (matches.length === 0) {
118467
+ throw new Error(
118468
+ `Autorouting phase "${phaseName}": connection "${rawSelector}" matched no trace or endpoint. Use a trace name such as "DDR_D0" or a port such as ".U1 > .A1".`
118469
+ );
118470
+ }
118471
+ for (const trace of matches) resolvedTraces.add(trace);
118472
+ }
118473
+ return resolvedTraces;
118474
+ }
118380
118475
  function getAutoroutersByPhaseIndex(group) {
118381
118476
  const autoroutingPhases = group.selectAll(
118382
118477
  "autoroutingphase"
@@ -118468,6 +118563,12 @@ function Group_getRoutingPhasePlans(group) {
118468
118563
  const plansByPhaseIndex = /* @__PURE__ */ new Map();
118469
118564
  const autoroutersByPhaseIndex = getAutoroutersByPhaseIndex(group);
118470
118565
  const phasePropsByPhaseIndex = getAutoroutingPhasePropsByPhaseIndex(group);
118566
+ const selectedTracesByPhaseIndex = new Map(
118567
+ Array.from(phasePropsByPhaseIndex, ([phaseIndex, phaseProps]) => [
118568
+ phaseIndex,
118569
+ resolvePhaseConnectionTraces(group, traces, phaseProps)
118570
+ ])
118571
+ );
118471
118572
  const groupFanoutProps = group._parsedProps;
118472
118573
  const routeRemaining = group.getInheritedProperty("routeRemaining") !== false;
118473
118574
  const defaultPhaseProps = phasePropsByPhaseIndex.get(null);
@@ -118504,15 +118605,10 @@ function Group_getRoutingPhasePlans(group) {
118504
118605
  const connectionSelectors = getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps);
118505
118606
  if (connectionSelectors.length > 0) {
118506
118607
  const plan = getOrCreateRoutingPhasePlan(plansByPhaseIndex, phaseIndex);
118507
- const connectionSelectorEndpointKeys = connectionSelectors.map(
118508
- convertPortSelectorToEndpointKey
118509
- );
118510
118608
  plan.connectionSelectors = connectionSelectors;
118511
118609
  for (const trace of traces) {
118512
118610
  if (breakoutByTrace.has(trace)) continue;
118513
- if (connectionSelectorEndpointKeys.some(
118514
- (endpointKey) => traceHasEndpointMatchingConnectionSelector(trace, endpointKey)
118515
- )) {
118611
+ if (selectedTracesByPhaseIndex.get(phaseIndex).has(trace)) {
118516
118612
  if (!phaseProps.reroute) {
118517
118613
  for (const existingPlan of plansByPhaseIndex.values()) {
118518
118614
  if (existingPlan === plan) continue;
@@ -118692,7 +118788,7 @@ var RoutingPhasePreparationError = class extends Error {
118692
118788
  var package_default = {
118693
118789
  name: "@tscircuit/core",
118694
118790
  type: "module",
118695
- version: "0.0.2146",
118791
+ version: "0.0.2148",
118696
118792
  types: "dist/index.d.ts",
118697
118793
  main: "dist/index.js",
118698
118794
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.2147",
4
+ "version": "0.0.2149",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",