@tscircuit/core 0.0.122 → 0.0.124
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 +9 -1
- package/dist/index.js +98 -27
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Matrix } from 'transformation-matrix';
|
|
|
8
8
|
import * as _tscircuit_props from '@tscircuit/props';
|
|
9
9
|
import { traceProps, groupProps, boardProps, capacitorProps, chipProps, diodeProps, jumperProps, ledProps, powerSourceProps, resistorProps, constraintProps, fabricationNotePathProps, fabricationNoteTextProps, footprintProps, holeProps, pcbKeepoutProps, netAliasProps, platedHoleProps, silkscreenCircleProps, silkscreenPathProps, silkscreenRectProps, silkscreenTextProps, smtPadProps, traceHintProps, viaProps, batteryProps } from '@tscircuit/props';
|
|
10
10
|
|
|
11
|
-
declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "
|
|
11
|
+
declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SchematicComponentRender", "SchematicPortRender", "SchematicLayout", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
|
|
12
12
|
type RenderPhase = (typeof orderedRenderPhases)[number];
|
|
13
13
|
type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
|
|
14
14
|
type RenderPhaseStates = Record<RenderPhase, {
|
|
@@ -598,6 +598,10 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
|
|
|
598
598
|
x: number;
|
|
599
599
|
y: number;
|
|
600
600
|
};
|
|
601
|
+
_getGlobalSchematicPositionAfterLayout(): {
|
|
602
|
+
x: number;
|
|
603
|
+
y: number;
|
|
604
|
+
};
|
|
601
605
|
/**
|
|
602
606
|
* Smtpads and platedholes call this method to register themselves as a match
|
|
603
607
|
* for this port. All the matching is done by primitives other than the Port,
|
|
@@ -720,6 +724,7 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
|
|
|
720
724
|
componentName: string;
|
|
721
725
|
};
|
|
722
726
|
doInitialCreateTraceHintsFromProps(): void;
|
|
727
|
+
doInitialSchematicLayout(): void;
|
|
723
728
|
}
|
|
724
729
|
|
|
725
730
|
declare class Board extends Group<typeof boardProps> {
|
|
@@ -746,6 +751,7 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
746
751
|
routingDisabled: z.ZodOptional<z.ZodBoolean>;
|
|
747
752
|
children: z.ZodAny;
|
|
748
753
|
defaultTraceWidth: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
|
|
754
|
+
schAutoLayoutEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
749
755
|
}, "strip", z.ZodTypeAny, {
|
|
750
756
|
pcbX: number;
|
|
751
757
|
pcbY: number;
|
|
@@ -755,6 +761,7 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
755
761
|
layout?: any;
|
|
756
762
|
routingDisabled?: boolean | undefined;
|
|
757
763
|
defaultTraceWidth?: number | undefined;
|
|
764
|
+
schAutoLayoutEnabled?: boolean | undefined;
|
|
758
765
|
outline?: {
|
|
759
766
|
x: number;
|
|
760
767
|
y: number;
|
|
@@ -768,6 +775,7 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
768
775
|
layout?: any;
|
|
769
776
|
routingDisabled?: boolean | undefined;
|
|
770
777
|
defaultTraceWidth?: string | number | undefined;
|
|
778
|
+
schAutoLayoutEnabled?: boolean | undefined;
|
|
771
779
|
outline?: {
|
|
772
780
|
x: string | number;
|
|
773
781
|
y: string | number;
|
package/dist/index.js
CHANGED
|
@@ -60,8 +60,8 @@ var orderedRenderPhases = [
|
|
|
60
60
|
"PortMatching",
|
|
61
61
|
"SourceTraceRender",
|
|
62
62
|
"SchematicComponentRender",
|
|
63
|
-
"SchematicLayout",
|
|
64
63
|
"SchematicPortRender",
|
|
64
|
+
"SchematicLayout",
|
|
65
65
|
"SchematicTraceRender",
|
|
66
66
|
"PcbComponentRender",
|
|
67
67
|
"PcbPrimitiveRender",
|
|
@@ -1530,6 +1530,20 @@ var Port = class extends PrimitiveComponent {
|
|
|
1530
1530
|
);
|
|
1531
1531
|
return applyToPoint4(transform, this.schematicSymbolPortDef);
|
|
1532
1532
|
}
|
|
1533
|
+
_getGlobalSchematicPositionAfterLayout() {
|
|
1534
|
+
const { db } = this.root;
|
|
1535
|
+
if (!this.schematic_port_id) {
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
`Can't get schematic port position after layout, no schematic_port_id`
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
const schematic_port = db.schematic_port.get(this.schematic_port_id);
|
|
1541
|
+
if (!schematic_port)
|
|
1542
|
+
throw new Error(
|
|
1543
|
+
`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`
|
|
1544
|
+
);
|
|
1545
|
+
return schematic_port.center;
|
|
1546
|
+
}
|
|
1533
1547
|
/**
|
|
1534
1548
|
* Smtpads and platedholes call this method to register themselves as a match
|
|
1535
1549
|
* for this port. All the matching is done by primitives other than the Port,
|
|
@@ -1631,12 +1645,14 @@ var Port = class extends PrimitiveComponent {
|
|
|
1631
1645
|
const { _parsedProps: props } = this;
|
|
1632
1646
|
const container = this.getPrimitiveContainer();
|
|
1633
1647
|
if (!container) return;
|
|
1648
|
+
const containerCenter = container._getGlobalSchematicPositionBeforeLayout();
|
|
1634
1649
|
let center = this._getGlobalSchematicPositionBeforeLayout();
|
|
1635
1650
|
if ("schematicDimensions" in container && props.pinNumber !== void 0) {
|
|
1636
1651
|
const chipDims = container.schematicDimensions;
|
|
1637
1652
|
center = chipDims.getPortPositionByPinNumber(props.pinNumber);
|
|
1653
|
+
center.x += containerCenter.x;
|
|
1654
|
+
center.y += containerCenter.y;
|
|
1638
1655
|
}
|
|
1639
|
-
const containerCenter = container._getGlobalSchematicPositionBeforeLayout();
|
|
1640
1656
|
this.facingDirection = getRelativeDirection(containerCenter, center);
|
|
1641
1657
|
const schematic_port = db.schematic_port.insert({
|
|
1642
1658
|
schematic_component_id: this.parent?.schematic_component_id,
|
|
@@ -2378,6 +2394,7 @@ var TraceHint = class extends PrimitiveComponent {
|
|
|
2378
2394
|
};
|
|
2379
2395
|
|
|
2380
2396
|
// lib/components/primitive-components/Group.ts
|
|
2397
|
+
import * as SAL from "@tscircuit/schematic-autolayout";
|
|
2381
2398
|
var Group = class extends NormalComponent {
|
|
2382
2399
|
get config() {
|
|
2383
2400
|
return {
|
|
@@ -2401,6 +2418,32 @@ var Group = class extends NormalComponent {
|
|
|
2401
2418
|
);
|
|
2402
2419
|
}
|
|
2403
2420
|
}
|
|
2421
|
+
doInitialSchematicLayout() {
|
|
2422
|
+
if (!this.isSubcircuit) return;
|
|
2423
|
+
const props = this._parsedProps;
|
|
2424
|
+
if (!props.schAutoLayoutEnabled) return;
|
|
2425
|
+
const { db } = this.root;
|
|
2426
|
+
const descendants = this.getDescendants();
|
|
2427
|
+
const components = [];
|
|
2428
|
+
const ports = [];
|
|
2429
|
+
for (const descendant of descendants) {
|
|
2430
|
+
if ("schematic_component_id" in descendant) {
|
|
2431
|
+
const component = db.schematic_component.get(
|
|
2432
|
+
descendant.schematic_component_id
|
|
2433
|
+
);
|
|
2434
|
+
if (component) {
|
|
2435
|
+
const schPorts = db.schematic_port.list().filter(
|
|
2436
|
+
(p) => p.schematic_component_id === component.schematic_component_id
|
|
2437
|
+
);
|
|
2438
|
+
components.push(component);
|
|
2439
|
+
ports.push(...schPorts);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
const scene = SAL.convertSoupToScene(db.toArray());
|
|
2444
|
+
const laidOutScene = SAL.ascendingCentralLrBug1(scene);
|
|
2445
|
+
SAL.mutateSoupForScene(db.toArray(), laidOutScene);
|
|
2446
|
+
}
|
|
2404
2447
|
};
|
|
2405
2448
|
|
|
2406
2449
|
// lib/components/normal-components/Board.ts
|
|
@@ -2481,22 +2524,6 @@ var computeObstacleBounds = (obstacles) => {
|
|
|
2481
2524
|
return { minX, maxX, minY, maxY };
|
|
2482
2525
|
};
|
|
2483
2526
|
|
|
2484
|
-
// lib/utils/projectPointInDirection.ts
|
|
2485
|
-
var projectPointInDirection = (point, direction, distance) => {
|
|
2486
|
-
switch (direction) {
|
|
2487
|
-
case "up":
|
|
2488
|
-
return { x: point.x, y: point.y - distance };
|
|
2489
|
-
case "down":
|
|
2490
|
-
return { x: point.x, y: point.y + distance };
|
|
2491
|
-
case "left":
|
|
2492
|
-
return { x: point.x - distance, y: point.y };
|
|
2493
|
-
case "right":
|
|
2494
|
-
return { x: point.x + distance, y: point.y };
|
|
2495
|
-
default:
|
|
2496
|
-
throw new Error(`Unknown direction "${direction}"`);
|
|
2497
|
-
}
|
|
2498
|
-
};
|
|
2499
|
-
|
|
2500
2527
|
// lib/utils/autorouting/findPossibleTraceLayerCombinations.ts
|
|
2501
2528
|
var LAYER_SELECTION_PREFERENCE = ["top", "bottom", "inner1", "inner2"];
|
|
2502
2529
|
var findPossibleTraceLayerCombinations = (hints, layer_path = []) => {
|
|
@@ -2644,6 +2671,45 @@ function tryNow(fn) {
|
|
|
2644
2671
|
|
|
2645
2672
|
// lib/components/primitive-components/Trace.ts
|
|
2646
2673
|
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
|
|
2674
|
+
|
|
2675
|
+
// lib/utils/autorouting/DirectLineRouter.ts
|
|
2676
|
+
var DirectLineRouter = class {
|
|
2677
|
+
input;
|
|
2678
|
+
constructor({ input }) {
|
|
2679
|
+
this.input = input;
|
|
2680
|
+
}
|
|
2681
|
+
solveAndMapToTraces() {
|
|
2682
|
+
const traces = [];
|
|
2683
|
+
for (const connection of this.input.connections) {
|
|
2684
|
+
if (connection.pointsToConnect.length !== 2) continue;
|
|
2685
|
+
const [start, end] = connection.pointsToConnect;
|
|
2686
|
+
const trace = {
|
|
2687
|
+
type: "pcb_trace",
|
|
2688
|
+
pcb_trace_id: "",
|
|
2689
|
+
route: [
|
|
2690
|
+
{
|
|
2691
|
+
route_type: "wire",
|
|
2692
|
+
x: start.x,
|
|
2693
|
+
y: start.y,
|
|
2694
|
+
layer: "top",
|
|
2695
|
+
width: 0.1
|
|
2696
|
+
},
|
|
2697
|
+
{
|
|
2698
|
+
route_type: "wire",
|
|
2699
|
+
x: end.x,
|
|
2700
|
+
y: end.y,
|
|
2701
|
+
layer: "top",
|
|
2702
|
+
width: 0.1
|
|
2703
|
+
}
|
|
2704
|
+
]
|
|
2705
|
+
};
|
|
2706
|
+
traces.push(trace);
|
|
2707
|
+
}
|
|
2708
|
+
return traces;
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2712
|
+
// lib/components/primitive-components/Trace.ts
|
|
2647
2713
|
var portToObjective = (port) => {
|
|
2648
2714
|
const portPosition = port._getGlobalPcbPositionAfterLayout();
|
|
2649
2715
|
return {
|
|
@@ -3069,29 +3135,34 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3069
3135
|
}
|
|
3070
3136
|
for (const { port } of ports) {
|
|
3071
3137
|
connection.pointsToConnect.push({
|
|
3072
|
-
...
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3138
|
+
...port._getGlobalSchematicPositionAfterLayout(),
|
|
3139
|
+
// ...projectPointInDirection(
|
|
3140
|
+
// port._getGlobalSchematicPositionAfterLayout(),
|
|
3141
|
+
// port.facingDirection!,
|
|
3142
|
+
// 0.1501,
|
|
3143
|
+
// ),
|
|
3077
3144
|
layer: "top"
|
|
3078
3145
|
});
|
|
3079
3146
|
}
|
|
3080
3147
|
const bounds = computeObstacleBounds(obstacles);
|
|
3081
3148
|
const simpleRouteJsonInput = {
|
|
3082
3149
|
minTraceWidth: 0.1,
|
|
3083
|
-
obstacles,
|
|
3150
|
+
obstacles: [],
|
|
3151
|
+
// leave empty to force traces to draw
|
|
3084
3152
|
connections: [connection],
|
|
3085
3153
|
bounds,
|
|
3086
3154
|
layerCount: 1
|
|
3087
3155
|
};
|
|
3088
|
-
|
|
3156
|
+
let Autorouter = IJumpAutorouter;
|
|
3157
|
+
if (this.getSubcircuit().props._schDirectLineRoutingEnabled) {
|
|
3158
|
+
Autorouter = DirectLineRouter;
|
|
3159
|
+
}
|
|
3160
|
+
const autorouter = new Autorouter({
|
|
3089
3161
|
input: simpleRouteJsonInput
|
|
3090
3162
|
});
|
|
3091
|
-
const results = autorouter.
|
|
3163
|
+
const results = autorouter.solveAndMapToTraces();
|
|
3092
3164
|
if (results.length === 0) return;
|
|
3093
3165
|
const [result] = results;
|
|
3094
|
-
if (!result.solved) return;
|
|
3095
3166
|
const { route } = result;
|
|
3096
3167
|
const edges = [];
|
|
3097
3168
|
for (let i = 0; i < route.length - 1; i++) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.124",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@lume/kiwi": "^0.4.3",
|
|
38
|
-
"@tscircuit/footprinter": "^0.0.
|
|
38
|
+
"@tscircuit/footprinter": "^0.0.77",
|
|
39
39
|
"@tscircuit/infgrid-ijump-astar": "^0.0.21",
|
|
40
40
|
"@tscircuit/math-utils": "^0.0.4",
|
|
41
|
-
"@tscircuit/props": "^0.0.
|
|
41
|
+
"@tscircuit/props": "^0.0.75",
|
|
42
|
+
"@tscircuit/schematic-autolayout": "^0.0.5",
|
|
42
43
|
"@tscircuit/soup-util": "^0.0.33",
|
|
43
44
|
"circuit-json": "^0.0.86",
|
|
44
45
|
"circuit-json-to-connectivity-map": "^0.0.17",
|