@tscircuit/core 0.0.1161 → 0.0.1163

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 (3) hide show
  1. package/dist/index.d.ts +61 -52
  2. package/dist/index.js +352 -145
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as circuit_json from 'circuit-json';
2
2
  import { PcbTraceError, PcbPlacementError, PcbManualEditConflictWarning, PcbViaClearanceError, LayerRef, AnyCircuitElement, Size, PcbTraceRoutePoint, AnySourceComponent, PcbTrace as PcbTrace$1, PcbVia, SchematicPort, SchematicComponent, RouteHintPoint, CircuitJson } from 'circuit-json';
3
3
  import * as _tscircuit_props from '@tscircuit/props';
4
- import { PlatformConfig, traceProps, subcircuitGroupProps, AutorouterConfig, PcbSx, SupplierPartNumbers, CadModelProp, SchematicPortArrangement, groupProps, boardProps, subcircuitProps, subpanelProps, capacitorProps, chipProps, pinoutProps, diodeProps, fuseProps, jumperProps, interconnectProps, solderjumperProps, ledProps, powerSourceProps, voltageSourceProps, currentSourceProps, resistorProps, constraintProps, fabricationNoteRectProps, fabricationNotePathProps, fabricationNoteTextProps, fabricationNoteDimensionProps, pcbNoteLineProps, pcbNoteRectProps, pcbNoteTextProps, pcbNotePathProps, pcbNoteDimensionProps, footprintProps, breakoutProps, breakoutPointProps, holeProps, pcbKeepoutProps, netLabelProps, cadmodelProps, cadassemblyProps, platedHoleProps, courtyardCircleProps, courtyardOutlineProps, courtyardRectProps, silkscreenCircleProps, silkscreenPathProps, silkscreenRectProps, silkscreenTextProps, silkscreenLineProps, smtPadProps, fiducialProps, traceHintProps, viaProps, copperPourProps, copperTextProps, cutoutProps, batteryProps, pinHeaderProps, resonatorProps, inductorProps, potentiometerProps, pushButtonProps, crystalProps, transistorProps, mosfetProps, opampProps, OpAmpPinLabels, switchProps, SwitchProps, testpointProps, schematicTextProps, schematicLineProps, schematicRectProps, schematicArcProps, schematicCircleProps, schematicPathProps, schematicBoxProps, schematicTableProps, schematicRowProps, schematicCellProps, symbolProps, analogSimulationProps, voltageProbeProps, CapacitorProps, ChipProps, DiodeProps, ResistorProps, ManualEditEvent, ManualEditsFile, ChipConnections, manual_edits_file } from '@tscircuit/props';
4
+ import { PlatformConfig, traceProps, netProps, subcircuitGroupProps, AutorouterConfig, PcbSx, SupplierPartNumbers, CadModelProp, SchematicPortArrangement, groupProps, boardProps, subcircuitProps, subpanelProps, capacitorProps, chipProps, pinoutProps, diodeProps, fuseProps, jumperProps, interconnectProps, solderjumperProps, ledProps, powerSourceProps, voltageSourceProps, currentSourceProps, resistorProps, constraintProps, fabricationNoteRectProps, fabricationNotePathProps, fabricationNoteTextProps, fabricationNoteDimensionProps, pcbNoteLineProps, pcbNoteRectProps, pcbNoteTextProps, pcbNotePathProps, pcbNoteDimensionProps, footprintProps, breakoutProps, breakoutPointProps, holeProps, pcbKeepoutProps, netLabelProps, cadmodelProps, cadassemblyProps, platedHoleProps, courtyardCircleProps, courtyardOutlineProps, courtyardRectProps, silkscreenCircleProps, silkscreenPathProps, silkscreenRectProps, silkscreenTextProps, silkscreenLineProps, smtPadProps, fiducialProps, traceHintProps, viaProps, copperPourProps, copperTextProps, cutoutProps, batteryProps, pinHeaderProps, resonatorProps, inductorProps, potentiometerProps, pushButtonProps, crystalProps, transistorProps, mosfetProps, opampProps, OpAmpPinLabels, switchProps, SwitchProps, testpointProps, schematicTextProps, schematicLineProps, schematicRectProps, schematicArcProps, schematicCircleProps, schematicPathProps, schematicBoxProps, schematicTableProps, schematicRowProps, schematicCellProps, symbolProps, analogSimulationProps, voltageProbeProps, CapacitorProps, ChipProps, DiodeProps, ResistorProps, ManualEditEvent, ManualEditsFile, ChipConnections, manual_edits_file } from '@tscircuit/props';
5
5
  export { kicadFootprintStrings } from '@tscircuit/props';
6
6
  import * as react from 'react';
7
7
  import react__default, { ReactElement, DetailedHTMLProps, SVGProps } from 'react';
@@ -397,57 +397,6 @@ interface IGroup extends PrimitiveComponent {
397
397
  }): void;
398
398
  }
399
399
 
