@tscircuit/core 0.0.154 → 0.0.156
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 -2
- package/dist/index.js +127 -36
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Matrix } from 'transformation-matrix';
|
|
|
9
9
|
import { SoupUtilObjects } from '@tscircuit/soup-util';
|
|
10
10
|
import * as _tscircuit_layout from '@tscircuit/layout';
|
|
11
11
|
|
|
12
|
-
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
|
+
declare const orderedRenderPhases: readonly ["ReactSubtreesRender", "InitializePortsFromChildren", "CreateNetsFromProps", "CreateTracesFromProps", "CreateTraceHintsFromProps", "SourceRender", "SourceParentAttachment", "PortDiscovery", "PortMatching", "SourceTraceRender", "SourceAddConnectivityMapKey", "SchematicComponentRender", "SchematicPortRender", "SchematicLayout", "SchematicTraceRender", "PcbComponentRender", "PcbPrimitiveRender", "PcbFootprintLayout", "PcbPortRender", "PcbPortAttachment", "PcbLayout", "PcbTraceRender", "PcbTraceHintRender", "PcbRouteNetIslands", "PcbComponentSizeCalculation", "CadModelRender"];
|
|
13
13
|
type RenderPhase = (typeof orderedRenderPhases)[number];
|
|
14
14
|
type RenderPhaseFn<K extends RenderPhase = RenderPhase> = `doInitial${K}` | `update${K}` | `remove${K}`;
|
|
15
15
|
type RenderPhaseStates = Record<RenderPhase, {
|
|
@@ -351,11 +351,17 @@ declare class Net extends PrimitiveComponent<typeof netProps> {
|
|
|
351
351
|
renderError(message: Parameters<typeof PrimitiveComponent.prototype.renderError>[0]): void;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
|
|
354
|
+
interface TraceI extends PrimitiveComponent<typeof traceProps> {
|
|
355
|
+
source_trace_id: string | null;
|
|
356
|
+
subcircuit_connectivity_map_key: string | null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
declare class Trace extends PrimitiveComponent<typeof traceProps> implements TraceI {
|
|
355
360
|
source_trace_id: string | null;
|
|
356
361
|
pcb_trace_id: string | null;
|
|
357
362
|
schematic_trace_id: string | null;
|
|
358
363
|
_portsRoutedOnPcb: Port[];
|
|
364
|
+
subcircuit_connectivity_map_key: string | null;
|
|
359
365
|
constructor(props: z.input<typeof traceProps>);
|
|
360
366
|
get config(): {
|
|
361
367
|
zodProps: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
|
@@ -841,6 +847,7 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
|
|
|
841
847
|
};
|
|
842
848
|
doInitialCreateTraceHintsFromProps(): void;
|
|
843
849
|
_getSimpleRouteJsonFromPcbTraces(): SimpleRouteJson;
|
|
850
|
+
doInitialSourceAddConnectivityMapKey(): void;
|
|
844
851
|
doInitialPcbTraceRender(): void;
|
|
845
852
|
updatePcbTraceRender(): void;
|
|
846
853
|
doInitialSchematicLayout(): void;
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ var orderedRenderPhases = [
|
|
|
62
62
|
"PortDiscovery",
|
|
63
63
|
"PortMatching",
|
|
64
64
|
"SourceTraceRender",
|
|
65
|
+
"SourceAddConnectivityMapKey",
|
|
65
66
|
"SchematicComponentRender",
|
|
66
67
|
"SchematicPortRender",
|
|
67
68
|
"SchematicLayout",
|
|
@@ -1654,7 +1655,7 @@ var Port = class extends PrimitiveComponent {
|
|
|
1654
1655
|
const matchedPcbElm = this.matchedComponents.find((c) => c.isPcbPrimitive);
|
|
1655
1656
|
if (!matchedPcbElm) {
|
|
1656
1657
|
throw new Error(
|
|
1657
|
-
`Port ${this} has no matched pcb component, can't get global
|
|
1658
|
+
`Port ${this} has no matched pcb component, can't get global pcb position`
|
|
1658
1659
|
);
|
|
1659
1660
|
}
|
|
1660
1661
|
return matchedPcbElm?._getGlobalPcbPositionBeforeLayout() ?? { x: 0, y: 0 };
|
|
@@ -2929,6 +2930,7 @@ var TraceHint = class extends PrimitiveComponent {
|
|
|
2929
2930
|
// lib/components/primitive-components/Group/Group.ts
|
|
2930
2931
|
import * as SAL from "@tscircuit/schematic-autolayout";
|
|
2931
2932
|
import { getObstaclesFromSoup } from "@tscircuit/infgrid-ijump-astar";
|
|
2933
|
+
import { ConnectivityMap } from "circuit-json-to-connectivity-map";
|
|
2932
2934
|
var Group = class extends NormalComponent {
|
|
2933
2935
|
_asyncAutoroutingResult = null;
|
|
2934
2936
|
get config() {
|
|
@@ -3001,6 +3003,35 @@ var Group = class extends NormalComponent {
|
|
|
3001
3003
|
minTraceWidth: this._parsedProps.minTraceWidth ?? 0.1
|
|
3002
3004
|
};
|
|
3003
3005
|
}
|
|
3006
|
+
doInitialSourceAddConnectivityMapKey() {
|
|
3007
|
+
if (!this.isSubcircuit) return;
|
|
3008
|
+
const { db } = this.root;
|
|
3009
|
+
const traces = this.selectAll("trace");
|
|
3010
|
+
const connMap = new ConnectivityMap({});
|
|
3011
|
+
connMap.addConnections(
|
|
3012
|
+
traces.map((t) => {
|
|
3013
|
+
const source_trace = db.source_trace.get(
|
|
3014
|
+
t.source_trace_id
|
|
3015
|
+
);
|
|
3016
|
+
if (!source_trace) return null;
|
|
3017
|
+
return [
|
|
3018
|
+
source_trace.source_trace_id,
|
|
3019
|
+
...source_trace.connected_source_port_ids,
|
|
3020
|
+
...source_trace.connected_source_net_ids
|
|
3021
|
+
];
|
|
3022
|
+
}).filter((c) => c !== null)
|
|
3023
|
+
);
|
|
3024
|
+
for (const trace of traces) {
|
|
3025
|
+
if (!trace.source_trace_id) continue;
|
|
3026
|
+
const connNetId = connMap.getNetConnectedToId(trace.source_trace_id);
|
|
3027
|
+
if (!connNetId) continue;
|
|
3028
|
+
const { name: subcircuitName } = this._parsedProps;
|
|
3029
|
+
trace.subcircuit_connectivity_map_key = `${subcircuitName ?? `unnamedsubcircuit${this._renderId}`}_${connNetId}`;
|
|
3030
|
+
db.source_trace.update(trace.source_trace_id, {
|
|
3031
|
+
subcircuit_connectivity_map_key: trace.subcircuit_connectivity_map_key
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3004
3035
|
doInitialPcbTraceRender() {
|
|
3005
3036
|
if (this._shouldUseTraceByTraceRouting()) return;
|
|
3006
3037
|
if (this.props.autorouter?.serverUrl) {
|
|
@@ -3135,7 +3166,7 @@ var stringProxy = new Proxy(
|
|
|
3135
3166
|
);
|
|
3136
3167
|
var FTYPE = stringProxy;
|
|
3137
3168
|
|
|
3138
|
-
// lib/components/primitive-components/Trace.ts
|
|
3169
|
+
// lib/components/primitive-components/Trace/Trace.ts
|
|
3139
3170
|
import {
|
|
3140
3171
|
MultilayerIjump,
|
|
3141
3172
|
getObstaclesFromSoup as getObstaclesFromSoup2
|
|
@@ -3331,7 +3362,7 @@ function tryNow(fn) {
|
|
|
3331
3362
|
}
|
|
3332
3363
|
}
|
|
3333
3364
|
|
|
3334
|
-
// lib/components/primitive-components/Trace.ts
|
|
3365
|
+
// lib/components/primitive-components/Trace/Trace.ts
|
|
3335
3366
|
import "zod";
|
|
3336
3367
|
|
|
3337
3368
|
// lib/utils/autorouting/getDominantDirection.ts
|
|
@@ -3382,8 +3413,95 @@ var getStubEdges = ({
|
|
|
3382
3413
|
return edges;
|
|
3383
3414
|
};
|
|
3384
3415
|
|
|
3385
|
-
// lib/components/primitive-components/Trace.ts
|
|
3416
|
+
// lib/components/primitive-components/Trace/Trace.ts
|
|
3417
|
+
import "@tscircuit/math-utils";
|
|
3418
|
+
|
|
3419
|
+
// lib/components/primitive-components/Trace/push-edges-of-schematic-trace-to-prevent-overlap.ts
|
|
3386
3420
|
import { doesLineIntersectLine } from "@tscircuit/math-utils";
|
|
3421
|
+
var pushEdgesOfSchematicTraceToPreventOverlap = ({
|
|
3422
|
+
edges,
|
|
3423
|
+
db
|
|
3424
|
+
}) => {
|
|
3425
|
+
const otherEdges = [];
|
|
3426
|
+
for (const otherSchematicTrace of db.schematic_trace.list()) {
|
|
3427
|
+
otherEdges.push(...otherSchematicTrace.edges);
|
|
3428
|
+
}
|
|
3429
|
+
const edgeOrientation = (edge) => {
|
|
3430
|
+
const { from, to } = edge;
|
|
3431
|
+
return from.x === to.x ? "vertical" : "horizontal";
|
|
3432
|
+
};
|
|
3433
|
+
for (const mySegment of edges) {
|
|
3434
|
+
const mySegmentOrientation = edgeOrientation(mySegment);
|
|
3435
|
+
const findOverlappingParallelSegment = () => otherEdges.find(
|
|
3436
|
+
(otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine(
|
|
3437
|
+
[mySegment.from, mySegment.to],
|
|
3438
|
+
[otherEdge.from, otherEdge.to],
|
|
3439
|
+
{
|
|
3440
|
+
lineThickness: 0.01
|
|
3441
|
+
}
|
|
3442
|
+
)
|
|
3443
|
+
);
|
|
3444
|
+
let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
|
|
3445
|
+
while (overlappingParallelSegmentFromOtherTrace) {
|
|
3446
|
+
if (mySegmentOrientation === "horizontal") {
|
|
3447
|
+
mySegment.from.y += 0.1;
|
|
3448
|
+
mySegment.to.y += 0.1;
|
|
3449
|
+
} else {
|
|
3450
|
+
mySegment.from.x += 0.1;
|
|
3451
|
+
mySegment.to.x += 0.1;
|
|
3452
|
+
}
|
|
3453
|
+
overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
};
|
|
3457
|
+
|
|
3458
|
+
// lib/components/primitive-components/Trace/create-schematic-trace-crossing-segments.ts
|
|
3459
|
+
import { doesLineIntersectLine as doesLineIntersectLine2 } from "@tscircuit/math-utils";
|
|
3460
|
+
var createSchematicTraceCrossingSegments = ({
|
|
3461
|
+
edges,
|
|
3462
|
+
db
|
|
3463
|
+
}) => {
|
|
3464
|
+
const otherEdges = [];
|
|
3465
|
+
for (const otherSchematicTrace of db.schematic_trace.list()) {
|
|
3466
|
+
otherEdges.push(...otherSchematicTrace.edges);
|
|
3467
|
+
}
|
|
3468
|
+
for (let i = 0; i < edges.length; i++) {
|
|
3469
|
+
const edge = edges[i];
|
|
3470
|
+
const edgeOrientation = edge.from.x === edge.to.x ? "vertical" : "horizontal";
|
|
3471
|
+
for (const otherEdge of otherEdges) {
|
|
3472
|
+
const otherOrientation = otherEdge.from.x === otherEdge.to.x ? "vertical" : "horizontal";
|
|
3473
|
+
if (edgeOrientation === otherOrientation) continue;
|
|
3474
|
+
const intersection = doesLineIntersectLine2(
|
|
3475
|
+
[edge.from, edge.to],
|
|
3476
|
+
[otherEdge.from, otherEdge.to],
|
|
3477
|
+
{ lineThickness: 0.01 }
|
|
3478
|
+
);
|
|
3479
|
+
if (intersection) {
|
|
3480
|
+
const intersectX = edgeOrientation === "vertical" ? edge.from.x : otherEdge.from.x;
|
|
3481
|
+
const intersectY = edgeOrientation === "vertical" ? otherEdge.from.y : edge.from.y;
|
|
3482
|
+
const crossingSegmentLength = 0.1;
|
|
3483
|
+
const crossingPoint = { x: intersectX, y: intersectY };
|
|
3484
|
+
const beforeCrossing = {
|
|
3485
|
+
x: edgeOrientation === "vertical" ? crossingPoint.x : crossingPoint.x - crossingSegmentLength / 2,
|
|
3486
|
+
y: edgeOrientation === "vertical" ? crossingPoint.y - crossingSegmentLength / 2 : crossingPoint.y
|
|
3487
|
+
};
|
|
3488
|
+
const afterCrossing = {
|
|
3489
|
+
x: edgeOrientation === "vertical" ? crossingPoint.x : crossingPoint.x + crossingSegmentLength / 2,
|
|
3490
|
+
y: edgeOrientation === "vertical" ? crossingPoint.y + crossingSegmentLength / 2 : crossingPoint.y
|
|
3491
|
+
};
|
|
3492
|
+
const newEdges = [
|
|
3493
|
+
{ from: edge.from, to: beforeCrossing },
|
|
3494
|
+
{ from: beforeCrossing, to: afterCrossing, is_crossing: true },
|
|
3495
|
+
{ from: afterCrossing, to: edge.to }
|
|
3496
|
+
];
|
|
3497
|
+
edges.splice(i, 1, ...newEdges);
|
|
3498
|
+
i += 2;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3504
|
+
// lib/components/primitive-components/Trace/Trace.ts
|
|
3387
3505
|
var portToObjective = (port) => {
|
|
3388
3506
|
const portPosition = port._getGlobalPcbPositionAfterLayout();
|
|
3389
3507
|
return {
|
|
@@ -3397,6 +3515,7 @@ var Trace = class extends PrimitiveComponent {
|
|
|
3397
3515
|
pcb_trace_id = null;
|
|
3398
3516
|
schematic_trace_id = null;
|
|
3399
3517
|
_portsRoutedOnPcb;
|
|
3518
|
+
subcircuit_connectivity_map_key = null;
|
|
3400
3519
|
constructor(props) {
|
|
3401
3520
|
super(props);
|
|
3402
3521
|
this._portsRoutedOnPcb = [];
|
|
@@ -3860,37 +3979,8 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3860
3979
|
to: route[i + 1]
|
|
3861
3980
|
});
|
|
3862
3981
|
}
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
otherEdges.push(...otherSchematicTrace.edges);
|
|
3866
|
-
}
|
|
3867
|
-
const edgeOrientation = (edge) => {
|
|
3868
|
-
const { from, to } = edge;
|
|
3869
|
-
return from.x === to.x ? "vertical" : "horizontal";
|
|
3870
|
-
};
|
|
3871
|
-
for (const mySegment of edges) {
|
|
3872
|
-
const mySegmentOrientation = edgeOrientation(mySegment);
|
|
3873
|
-
const findOverlappingParallelSegment = () => otherEdges.find(
|
|
3874
|
-
(otherEdge) => edgeOrientation(otherEdge) === mySegmentOrientation && doesLineIntersectLine(
|
|
3875
|
-
[mySegment.from, mySegment.to],
|
|
3876
|
-
[otherEdge.from, otherEdge.to],
|
|
3877
|
-
{
|
|
3878
|
-
lineThickness: 0.01
|
|
3879
|
-
}
|
|
3880
|
-
)
|
|
3881
|
-
);
|
|
3882
|
-
let overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
|
|
3883
|
-
while (overlappingParallelSegmentFromOtherTrace) {
|
|
3884
|
-
if (mySegmentOrientation === "horizontal") {
|
|
3885
|
-
mySegment.from.y += 0.1;
|
|
3886
|
-
mySegment.to.y += 0.1;
|
|
3887
|
-
} else {
|
|
3888
|
-
mySegment.from.x += 0.1;
|
|
3889
|
-
mySegment.to.x += 0.1;
|
|
3890
|
-
}
|
|
3891
|
-
overlappingParallelSegmentFromOtherTrace = findOverlappingParallelSegment();
|
|
3892
|
-
}
|
|
3893
|
-
}
|
|
3982
|
+
pushEdgesOfSchematicTraceToPreventOverlap({ edges, db });
|
|
3983
|
+
createSchematicTraceCrossingSegments({ edges, db });
|
|
3894
3984
|
const lastEdge = edges[edges.length - 1];
|
|
3895
3985
|
const lastEdgePort = portsWithPosition[portsWithPosition.length - 1];
|
|
3896
3986
|
const lastDominantDirection = getDominantDirection(lastEdge);
|
|
@@ -3899,7 +3989,8 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
3899
3989
|
);
|
|
3900
3990
|
const trace = db.schematic_trace.insert({
|
|
3901
3991
|
source_trace_id: this.source_trace_id,
|
|
3902
|
-
edges
|
|
3992
|
+
edges,
|
|
3993
|
+
junctions: []
|
|
3903
3994
|
});
|
|
3904
3995
|
this.schematic_trace_id = trace.schematic_trace_id;
|
|
3905
3996
|
}
|
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.156",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@tscircuit/props": "^0.0.86",
|
|
44
44
|
"@tscircuit/schematic-autolayout": "^0.0.5",
|
|
45
45
|
"@tscircuit/soup-util": "^0.0.33",
|
|
46
|
-
"circuit-json": "^0.0.
|
|
46
|
+
"circuit-json": "^0.0.98",
|
|
47
47
|
"circuit-json-to-connectivity-map": "^0.0.17",
|
|
48
|
-
"circuit-to-svg": "^0.0.
|
|
48
|
+
"circuit-to-svg": "^0.0.64",
|
|
49
49
|
"format-si-unit": "^0.0.2",
|
|
50
50
|
"nanoid": "^5.0.7",
|
|
51
51
|
"performance-now": "^2.1.0",
|