@tscircuit/core 0.0.192 → 0.0.194
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 +28 -2
- package/dist/index.js +119 -57
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import React, { ReactElement } from 'react';
|
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
import { z, ZodType } from 'zod';
|
|
6
6
|
import { symbols, SchSymbol, BaseSymbolName } from 'schematic-symbols';
|
|
7
|
-
import { PcbTraceError, PcbPlacementError, LayerRef, AnyCircuitElement, AnySourceComponent, RouteHintPoint } from 'circuit-json';
|
|
7
|
+
import { PcbTraceError, PcbPlacementError, LayerRef, AnyCircuitElement, AnySourceComponent, PcbTrace, RouteHintPoint } from 'circuit-json';
|
|
8
8
|
import { Matrix } from 'transformation-matrix';
|
|
9
9
|
import { SoupUtilObjects } from '@tscircuit/soup-util';
|
|
10
10
|
import * as _tscircuit_layout from '@tscircuit/layout';
|
|
@@ -860,7 +860,8 @@ interface SimpleRouteJson {
|
|
|
860
860
|
|
|
861
861
|
declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps> extends NormalComponent<Props> implements ISubcircuit {
|
|
862
862
|
_asyncAutoroutingResult: {
|
|
863
|
-
output_simple_route_json
|
|
863
|
+
output_simple_route_json?: SimpleRouteJson;
|
|
864
|
+
output_pcb_traces?: PcbTrace[];
|
|
864
865
|
} | null;
|
|
865
866
|
get config(): {
|
|
866
867
|
zodProps: Props;
|
|
@@ -871,6 +872,8 @@ declare class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
|
|
|
871
872
|
doInitialSourceAddConnectivityMapKey(): void;
|
|
872
873
|
doInitialPcbTraceRender(): void;
|
|
873
874
|
updatePcbTraceRender(): void;
|
|
875
|
+
_updatePcbTraceRenderFromSimpleRouteJson(): void;
|
|
876
|
+
_updatePcbTraceRenderFromPcbTraces(): void;
|
|
874
877
|
doInitialSchematicLayout(): void;
|
|
875
878
|
/**
|
|
876
879
|
* Trace-by-trace autorouting is where each trace routes itself in a well-known
|
|
@@ -917,6 +920,19 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
917
920
|
minTraceWidth: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
|
|
918
921
|
partsEngine: z.ZodOptional<z.ZodType<_tscircuit_props.PartsEngine, z.ZodTypeDef, _tscircuit_props.PartsEngine>>;
|
|
919
922
|
pcbRouteCache: z.ZodOptional<z.ZodType<_tscircuit_props.PcbRouteCache, z.ZodTypeDef, _tscircuit_props.PcbRouteCache>>;
|
|
923
|
+
autorouter: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
924
|
+
serverUrl: z.ZodOptional<z.ZodString>;
|
|
925
|
+
inputFormat: z.ZodOptional<z.ZodEnum<["simplified", "circuit-json"]>>;
|
|
926
|
+
cache: z.ZodOptional<z.ZodType<_tscircuit_props.PcbRouteCache, z.ZodTypeDef, _tscircuit_props.PcbRouteCache>>;
|
|
927
|
+
}, "strip", z.ZodTypeAny, {
|
|
928
|
+
serverUrl?: string | undefined;
|
|
929
|
+
inputFormat?: "simplified" | "circuit-json" | undefined;
|
|
930
|
+
cache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
931
|
+
}, {
|
|
932
|
+
serverUrl?: string | undefined;
|
|
933
|
+
inputFormat?: "simplified" | "circuit-json" | undefined;
|
|
934
|
+
cache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
935
|
+
}>, z.ZodLiteral<"auto">, z.ZodLiteral<"auto-local">, z.ZodLiteral<"auto-cloud">]>>;
|
|
920
936
|
}>, {
|
|
921
937
|
width: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
|
|
922
938
|
height: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>>;
|
|
@@ -949,6 +965,11 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
949
965
|
defaultTraceWidth?: number | undefined;
|
|
950
966
|
minTraceWidth?: number | undefined;
|
|
951
967
|
pcbRouteCache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
968
|
+
autorouter?: "auto" | "auto-local" | "auto-cloud" | {
|
|
969
|
+
serverUrl?: string | undefined;
|
|
970
|
+
inputFormat?: "simplified" | "circuit-json" | undefined;
|
|
971
|
+
cache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
972
|
+
} | undefined;
|
|
952
973
|
schAutoLayoutEnabled?: boolean | undefined;
|
|
953
974
|
partsEngine?: _tscircuit_props.PartsEngine | undefined;
|
|
954
975
|
outline?: {
|
|
@@ -976,6 +997,11 @@ declare class Board extends Group<typeof boardProps> {
|
|
|
976
997
|
defaultTraceWidth?: string | number | undefined;
|
|
977
998
|
minTraceWidth?: string | number | undefined;
|
|
978
999
|
pcbRouteCache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
1000
|
+
autorouter?: "auto" | "auto-local" | "auto-cloud" | {
|
|
1001
|
+
serverUrl?: string | undefined;
|
|
1002
|
+
inputFormat?: "simplified" | "circuit-json" | undefined;
|
|
1003
|
+
cache?: _tscircuit_props.PcbRouteCache | undefined;
|
|
1004
|
+
} | undefined;
|
|
979
1005
|
schAutoLayoutEnabled?: boolean | undefined;
|
|
980
1006
|
partsEngine?: _tscircuit_props.PartsEngine | undefined;
|
|
981
1007
|
outline?: {
|
package/dist/index.js
CHANGED
|
@@ -131,10 +131,7 @@ var Renderable = class {
|
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}).catch((error) => {
|
|
134
|
-
console.error(
|
|
135
|
-
`Async effect error in ${this._currentRenderPhase}:`,
|
|
136
|
-
error
|
|
137
|
-
);
|
|
134
|
+
console.error(`Async effect error in ${asyncEffect.phase}:`, error);
|
|
138
135
|
asyncEffect.complete = true;
|
|
139
136
|
if ("root" in this && this.root) {
|
|
140
137
|
;
|
|
@@ -3221,8 +3218,63 @@ var TraceHint = class extends PrimitiveComponent {
|
|
|
3221
3218
|
|
|
3222
3219
|
// lib/components/primitive-components/Group/Group.ts
|
|
3223
3220
|
import * as SAL from "@tscircuit/schematic-autolayout";
|
|
3224
|
-
import
|
|
3221
|
+
import "@tscircuit/infgrid-ijump-astar";
|
|
3225
3222
|
import { ConnectivityMap } from "circuit-json-to-connectivity-map";
|
|
3223
|
+
|
|
3224
|
+
// lib/utils/autorouting/getSimpleRouteJsonFromTracesAndDb.ts
|
|
3225
|
+
import { getObstaclesFromSoup } from "@tscircuit/infgrid-ijump-astar";
|
|
3226
|
+
var getSimpleRouteJsonFromTracesAndDb = ({
|
|
3227
|
+
db,
|
|
3228
|
+
traces,
|
|
3229
|
+
minTraceWidth = 0.1
|
|
3230
|
+
}) => {
|
|
3231
|
+
const obstacles = getObstaclesFromSoup([
|
|
3232
|
+
...db.pcb_component.list(),
|
|
3233
|
+
...db.pcb_smtpad.list(),
|
|
3234
|
+
...db.pcb_plated_hole.list()
|
|
3235
|
+
]);
|
|
3236
|
+
const allPoints = obstacles.flatMap((o) => [
|
|
3237
|
+
{
|
|
3238
|
+
x: o.center.x - o.width / 2,
|
|
3239
|
+
y: o.center.y - o.height / 2
|
|
3240
|
+
},
|
|
3241
|
+
{
|
|
3242
|
+
x: o.center.x + o.width / 2,
|
|
3243
|
+
y: o.center.y + o.height / 2
|
|
3244
|
+
}
|
|
3245
|
+
]);
|
|
3246
|
+
const bounds = {
|
|
3247
|
+
minX: Math.min(...allPoints.map((p) => p.x)) - 1,
|
|
3248
|
+
maxX: Math.max(...allPoints.map((p) => p.x)) + 1,
|
|
3249
|
+
minY: Math.min(...allPoints.map((p) => p.y)) - 1,
|
|
3250
|
+
maxY: Math.max(...allPoints.map((p) => p.y)) + 1
|
|
3251
|
+
};
|
|
3252
|
+
const connections = traces.map((trace) => {
|
|
3253
|
+
const connectedPorts = trace._findConnectedPorts();
|
|
3254
|
+
if (!connectedPorts.allPortsFound || connectedPorts.ports.length < 2)
|
|
3255
|
+
return null;
|
|
3256
|
+
return {
|
|
3257
|
+
name: trace.source_trace_id ?? "",
|
|
3258
|
+
pointsToConnect: connectedPorts.ports.map((port) => {
|
|
3259
|
+
const pos = port._getGlobalPcbPositionBeforeLayout();
|
|
3260
|
+
return {
|
|
3261
|
+
x: pos.x,
|
|
3262
|
+
y: pos.y,
|
|
3263
|
+
layer: port.getAvailablePcbLayers()[0] ?? "top"
|
|
3264
|
+
};
|
|
3265
|
+
})
|
|
3266
|
+
};
|
|
3267
|
+
}).filter((c) => c !== null);
|
|
3268
|
+
return {
|
|
3269
|
+
bounds,
|
|
3270
|
+
obstacles: [],
|
|
3271
|
+
connections,
|
|
3272
|
+
layerCount: 2,
|
|
3273
|
+
minTraceWidth
|
|
3274
|
+
};
|
|
3275
|
+
};
|
|
3276
|
+
|
|
3277
|
+
// lib/components/primitive-components/Group/Group.ts
|
|
3226
3278
|
var Group = class extends NormalComponent {
|
|
3227
3279
|
_asyncAutoroutingResult = null;
|
|
3228
3280
|
get config() {
|
|
@@ -3250,50 +3302,11 @@ var Group = class extends NormalComponent {
|
|
|
3250
3302
|
_getSimpleRouteJsonFromPcbTraces() {
|
|
3251
3303
|
const traces = this.selectAll("trace");
|
|
3252
3304
|
const { db } = this.root;
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
...db.pcb_plated_hole.list()
|
|
3257
|
-
]);
|
|
3258
|
-
const allPoints = obstacles.flatMap((o) => [
|
|
3259
|
-
{
|
|
3260
|
-
x: o.center.x - o.width / 2,
|
|
3261
|
-
y: o.center.y - o.height / 2
|
|
3262
|
-
},
|
|
3263
|
-
{
|
|
3264
|
-
x: o.center.x + o.width / 2,
|
|
3265
|
-
y: o.center.y + o.height / 2
|
|
3266
|
-
}
|
|
3267
|
-
]);
|
|
3268
|
-
const bounds = {
|
|
3269
|
-
minX: Math.min(...allPoints.map((p) => p.x)) - 1,
|
|
3270
|
-
maxX: Math.max(...allPoints.map((p) => p.x)) + 1,
|
|
3271
|
-
minY: Math.min(...allPoints.map((p) => p.y)) - 1,
|
|
3272
|
-
maxY: Math.max(...allPoints.map((p) => p.y)) + 1
|
|
3273
|
-
};
|
|
3274
|
-
const connections = traces.map((trace) => {
|
|
3275
|
-
const connectedPorts = trace._findConnectedPorts();
|
|
3276
|
-
if (!connectedPorts.allPortsFound || connectedPorts.ports.length < 2)
|
|
3277
|
-
return null;
|
|
3278
|
-
return {
|
|
3279
|
-
name: trace.source_trace_id ?? "",
|
|
3280
|
-
pointsToConnect: connectedPorts.ports.map((port) => {
|
|
3281
|
-
const pos = port._getGlobalPcbPositionBeforeLayout();
|
|
3282
|
-
return {
|
|
3283
|
-
x: pos.x,
|
|
3284
|
-
y: pos.y,
|
|
3285
|
-
layer: port.getAvailablePcbLayers()[0] ?? "top"
|
|
3286
|
-
};
|
|
3287
|
-
})
|
|
3288
|
-
};
|
|
3289
|
-
}).filter((c) => c !== null);
|
|
3290
|
-
return {
|
|
3291
|
-
bounds,
|
|
3292
|
-
obstacles: [],
|
|
3293
|
-
connections,
|
|
3294
|
-
layerCount: 2,
|
|
3305
|
+
return getSimpleRouteJsonFromTracesAndDb({
|
|
3306
|
+
db,
|
|
3307
|
+
traces,
|
|
3295
3308
|
minTraceWidth: this._parsedProps.minTraceWidth ?? 0.1
|
|
3296
|
-
};
|
|
3309
|
+
});
|
|
3297
3310
|
}
|
|
3298
3311
|
doInitialSourceAddConnectivityMapKey() {
|
|
3299
3312
|
if (!this.isSubcircuit) return;
|
|
@@ -3326,18 +3339,38 @@ var Group = class extends NormalComponent {
|
|
|
3326
3339
|
}
|
|
3327
3340
|
doInitialPcbTraceRender() {
|
|
3328
3341
|
if (this._shouldUseTraceByTraceRouting()) return;
|
|
3329
|
-
|
|
3342
|
+
let serverUrl = this.props.autorouter?.serverUrl;
|
|
3343
|
+
if (this.props.autorouter === "auto-cloud") {
|
|
3344
|
+
serverUrl = "https://registry-api.tscircuit.com/autorouting/solve";
|
|
3345
|
+
}
|
|
3346
|
+
if (serverUrl) {
|
|
3330
3347
|
this._queueAsyncEffect(async () => {
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
{
|
|
3348
|
+
if (this.props.autorouter?.inputFormat === "simplified") {
|
|
3349
|
+
const { autorouting_result: autorouting_result2 } = await fetch(serverUrl, {
|
|
3334
3350
|
method: "POST",
|
|
3335
3351
|
body: JSON.stringify({
|
|
3336
3352
|
input_simple_route_json: this._getSimpleRouteJsonFromPcbTraces()
|
|
3337
|
-
})
|
|
3353
|
+
}),
|
|
3354
|
+
headers: {
|
|
3355
|
+
"Content-Type": "application/json"
|
|
3356
|
+
}
|
|
3357
|
+
}).then((r) => r.json());
|
|
3358
|
+
this._asyncAutoroutingResult = autorouting_result2;
|
|
3359
|
+
this._markDirty("PcbTraceRender");
|
|
3360
|
+
}
|
|
3361
|
+
const arRes = await fetch(serverUrl, {
|
|
3362
|
+
method: "POST",
|
|
3363
|
+
body: JSON.stringify({
|
|
3364
|
+
// TODO filter such that we're only using this subcircuit's
|
|
3365
|
+
// components
|
|
3366
|
+
input_circuit_json: this.root.db.toArray()
|
|
3367
|
+
}),
|
|
3368
|
+
headers: {
|
|
3369
|
+
"Content-Type": "application/json"
|
|
3338
3370
|
}
|
|
3339
|
-
)
|
|
3340
|
-
const
|
|
3371
|
+
});
|
|
3372
|
+
const resultText = await arRes.text();
|
|
3373
|
+
const { autorouting_result } = JSON.parse(resultText);
|
|
3341
3374
|
this._asyncAutoroutingResult = autorouting_result;
|
|
3342
3375
|
this._markDirty("PcbTraceRender");
|
|
3343
3376
|
});
|
|
@@ -3346,6 +3379,17 @@ var Group = class extends NormalComponent {
|
|
|
3346
3379
|
updatePcbTraceRender() {
|
|
3347
3380
|
if (!this._asyncAutoroutingResult) return;
|
|
3348
3381
|
if (this._shouldUseTraceByTraceRouting()) return;
|
|
3382
|
+
const { db } = this.root;
|
|
3383
|
+
if (this._asyncAutoroutingResult.output_simple_route_json) {
|
|
3384
|
+
this._updatePcbTraceRenderFromSimpleRouteJson();
|
|
3385
|
+
return;
|
|
3386
|
+
}
|
|
3387
|
+
if (this._asyncAutoroutingResult.output_pcb_traces) {
|
|
3388
|
+
this._updatePcbTraceRenderFromPcbTraces();
|
|
3389
|
+
return;
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
_updatePcbTraceRenderFromSimpleRouteJson() {
|
|
3349
3393
|
const { db } = this.root;
|
|
3350
3394
|
const { traces: routedTraces } = this._asyncAutoroutingResult.output_simple_route_json;
|
|
3351
3395
|
if (!routedTraces) return;
|
|
@@ -3357,6 +3401,14 @@ var Group = class extends NormalComponent {
|
|
|
3357
3401
|
});
|
|
3358
3402
|
}
|
|
3359
3403
|
}
|
|
3404
|
+
_updatePcbTraceRenderFromPcbTraces() {
|
|
3405
|
+
const { output_pcb_traces } = this._asyncAutoroutingResult;
|
|
3406
|
+
if (!output_pcb_traces) return;
|
|
3407
|
+
const { db } = this.root;
|
|
3408
|
+
for (const pcb_trace of output_pcb_traces) {
|
|
3409
|
+
db.pcb_trace.insert(pcb_trace);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3360
3412
|
doInitialSchematicLayout() {
|
|
3361
3413
|
if (!this.isSubcircuit) return;
|
|
3362
3414
|
const props = this._parsedProps;
|
|
@@ -3461,7 +3513,7 @@ var FTYPE = stringProxy;
|
|
|
3461
3513
|
// lib/components/primitive-components/Trace/Trace.ts
|
|
3462
3514
|
import {
|
|
3463
3515
|
MultilayerIjump,
|
|
3464
|
-
getObstaclesFromSoup as
|
|
3516
|
+
getObstaclesFromSoup as getObstaclesFromSoup3
|
|
3465
3517
|
} from "@tscircuit/infgrid-ijump-astar";
|
|
3466
3518
|
import { traceProps } from "@tscircuit/props";
|
|
3467
3519
|
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
|
|
@@ -4186,7 +4238,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4186
4238
|
this.root.db.toArray()
|
|
4187
4239
|
);
|
|
4188
4240
|
const [obstacles, errGettingObstacles] = tryNow(
|
|
4189
|
-
() =>
|
|
4241
|
+
() => getObstaclesFromSoup3(this.root.db.toArray())
|
|
4190
4242
|
// Remove as any when autorouting-dataset gets updated
|
|
4191
4243
|
);
|
|
4192
4244
|
if (errGettingObstacles) {
|
|
@@ -4380,6 +4432,16 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
|
|
|
4380
4432
|
connectedTo: []
|
|
4381
4433
|
});
|
|
4382
4434
|
}
|
|
4435
|
+
if (elm.type === "schematic_box") {
|
|
4436
|
+
obstacles.push({
|
|
4437
|
+
type: "rect",
|
|
4438
|
+
layers: ["top"],
|
|
4439
|
+
center: { x: elm.x, y: elm.y },
|
|
4440
|
+
width: elm.width,
|
|
4441
|
+
height: elm.width,
|
|
4442
|
+
connectedTo: []
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4383
4445
|
}
|
|
4384
4446
|
const portsWithPosition = connectedPorts.map(({ port }) => ({
|
|
4385
4447
|
port,
|
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.194",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@tscircuit/footprinter": "^0.0.77",
|
|
41
41
|
"@tscircuit/infgrid-ijump-astar": "^0.0.24",
|
|
42
42
|
"@tscircuit/math-utils": "^0.0.5",
|
|
43
|
-
"@tscircuit/props": "^0.0.
|
|
43
|
+
"@tscircuit/props": "^0.0.102",
|
|
44
44
|
"@tscircuit/schematic-autolayout": "^0.0.6",
|
|
45
45
|
"@tscircuit/soup-util": "^0.0.40",
|
|
46
46
|
"circuit-json": "^0.0.104",
|