400
- declare const netProps: z.ZodObject<{
401
- name: z.ZodEffects<z.ZodString, string, string>;
402
- }, "strip", z.ZodTypeAny, {
403
- name: string;
404
- }, {
405
- name: string;
406
- }>;
407
- declare class Net extends PrimitiveComponent<typeof netProps> {
408
- source_net_id?: string;
409
- subcircuit_connectivity_map_key: string | null;
410
- get config(): {
411
- componentName: string;
412
- zodProps: z.ZodObject<{
413
- name: z.ZodEffects<z.ZodString, string, string>;
414
- }, "strip", z.ZodTypeAny, {
415
- name: string;
416
- }, {
417
- name: string;
418
- }>;
419
- };
420
- getPortSelector(): string;
421
- doInitialSourceRender(): void;
422
- doInitialSourceParentAttachment(): void;
423
- /**
424
- * Get all ports connected to this net.
425
- *
426
- * TODO currently we're not checking for indirect connections (traces that are
427
- * connected to other traces that are in turn connected to the net)
428
- */
429
- getAllConnectedPorts(): Port[];
430
- /**
431
- * Get all traces that are directly connected to this net, i.e. they list
432
- * this net in their path, from, or to props
433
- */
434
- _getAllDirectlyConnectedTraces(): Trace[];
435
- /**
436
- * Add PCB Traces to connect net islands together. A net island is a set of
437
- * ports that are connected to each other. If a there are multiple net islands
438
- * that means that the net is not fully connected and we need to add traces
439
- * such that the nets are fully connected
440
- *
441
- * Sometimes this phase doesn't find any net islands if the autorouter did
442
- * a good job and connected the islands. In some sense this is a "backup"
443
- * routing phase for autorouters that don't care about connecting nets.
444
- *
445
- * This should only run if the autorouter is sequential-trace
446
- */
447
- doInitialPcbRouteNetIslands(): void;
448
- renderError(message: Parameters<typeof PrimitiveComponent.prototype.renderError>[0]): void;
449
- }
450
-
451
400
  interface TraceI extends PrimitiveComponent<typeof traceProps> {
452
401
  source_trace_id: string | null;
453
402
  subcircuit_connectivity_map_key: string | null;
@@ -1049,8 +998,68 @@ declare class Trace extends PrimitiveComponent<typeof traceProps> implements Tra
1049
998
  doInitialSchematicTraceRender(): void;
1050
999
  }
1051
1000
 
1001
+ declare class Net extends PrimitiveComponent<typeof netProps> {
1002
+ source_net_id?: string;
1003
+ subcircuit_connectivity_map_key: string | null;
1004
+ get config(): {
1005
+ componentName: string;
1006
+ zodProps: zod.ZodObject<{
1007
+ name: zod.ZodString;
1008
+ connectsTo: zod.ZodOptional<zod.ZodUnion<[zod.ZodString, zod.ZodArray<zod.ZodString, "many">]>>;
1009
+ routingPhaseIndex: zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>;
1010
+ highlightColor: zod.ZodOptional<zod.ZodString>;
1011
+ isPowerNet: zod.ZodOptional<zod.ZodBoolean>;
1012
+ isGroundNet: zod.ZodOptional<zod.ZodBoolean>;
1013
+ }, "strip", zod.ZodTypeAny, {
1014
+ name: string;
1015
+ highlightColor?: string | undefined;
1016
+ connectsTo?: string | string[] | undefined;
1017
+ routingPhaseIndex?: number | null | undefined;
1018
+ isPowerNet?: boolean | undefined;
1019
+ isGroundNet?: boolean | undefined;
1020
+ }, {
1021
+ name: string;
1022
+ highlightColor?: string | undefined;
1023
+ connectsTo?: string | string[] | undefined;
1024
+ routingPhaseIndex?: number | null | undefined;
1025
+ isPowerNet?: boolean | undefined;
1026
+ isGroundNet?: boolean | undefined;
1027
+ }>;
1028
+ };
1029
+ getPortSelector(): string;
1030
+ doInitialSourceRender(): void;
1031
+ doInitialSourceParentAttachment(): void;
1032
+ /**
1033
+ * Get all ports connected to this net.
1034
+ *
1035
+ * TODO currently we're not checking for indirect connections (traces that are
1036
+ * connected to other traces that are in turn connected to the net)
1037
+ */
1038
+ getAllConnectedPorts(): Port[];
1039
+ /**
1040
+ * Get all traces that are directly connected to this net, i.e. they list
1041
+ * this net in their path, from, or to props
1042
+ */
1043
+ _getAllDirectlyConnectedTraces(): Trace[];
1044
+ /**
1045
+ * Add PCB Traces to connect net islands together. A net island is a set of
1046
+ * ports that are connected to each other. If a there are multiple net islands
1047
+ * that means that the net is not fully connected and we need to add traces
1048
+ * such that the nets are fully connected
1049
+ *
1050
+ * Sometimes this phase doesn't find any net islands if the autorouter did
1051
+ * a good job and connected the islands. In some sense this is a "backup"
1052
+ * routing phase for autorouters that don't care about connecting nets.
1053
+ *
1054
+ * This should only run if the autorouter is sequential-trace
1055
+ */
1056
+ doInitialPcbRouteNetIslands(): void;
1057
+ renderError(message: Parameters<typeof PrimitiveComponent.prototype.renderError>[0]): void;
1058
+ }
1059
+
1052
1060
  interface RoutingPhasePlan {
1053
1061
  routingPhaseIndex: number | null;
1062
+ nets: Net[];
1054
1063
  traces: Trace[];
1055
1064
  }
1056
1065
 
package/dist/index.js CHANGED
@@ -288,6 +288,9 @@ var mergeRoutes = (routes) => {
288
288
  return merged;
289
289
  };
290
290
 
291
+ // lib/components/primitive-components/Net.ts
292
+ import { netProps } from "@tscircuit/props";
293
+
291
294
  // lib/components/base-components/PrimitiveComponent/PrimitiveComponent.ts
292
295
  import { selectAll, selectOne } from "css-select";
293
296
  import "debug";
@@ -2113,9 +2116,6 @@ var PrimitiveComponent2 = class extends Renderable {
2113
2116
  }
2114
2117
  };
2115
2118
 
2116
- // lib/components/primitive-components/Net.ts
2117
- import { z as z2 } from "zod";
2118
-
2119
2119
  // lib/utils/pairs.ts
2120
2120
  function pairs(arr) {
2121
2121
  const result = [];
@@ -2127,14 +2127,6 @@ function pairs(arr) {
2127
2127
 
2128
2128
  // lib/components/primitive-components/Net.ts
2129
2129
  import { autoroute } from "@tscircuit/infgrid-ijump-astar";
2130
- var netProps = z2.object({
2131
- name: z2.string().refine(
2132
- (val) => !/[+-]/.test(val),
2133
- (val) => ({
2134
- message: `Net names cannot contain "+" or "-" (component "Net" received "${val}"). Try using underscores instead, e.g. VCC_P`
2135
- })
2136
- )
2137
- });
2138
2130
  var Net = class extends PrimitiveComponent2 {
2139
2131
  source_net_id;
2140
2132
  subcircuit_connectivity_map_key = null;
@@ -2961,8 +2953,7 @@ var getObstaclesFromCircuitJson = (soup, connMap) => {
2961
2953
  x: element.x,
2962
2954
  y: element.y
2963
2955
  },
2964
- connectedTo: [],
2965
- // TODO we can associate source_ports with this via
2956
+ connectedTo: withNetId([element.pcb_via_id]),
2966
2957
  width: element.outer_diameter,
2967
2958
  height: element.outer_diameter,
2968
2959
  netIsAssignable: netIsAssignable || void 0
@@ -4588,7 +4579,7 @@ function Trace_doInitialPcbManualTraceRender(trace) {
4588
4579
  for (const pt of pcbPath) {
4589
4580
  let coordinates;
4590
4581
  let isGlobalPosition = false;
4591
- const isViaPoint = typeof pt !== "string" && pt.via;
4582
+ const isViaPoint2 = typeof pt !== "string" && pt.via;
4592
4583
  let viaFromLayer;
4593
4584
  let viaToLayer;
4594
4585
  if (typeof pt === "string") {
@@ -4630,7 +4621,7 @@ function Trace_doInitialPcbManualTraceRender(trace) {
4630
4621
  }
4631
4622
  }
4632
4623
  const finalCoordinates = isGlobalPosition ? coordinates : applyToPoint2(transform, coordinates);
4633
- if (isViaPoint) {
4624
+ if (isViaPoint2) {
4634
4625
  route.push({
4635
4626
  route_type: "via",
4636
4627
  x: finalCoordinates.x,
@@ -5124,7 +5115,7 @@ var extendCatalogue = (objects) => {
5124
5115
  import { identity as identity3 } from "transformation-matrix";
5125
5116
 
5126
5117
  // lib/components/primitive-components/ErrorPlaceholder.ts
5127
- import { z as z4 } from "zod";
5118
+ import { z as z3 } from "zod";
5128
5119
  var ErrorPlaceholderComponent = class extends PrimitiveComponent2 {
5129
5120
  constructor(props, error) {
5130
5121
  super(props);
@@ -5196,7 +5187,7 @@ var ErrorPlaceholderComponent = class extends PrimitiveComponent2 {
5196
5187
  get config() {
5197
5188
  return {
5198
5189
  componentName: "ErrorPlaceholder",
5199
- zodProps: z4.object({}).passthrough()
5190
+ zodProps: z3.object({}).passthrough()
5200
5191
  };
5201
5192
  }
5202
5193
  doInitialSourceRender() {
@@ -6678,14 +6669,14 @@ var PcbNoteText = class extends PrimitiveComponent2 {
6678
6669
  };
6679
6670
 
6680
6671
  // lib/components/primitive-components/PcbTrace.ts
6681
- import { z as z6 } from "zod";
6672
+ import { z as z5 } from "zod";
6682
6673
  import { pcb_trace_route_point } from "circuit-json";
6683
6674
  import { applyToPoint as applyToPoint11 } from "transformation-matrix";
6684
- var pcbTraceProps = z6.object({
6685
- route: z6.array(pcb_trace_route_point),
6675
+ var pcbTraceProps = z5.object({
6676
+ route: z5.array(pcb_trace_route_point),
6686
6677
  // If this primitive PcbTrace needs to be associated with a source_trace_id
6687
6678
  // it can be added as a prop here. For footprints, it's often not needed.
6688
- source_trace_id: z6.string().optional()
6679
+ source_trace_id: z5.string().optional()
6689
6680
  });
6690
6681
  var PcbTrace = class extends PrimitiveComponent2 {
6691
6682
  pcb_trace_id = null;
@@ -8512,7 +8503,7 @@ var SCHEMATIC_COMPONENT_OUTLINE_STROKE_WIDTH = 0.12;
8512
8503
  // lib/components/primitive-components/Port/Port.ts
8513
8504
  import "schematic-symbols";
8514
8505
  import { applyToPoint as applyToPoint16, compose as compose4, translate as translate3 } from "transformation-matrix";
8515
- import { z as z7 } from "zod";
8506
+ import { z as z6 } from "zod";
8516
8507
 
8517
8508
  // lib/components/primitive-components/Port/getCenterOfPcbPrimitives.ts
8518
8509
  var getCenterOfPcbPrimitives = (pcbPrimitives) => {
@@ -8596,17 +8587,17 @@ var applyPinAttributesToSourcePort = (sourcePortProps, attributes) => {
8596
8587
  };
8597
8588
 
8598
8589
  // lib/components/primitive-components/Port/Port.ts
8599
- var portProps = z7.object({
8600
- name: z7.string().optional(),
8601
- pinNumber: z7.number().optional(),
8602
- schStemLength: z7.number().optional(),
8603
- aliases: z7.array(z7.string()).optional(),
8604
- layer: z7.string().optional(),
8605
- layers: z7.array(z7.string()).optional(),
8606
- schX: z7.number().optional(),
8607
- schY: z7.number().optional(),
8608
- direction: z7.enum(["up", "down", "left", "right"]).optional(),
8609
- connectsTo: z7.union([z7.string(), z7.array(z7.string())]).optional()
8590
+ var portProps = z6.object({
8591
+ name: z6.string().optional(),
8592
+ pinNumber: z6.number().optional(),
8593
+ schStemLength: z6.number().optional(),
8594
+ aliases: z6.array(z6.string()).optional(),
8595
+ layer: z6.string().optional(),
8596
+ layers: z6.array(z6.string()).optional(),
8597
+ schX: z6.number().optional(),
8598
+ schY: z6.number().optional(),
8599
+ direction: z6.enum(["up", "down", "left", "right"]).optional(),
8600
+ connectsTo: z6.union([z6.string(), z6.array(z6.string())]).optional()
8610
8601
  });
8611
8602
  var Port = class extends PrimitiveComponent2 {
8612
8603
  source_port_id = null;
@@ -9573,7 +9564,7 @@ import {
9573
9564
  } from "react";
9574
9565
  import { symbols as symbols2 } from "schematic-symbols";
9575
9566
  import { decomposeTSR as decomposeTSR8 } from "transformation-matrix";
9576
- import { z as z9 } from "zod";
9567
+ import { z as z8 } from "zod";
9577
9568
 
9578
9569
  // lib/components/primitive-components/CadAssembly.ts
9579
9570
  import { cadassemblyProps } from "@tscircuit/props";
@@ -9589,7 +9580,7 @@ var CadAssembly = class extends PrimitiveComponent2 {
9589
9580
 
9590
9581
  // lib/components/primitive-components/CadModel.ts
9591
9582
  import { cadmodelProps, point3 } from "@tscircuit/props";
9592
- import { z as z8 } from "zod";
9583
+ import { z as z7 } from "zod";
9593
9584
  import { distance as distance7 } from "circuit-json";
9594
9585
  import { decomposeTSR as decomposeTSR7 } from "transformation-matrix";
9595
9586
 
@@ -9631,8 +9622,8 @@ var constructAssetUrl = (targetUrl, baseUrl) => {
9631
9622
  };
9632
9623
 
9633
9624
  // lib/components/primitive-components/CadModel.ts
9634
- var rotation = z8.union([z8.number(), z8.string()]);
9635
- var rotation3 = z8.object({ x: rotation, y: rotation, z: rotation });
9625
+ var rotation = z7.union([z7.number(), z7.string()]);
9626
+ var rotation3 = z7.object({ x: rotation, y: rotation, z: rotation });
9636
9627
  var CadModel = class extends PrimitiveComponent2 {
9637
9628
  get config() {
9638
9629
  return {
@@ -10559,7 +10550,7 @@ function getLogicalPortsFromPortHintGroups(portHintGroups, opts) {
10559
10550
 
10560
10551
  // lib/components/base-components/NormalComponent/NormalComponent.ts
10561
10552
  var debug3 = Debug5("tscircuit:core");
10562
- var rotation32 = z9.object({
10553
+ var rotation32 = z8.object({
10563
10554
  x: rotation2,
10564
10555
  y: rotation2,
10565
10556
  z: rotation2
@@ -13519,8 +13510,18 @@ var getSimpleRouteJsonFromCircuitJson = ({
13519
13510
  const connectionsFromNets = [];
13520
13511
  for (const net of source_nets) {
13521
13512
  const connectedSourceTraces = db.source_trace.list().filter((st) => st.connected_source_net_ids?.includes(net.source_net_id));
13513
+ let nominalTraceWidthFromConnectedTraces;
13514
+ for (const sourceTrace of connectedSourceTraces) {
13515
+ if (sourceTrace.min_trace_thickness === void 0) continue;
13516
+ nominalTraceWidthFromConnectedTraces = Math.max(
13517
+ nominalTraceWidthFromConnectedTraces ?? 0,
13518
+ sourceTrace.min_trace_thickness
13519
+ );
13520
+ }
13522
13521
  connectionsFromNets.push({
13523
13522
  name: net.source_net_id ?? connMap.getNetConnectedToId(net.source_net_id),
13523
+ nominalTraceWidth: nominalTraceWidthFromConnectedTraces,
13524
+ width: nominalTraceWidthFromConnectedTraces,
13524
13525
  pointsToConnect: connectedSourceTraces.flatMap((st) => {
13525
13526
  const pcb_ports = db.pcb_port.list().filter(
13526
13527
  (p) => st.connected_source_port_ids.includes(p.source_port_id)
@@ -17352,15 +17353,201 @@ function Group_doInitialSourceAddConnectivityMapKey(group) {
17352
17353
  }
17353
17354
 
17354
17355
  // lib/components/primitive-components/Group/Group_getRoutingPhasePlans.ts
17356
+ function getPhaseSortValue(routingPhaseIndex) {
17357
+ return routingPhaseIndex === null ? Number.POSITIVE_INFINITY : routingPhaseIndex;
17358
+ }
17359
+ function compareRoutingPhasePlans(a, b) {
17360
+ return getPhaseSortValue(a.routingPhaseIndex) - getPhaseSortValue(b.routingPhaseIndex);
17361
+ }
17362
+ function getOrCreateRoutingPhasePlan(plansByPhaseIndex, routingPhaseIndex) {
17363
+ let plan = plansByPhaseIndex.get(routingPhaseIndex);
17364
+ if (!plan) {
17365
+ plan = { routingPhaseIndex, nets: [], traces: [] };
17366
+ plansByPhaseIndex.set(routingPhaseIndex, plan);
17367
+ }
17368
+ return plan;
17369
+ }
17370
+ function getNetRoutingPhaseIndex(net) {
17371
+ return net.props.routingPhaseIndex ?? null;
17372
+ }
17373
+ function getTraceRoutingPhaseIndex(trace) {
17374
+ const traceRoutingPhaseIndex = trace.props.routingPhaseIndex;
17375
+ if (traceRoutingPhaseIndex !== void 0) return traceRoutingPhaseIndex;
17376
+ let routingPhaseIndex = null;
17377
+ const connectedNets = trace._findConnectedNets().nets;
17378
+ for (const net of connectedNets) {
17379
+ const netRoutingPhaseIndex = net.props.routingPhaseIndex;
17380
+ if (typeof netRoutingPhaseIndex === "number") {
17381
+ if (routingPhaseIndex === null || netRoutingPhaseIndex < routingPhaseIndex) {
17382
+ routingPhaseIndex = netRoutingPhaseIndex;
17383
+ }
17384
+ }
17385
+ }
17386
+ return routingPhaseIndex;
17387
+ }
17355
17388
  function Group_getRoutingPhasePlans(group) {
17356
17389
  const traces = group.selectAll("trace");
17357
- if (traces.length === 0) return [];
17358
- return [
17359
- {
17360
- routingPhaseIndex: null,
17361
- traces
17390
+ const nets = group.selectAll("net");
17391
+ if (traces.length === 0 && nets.length === 0) return [];
17392
+ const plansByPhaseIndex = /* @__PURE__ */ new Map();
17393
+ for (const net of nets) {
17394
+ const routingPhaseIndex = getNetRoutingPhaseIndex(net);
17395
+ getOrCreateRoutingPhasePlan(plansByPhaseIndex, routingPhaseIndex).nets.push(
17396
+ net
17397
+ );
17398
+ }
17399
+ for (const trace of traces) {
17400
+ const routingPhaseIndex = getTraceRoutingPhaseIndex(trace);
17401
+ getOrCreateRoutingPhasePlan(
17402
+ plansByPhaseIndex,
17403
+ routingPhaseIndex
17404
+ ).traces.push(trace);
17405
+ }
17406
+ return Array.from(plansByPhaseIndex.values()).sort(compareRoutingPhasePlans);
17407
+ }
17408
+
17409
+ // lib/components/primitive-components/Group/Group_phasedAutoroutingUtils.ts
17410
+ function isWirePoint(point6) {
17411
+ return point6.route_type === "wire";
17412
+ }
17413
+ function isViaPoint(point6) {
17414
+ return point6.route_type === "via";
17415
+ }
17416
+ function isJumperPoint(point6) {
17417
+ return point6.route_type === "jumper";
17418
+ }
17419
+ function getTraceConnectionName(trace) {
17420
+ return trace.connection_name ?? trace.pcb_trace_id;
17421
+ }
17422
+ function getWireWidth(start, end) {
17423
+ if (isWirePoint(start)) return start.width;
17424
+ if (isWirePoint(end)) return end.width;
17425
+ return 0.1;
17426
+ }
17427
+ function getSegmentLayer(start, end) {
17428
+ if (isWirePoint(start)) return start.layer;
17429
+ if (isWirePoint(end)) return end.layer;
17430
+ if (isJumperPoint(start)) return start.layer;
17431
+ if (isJumperPoint(end)) return end.layer;
17432
+ return null;
17433
+ }
17434
+ function getRoutePointX(point6) {
17435
+ if (isJumperPoint(point6)) return null;
17436
+ return point6.x;
17437
+ }
17438
+ function getRoutePointY(point6) {
17439
+ if (isJumperPoint(point6)) return null;
17440
+ return point6.y;
17441
+ }
17442
+ function createWireObstacle(start, end, connectedTo, obstacleIndex) {
17443
+ const startX = getRoutePointX(start);
17444
+ const startY = getRoutePointY(start);
17445
+ const endX = getRoutePointX(end);
17446
+ const endY = getRoutePointY(end);
17447
+ const layer = getSegmentLayer(start, end);
17448
+ if (startX === null || startY === null) return null;
17449
+ if (endX === null || endY === null) return null;
17450
+ if (!layer) return null;
17451
+ const width = getWireWidth(start, end);
17452
+ const dx = Math.abs(startX - endX);
17453
+ const dy = Math.abs(startY - endY);
17454
+ return {
17455
+ obstacleId: `${connectedTo}_phase_obstacle_${obstacleIndex}`,
17456
+ type: "rect",
17457
+ layers: [layer],
17458
+ center: {
17459
+ x: (startX + endX) / 2,
17460
+ y: (startY + endY) / 2
17461
+ },
17462
+ width: dx + width,
17463
+ height: dy + width,
17464
+ connectedTo: [connectedTo]
17465
+ };
17466
+ }
17467
+ function createJumperObstacle(point6, connectedTo, obstacleIndex) {
17468
+ const dx = Math.abs(point6.start.x - point6.end.x);
17469
+ const dy = Math.abs(point6.start.y - point6.end.y);
17470
+ const width = 0.6;
17471
+ return {
17472
+ obstacleId: `${connectedTo}_phase_jumper_obstacle_${obstacleIndex}`,
17473
+ type: "rect",
17474
+ layers: [point6.layer],
17475
+ center: {
17476
+ x: (point6.start.x + point6.end.x) / 2,
17477
+ y: (point6.start.y + point6.end.y) / 2
17478
+ },
17479
+ width: dx + width,
17480
+ height: dy + width,
17481
+ connectedTo: [connectedTo]
17482
+ };
17483
+ }
17484
+ function createViaObstacle(point6, connectedTo, obstacleIndex) {
17485
+ return {
17486
+ obstacleId: `${connectedTo}_phase_via_obstacle_${obstacleIndex}`,
17487
+ type: "rect",
17488
+ layers: [point6.from_layer, point6.to_layer],
17489
+ center: { x: point6.x, y: point6.y },
17490
+ width: 0.6,
17491
+ height: 0.6,
17492
+ connectedTo: [connectedTo]
17493
+ };
17494
+ }
17495
+ function addTraceObstacles(obstacles, trace) {
17496
+ const connectedTo = getTraceConnectionName(trace);
17497
+ for (let routeIndex = 0; routeIndex < trace.route.length; routeIndex++) {
17498
+ const routePoint = trace.route[routeIndex];
17499
+ if (isViaPoint(routePoint)) {
17500
+ obstacles.push(createViaObstacle(routePoint, connectedTo, routeIndex));
17501
+ } else if (isJumperPoint(routePoint)) {
17502
+ obstacles.push(createJumperObstacle(routePoint, connectedTo, routeIndex));
17503
+ }
17504
+ if (routeIndex === trace.route.length - 1) continue;
17505
+ const nextPoint = trace.route[routeIndex + 1];
17506
+ const obstacle = createWireObstacle(
17507
+ routePoint,
17508
+ nextPoint,
17509
+ connectedTo,
17510
+ routeIndex
17511
+ );
17512
+ if (obstacle) obstacles.push(obstacle);
17513
+ }
17514
+ }
17515
+ function connectionIsInRoutingPhase(connection, phasePlan) {
17516
+ for (const trace of phasePlan.traces) {
17517
+ if (!trace.source_trace_id) continue;
17518
+ if (connection.source_trace_id === trace.source_trace_id) return true;
17519
+ if (connection.name === trace.source_trace_id) return true;
17520
+ }
17521
+ for (const net of phasePlan.nets) {
17522
+ if (!net.source_net_id) continue;
17523
+ if (connection.name === net.source_net_id) return true;
17524
+ }
17525
+ return false;
17526
+ }
17527
+ function Group_hasPhasedAutorouting(routingPhasePlans) {
17528
+ for (const plan of routingPhasePlans) {
17529
+ if (plan.routingPhaseIndex !== null) return true;
17530
+ }
17531
+ return false;
17532
+ }
17533
+ function Group_filterSimpleRouteJsonForPhase(simpleRouteJson, phasePlan) {
17534
+ const connections = [];
17535
+ for (const connection of simpleRouteJson.connections) {
17536
+ if (connectionIsInRoutingPhase(connection, phasePlan)) {
17537
+ connections.push(connection);
17362
17538
  }
17363
- ];
17539
+ }
17540
+ return {
17541
+ ...simpleRouteJson,
17542
+ connections
17543
+ };
17544
+ }
17545
+ function Group_getObstaclesFromRoutedTraces(traces) {
17546
+ const obstacles = [];
17547
+ for (const trace of traces) {
17548
+ addTraceObstacles(obstacles, trace);
17549
+ }
17550
+ return obstacles;
17364
17551
  }
17365
17552
 
17366
17553
  // lib/components/primitive-components/Group/add-port-ids-to-traces-at-jumper-pads.ts
@@ -18052,123 +18239,143 @@ var Group6 = class extends NormalComponent3 {
18052
18239
  const isLaserPrefabPreset = this._isLaserPrefabAutorouter(autorouterConfig);
18053
18240
  const isAutoJumperPreset = this._isAutoJumperAutorouter(autorouterConfig);
18054
18241
  const isSingleLayerBoard = this._getSubcircuitLayerCount() === 1;
18055
- const { simpleRouteJson } = getSimpleRouteJsonFromCircuitJson({
18242
+ const { simpleRouteJson: baseSimpleRouteJson } = getSimpleRouteJsonFromCircuitJson({
18056
18243
  db,
18057
18244
  minTraceWidth: this.props.autorouter?.minTraceWidth ?? 0.15,
18058
18245
  nominalTraceWidth: this.props.nominalTraceWidth,
18059
18246
  subcircuit_id: this.subcircuit_id,
18060
18247
  subcircuitComponent: this
18061
18248
  });
18062
- if (isAutoJumperPreset) {
18063
- simpleRouteJson.allowJumpers = true;
18064
- if (autorouterConfig.availableJumperTypes) {
18065
- simpleRouteJson.availableJumperTypes = autorouterConfig.availableJumperTypes;
18249
+ const routingPhasePlans = this._getRoutingPhasePlans();
18250
+ const hasPhasedAutorouting = Group_hasPhasedAutorouting(routingPhasePlans);
18251
+ const outputTraces = [];
18252
+ const outputJumpers = [];
18253
+ for (const routingPhasePlan of routingPhasePlans) {
18254
+ let simpleRouteJson = baseSimpleRouteJson;
18255
+ if (hasPhasedAutorouting) {
18256
+ simpleRouteJson = Group_filterSimpleRouteJsonForPhase(
18257
+ baseSimpleRouteJson,
18258
+ routingPhasePlan
18259
+ );
18260
+ simpleRouteJson.obstacles = [
18261
+ ...simpleRouteJson.obstacles,
18262
+ ...Group_getObstaclesFromRoutedTraces(outputTraces)
18263
+ ];
18066
18264
  }
18067
- }
18068
- if (debug11.enabled) {
18069
- ;
18070
- global.debugOutputArray?.push({
18071
- name: `simpleroutejson-${this.props.name}.json`,
18072
- obj: simpleRouteJson
18073
- });
18074
- }
18075
- if (debug11.enabled) {
18076
- const graphicsObject = convertSrjToGraphicsObject(
18077
- simpleRouteJson
18078
- );
18079
- graphicsObject.title = `autorouting-${this.props.name}`;
18080
- global.debugGraphics?.push(graphicsObject);
18081
- }
18082
- this.root?.emit("autorouting:start", {
18083
- subcircuit_id: this.subcircuit_id,
18084
- componentDisplayName: this.getString(),
18085
- simpleRouteJson
18086
- });
18087
- let autorouter;
18088
- if (autorouterConfig.algorithmFn) {
18089
- autorouter = await autorouterConfig.algorithmFn(simpleRouteJson);
18090
- } else {
18091
- const autorouterVersion2 = this.props.autorouterVersion;
18092
- const effortLevel = this.props.autorouterEffortLevel;
18093
- const effort = effortLevel ? Number.parseInt(effortLevel.replace("x", ""), 10) : void 0;
18094
- autorouter = new TscircuitAutorouter(simpleRouteJson, {
18095
- // Optional configuration parameters
18096
- capacityDepth: this.props.autorouter?.capacityDepth,
18097
- targetMinCapacity: this.props.autorouter?.targetMinCapacity,
18098
- useAssignableSolver: isLaserPrefabPreset || isSingleLayerBoard,
18099
- useAutoJumperSolver: isAutoJumperPreset,
18100
- autorouterVersion: autorouterVersion2,
18101
- effort,
18102
- onSolverStarted: ({ solverName, solverParams }) => this.root?.emit("solver:started", {
18103
- type: "solver:started",
18104
- solverName,
18105
- solverParams,
18106
- componentName: this.getString()
18107
- })
18108
- });
18109
- }
18110
- const routingPromise = new Promise(
18111
- (resolve, reject) => {
18112
- autorouter.on("complete", (event) => {
18113
- debug11(`[${this.getString()}] local autorouting complete`);
18114
- resolve(event.traces);
18115
- });
18116
- autorouter.on("error", (event) => {
18117
- debug11(
18118
- `[${this.getString()}] local autorouting error: ${event.error.message}`
18119
- );
18120
- reject(event.error);
18265
+ if (hasPhasedAutorouting && simpleRouteJson.connections.length === 0) {
18266
+ continue;
18267
+ }
18268
+ if (isAutoJumperPreset) {
18269
+ simpleRouteJson.allowJumpers = true;
18270
+ if (autorouterConfig.availableJumperTypes) {
18271
+ simpleRouteJson.availableJumperTypes = autorouterConfig.availableJumperTypes;
18272
+ }
18273
+ }
18274
+ if (debug11.enabled) {
18275
+ ;
18276
+ global.debugOutputArray?.push({
18277
+ name: `simpleroutejson-${this.props.name}.json`,
18278
+ obj: simpleRouteJson
18121
18279
  });
18122
18280
  }
18123
- );
18124
- autorouter.on("progress", (event) => {
18125
- this.root?.emit("autorouting:progress", {
18281
+ if (debug11.enabled) {
18282
+ const graphicsObject = convertSrjToGraphicsObject(
18283
+ simpleRouteJson
18284
+ );
18285
+ graphicsObject.title = `autorouting-${this.props.name}`;
18286
+ global.debugGraphics?.push(graphicsObject);
18287
+ }
18288
+ this.root?.emit("autorouting:start", {
18126
18289
  subcircuit_id: this.subcircuit_id,
18127
18290
  componentDisplayName: this.getString(),
18128
- ...event
18291
+ simpleRouteJson
18129
18292
  });
18130
- });
18131
- autorouter.start();
18132
- try {
18133
- const traces = await routingPromise;
18134
- if (autorouter.getConnectedOffboardObstacles) {
18135
- const connectedOffboardObstacles = autorouter.getConnectedOffboardObstacles();
18136
- createSourceTracesFromOffboardConnections({
18137
- db,
18138
- connectedOffboardObstacles,
18139
- simpleRouteJson,
18140
- subcircuit_id: this.subcircuit_id
18293
+ let autorouter;
18294
+ if (autorouterConfig.algorithmFn) {
18295
+ autorouter = await autorouterConfig.algorithmFn(simpleRouteJson);
18296
+ } else {
18297
+ const autorouterVersion2 = this.props.autorouterVersion;
18298
+ const effortLevel = this.props.autorouterEffortLevel;
18299
+ const effort = effortLevel ? Number.parseInt(effortLevel.replace("x", ""), 10) : void 0;
18300
+ autorouter = new TscircuitAutorouter(simpleRouteJson, {
18301
+ // Optional configuration parameters
18302
+ capacityDepth: this.props.autorouter?.capacityDepth,
18303
+ targetMinCapacity: this.props.autorouter?.targetMinCapacity,
18304
+ useAssignableSolver: isLaserPrefabPreset || isSingleLayerBoard,
18305
+ useAutoJumperSolver: isAutoJumperPreset,
18306
+ autorouterVersion: autorouterVersion2,
18307
+ effort,
18308
+ onSolverStarted: ({ solverName, solverParams }) => this.root?.emit("solver:started", {
18309
+ type: "solver:started",
18310
+ solverName,
18311
+ solverParams,
18312
+ componentName: this.getString()
18313
+ })
18141
18314
  });
18142
18315
  }
18143
- let outputJumpers = [];
18144
- const solver = autorouter.solver;
18145
- if (solver?.getOutputJumpers) {
18146
- outputJumpers = solver.getOutputJumpers() || [];
18147
- }
18148
- this._asyncAutoroutingResult = {
18149
- output_pcb_traces: traces,
18150
- output_jumpers: outputJumpers
18151
- };
18152
- this._markDirty("PcbTraceRender");
18153
- } catch (error) {
18154
- const { db: db2 } = this.root;
18155
- db2.pcb_autorouting_error.insert({
18156
- pcb_error_id: `pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,
18157
- error_type: "pcb_autorouting_error",
18158
- message: error instanceof Error ? error.message : String(error)
18316
+ const routingPromise = new Promise(
18317
+ (resolve, reject) => {
18318
+ autorouter.on("complete", (event) => {
18319
+ debug11(`[${this.getString()}] local autorouting complete`);
18320
+ resolve(event.traces);
18321
+ });
18322
+ autorouter.on("error", (event) => {
18323
+ debug11(
18324
+ `[${this.getString()}] local autorouting error: ${event.error.message}`
18325
+ );
18326
+ reject(event.error);
18327
+ });
18328
+ }
18329
+ );
18330
+ autorouter.on("progress", (event) => {
18331
+ this.root?.emit("autorouting:progress", {
18332
+ subcircuit_id: this.subcircuit_id,
18333
+ componentDisplayName: this.getString(),
18334
+ ...event
18335
+ });
18159
18336
  });
18160
- this.root?.emit("autorouting:error", {
18161
- subcircuit_id: this.subcircuit_id,
18162
- componentDisplayName: this.getString(),
18163
- error: {
18337
+ autorouter.start();
18338
+ try {
18339
+ const traces = await routingPromise;
18340
+ if (autorouter.getConnectedOffboardObstacles) {
18341
+ const connectedOffboardObstacles = autorouter.getConnectedOffboardObstacles();
18342
+ createSourceTracesFromOffboardConnections({
18343
+ db,
18344
+ connectedOffboardObstacles,
18345
+ simpleRouteJson,
18346
+ subcircuit_id: this.subcircuit_id
18347
+ });
18348
+ }
18349
+ const solver = autorouter.solver;
18350
+ if (solver?.getOutputJumpers) {
18351
+ outputJumpers.push(...solver.getOutputJumpers() || []);
18352
+ }
18353
+ outputTraces.push(...traces);
18354
+ } catch (error) {
18355
+ const { db: db2 } = this.root;
18356
+ db2.pcb_autorouting_error.insert({
18357
+ pcb_error_id: `pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,
18358
+ error_type: "pcb_autorouting_error",
18164
18359
  message: error instanceof Error ? error.message : String(error)
18165
- },
18166
- simpleRouteJson
18167
- });
18168
- throw error;
18169
- } finally {
18170
- autorouter.stop();
18360
+ });
18361
+ this.root?.emit("autorouting:error", {
18362
+ subcircuit_id: this.subcircuit_id,
18363
+ componentDisplayName: this.getString(),
18364
+ error: {
18365
+ message: error instanceof Error ? error.message : String(error)
18366
+ },
18367
+ simpleRouteJson
18368
+ });
18369
+ throw error;
18370
+ } finally {
18371
+ autorouter.stop();
18372
+ }
18171
18373
  }
18374
+ this._asyncAutoroutingResult = {
18375
+ output_pcb_traces: outputTraces,
18376
+ output_jumpers: outputJumpers
18377
+ };
18378
+ this._markDirty("PcbTraceRender");
18172
18379
  }
18173
18380
  _startAsyncAutorouting() {
18174
18381
  if (this._hasStartedAsyncAutorouting) return;
@@ -19345,7 +19552,7 @@ import { identity as identity5 } from "transformation-matrix";
19345
19552
  var package_default = {
19346
19553
  name: "@tscircuit/core",
19347
19554
  type: "module",
19348
- version: "0.0.1160",
19555
+ version: "0.0.1162",
19349
19556
  types: "dist/index.d.ts",
19350
19557
  main: "dist/index.js",
19351
19558
  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.1161",
4
+ "version": "0.0.1163",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",