diff --git a/bun.lockb b/bun.lockb index 8f32921..30fa02c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/Circuit.ts b/lib/Circuit.ts index 7c53563..f321863 100644 --- a/lib/Circuit.ts +++ b/lib/Circuit.ts @@ -1,5 +1,4 @@ -import type { AnySoupElement } from "@tscircuit/soup" -import type { LayerRef } from "circuit-json" +import type { AnyCircuitElement, LayerRef } from "circuit-json" import type { PrimitiveComponent } from "./components/base-components/PrimitiveComponent" import type { SoupUtilObjects } from "@tscircuit/soup-util" import { su } from "@tscircuit/soup-util" @@ -87,12 +86,12 @@ export class Circuit { this._hasRenderedAtleastOnce = true } - getSoup(): AnySoupElement[] { + getSoup(): AnyCircuitElement[] { if (!this._hasRenderedAtleastOnce) this.render() return this.db.toArray() } - getCircuitJson(): AnySoupElement[] { + getCircuitJson(): AnyCircuitElement[] { return this.getSoup() } @@ -103,7 +102,7 @@ export class Circuit { ) }) - return circuitToSvg.circuitJsonToPcbSvg(this.getCircuitJson()) + return circuitToSvg.convertCircuitJsonToPcbSvg(this.getCircuitJson()) } async preview( diff --git a/lib/components/base-components/NormalComponent.ts b/lib/components/base-components/NormalComponent.ts index 1f148eb..962ad0b 100644 --- a/lib/components/base-components/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent.ts @@ -131,7 +131,7 @@ export class NormalComponent< if (!footprint) return if (typeof footprint === "string") { const fpSoup = fp.string(footprint).soup() - const fpComponents = createComponentsFromSoup(fpSoup) + const fpComponents = createComponentsFromSoup(fpSoup as any) // Remove as any when footprinter gets updated this.addAll(fpComponents) } } diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index 74959b3..5360315 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -1,5 +1,5 @@ -import type { AnySoupElement, AnySourceComponent } from "@tscircuit/soup" import type { Circuit } from "../../Circuit" +import type { AnyCircuitElement, AnySourceComponent } from "circuit-json" import type { ZodType } from "zod" import { z } from "zod" import { symbols, type SchSymbol, type BaseSymbolName } from "schematic-symbols" @@ -507,7 +507,7 @@ export abstract class PrimitiveComponent< return super.renderError(message) } // TODO this needs to be cleaned up at some point! - this.root?.db.pcb_error.insert(message) + this.root?.db.pcb_placement_error.insert(message) } getString(): string { diff --git a/lib/components/base-components/Renderable.ts b/lib/components/base-components/Renderable.ts index e55bf8c..0fb39a3 100644 --- a/lib/components/base-components/Renderable.ts +++ b/lib/components/base-components/Renderable.ts @@ -1,4 +1,4 @@ -import type { PCBPlacementError, PCBTraceError } from "@tscircuit/soup" +import type { PCBPlacementError, PCBTraceError } from "circuit-json" import { Component, createElement, type ReactElement } from "react" export const orderedRenderPhases = [ diff --git a/lib/components/normal-components/Capacitor.ts b/lib/components/normal-components/Capacitor.ts index e6c71d8..b453c4a 100644 --- a/lib/components/normal-components/Capacitor.ts +++ b/lib/components/normal-components/Capacitor.ts @@ -1,7 +1,7 @@ import { capacitorProps, ledProps } from "@tscircuit/props" import { FTYPE, SYMBOL } from "lib/utils/constants" import { NormalComponent } from "../base-components/NormalComponent" -import type { capacitance, SourceSimpleCapacitorInput } from "@tscircuit/soup" +import type { capacitance, SourceSimpleCapacitorInput } from "circuit-json" import { Trace } from "../primitive-components/Trace" type PortNames = diff --git a/lib/components/normal-components/Resistor.ts b/lib/components/normal-components/Resistor.ts index 6e32f54..3751833 100644 --- a/lib/components/normal-components/Resistor.ts +++ b/lib/components/normal-components/Resistor.ts @@ -1,7 +1,7 @@ import { resistorProps } from "@tscircuit/props" import type { PassivePorts, Ftype, BaseSymbolName } from "lib/utils/constants" import { NormalComponent } from "../base-components/NormalComponent" -import type { SourceSimpleResistorInput } from "@tscircuit/soup" +import type { SourceSimpleResistorInput } from "circuit-json" import { z } from "zod" import { Trace } from "../primitive-components/Trace" import { Net } from "../primitive-components/Net" diff --git a/lib/components/primitive-components/Hole.ts b/lib/components/primitive-components/Hole.ts index 5b429e2..e0c8f75 100644 --- a/lib/components/primitive-components/Hole.ts +++ b/lib/components/primitive-components/Hole.ts @@ -1,6 +1,6 @@ import { PrimitiveComponent } from "../base-components/PrimitiveComponent" import { holeProps } from "@tscircuit/props" -import type { PCBHole } from "@tscircuit/soup" +import type { PCBHole } from "circuit-json" export class Hole extends PrimitiveComponent { pcb_hole_id: string | null = null diff --git a/lib/components/primitive-components/Keepout.ts b/lib/components/primitive-components/Keepout.ts index 56ec860..4f1314a 100644 --- a/lib/components/primitive-components/Keepout.ts +++ b/lib/components/primitive-components/Keepout.ts @@ -1,7 +1,7 @@ import { PrimitiveComponent } from "../base-components/PrimitiveComponent" import { pcbKeepoutProps } from "@tscircuit/props" import type { RenderPhaseFn } from "../base-components/Renderable" -import type { PCBKeepout } from "@tscircuit/soup" +import type { PCBKeepout } from "circuit-json" import { decomposeTSR } from "transformation-matrix" export class Keepout extends PrimitiveComponent { diff --git a/lib/components/primitive-components/Net.ts b/lib/components/primitive-components/Net.ts index 1642438..0c417d6 100644 --- a/lib/components/primitive-components/Net.ts +++ b/lib/components/primitive-components/Net.ts @@ -3,7 +3,7 @@ import { z } from "zod" import type { Port } from "./Port" import type { Trace } from "./Trace" import { pairs } from "lib/utils/pairs" -import type { AnySoupElement, SourceTrace } from "@tscircuit/soup" +import type { AnyCircuitElement, SourceTrace } from "circuit-json" import { autoroute } from "@tscircuit/infgrid-ijump-astar" export const netProps = z.object({ @@ -134,7 +134,7 @@ export class Net extends PrimitiveComponent { const Aport = A.ports[closestPair[0]] const Bport = B.ports[closestPair[1]] - const pcbElements: AnySoupElement[] = db + const pcbElements: AnyCircuitElement[] = db .toArray() .filter( (elm) => @@ -156,7 +156,7 @@ export class Net extends PrimitiveComponent { Bport.source_port_id!, ], } as SourceTrace, - ]), + ]) as any, // Remove as any when autorouting-dataset has been updated ) const trace = solution[0] diff --git a/lib/components/primitive-components/PlatedHole.ts b/lib/components/primitive-components/PlatedHole.ts index 68079e0..d1fe563 100644 --- a/lib/components/primitive-components/PlatedHole.ts +++ b/lib/components/primitive-components/PlatedHole.ts @@ -1,7 +1,7 @@ import { PrimitiveComponent } from "../base-components/PrimitiveComponent" import { platedHoleProps } from "@tscircuit/props" import type { Port } from "./Port" -import type { PCBPlatedHoleInput } from "@tscircuit/soup" +import type { PCBPlatedHoleInput } from "circuit-json" export class PlatedHole extends PrimitiveComponent { pcb_plated_hole_id: string | null = null @@ -93,7 +93,7 @@ export class PlatedHole extends PrimitiveComponent { const pcb_plated_hole = db.pcb_plated_hole.insert({ pcb_component_id, pcb_port_id: this.matchedPort?.pcb_port_id!, - // @ts-ignore - some issue with @tscircuit/soup union type + // @ts-ignore - some issue with circuit-json union type outer_diameter: props.outerDiameter, hole_diameter: props.holeDiameter, shape: "circle" as const, diff --git a/lib/components/primitive-components/Port.ts b/lib/components/primitive-components/Port.ts index f0281e5..c528884 100644 --- a/lib/components/primitive-components/Port.ts +++ b/lib/components/primitive-components/Port.ts @@ -1,4 +1,4 @@ -import type { PCBSMTPad } from "@tscircuit/soup" +import type { PCBSMTPad } from "circuit-json" import { PrimitiveComponent } from "../base-components/PrimitiveComponent" import { z } from "zod" import { getRelativeDirection } from "lib/utils/get-relative-direction" diff --git a/lib/components/primitive-components/SmtPad.ts b/lib/components/primitive-components/SmtPad.ts index 515ea15..d596ce1 100644 --- a/lib/components/primitive-components/SmtPad.ts +++ b/lib/components/primitive-components/SmtPad.ts @@ -2,7 +2,7 @@ import { PrimitiveComponent } from "../base-components/PrimitiveComponent" import { smtPadProps } from "@tscircuit/props" import type { Port } from "./Port" import type { RenderPhaseFn } from "../base-components/Renderable" -import type { LayerRef, PCBSMTPad } from "@tscircuit/soup" +import type { LayerRef, PCBSMTPad } from "circuit-json" import { applyToPoint, compose, @@ -12,6 +12,7 @@ import { translate, } from "transformation-matrix" + export class SmtPad extends PrimitiveComponent { pcb_smtpad_id: string | null = null diff --git a/lib/components/primitive-components/Trace.ts b/lib/components/primitive-components/Trace.ts index bfef2d8..78a31b2 100644 --- a/lib/components/primitive-components/Trace.ts +++ b/lib/components/primitive-components/Trace.ts @@ -9,13 +9,13 @@ import { markObstaclesAsConnected, } from "@tscircuit/infgrid-ijump-astar" import type { - AnySoupElement, + AnyCircuitElement, LayerRef, PCBTrace, RouteHintPoint, SchematicTrace, SourceTrace, -} from "@tscircuit/soup" +} from "circuit-json" import type { Obstacle, SimpleRouteConnection, @@ -379,14 +379,15 @@ export class Trace extends PrimitiveComponent { // Cache the PCB obstacles, they'll be needed for each segment between // ports/hints - const [obstacles, errGettingObstacles] = tryNow(() => - getObstaclesFromSoup(this.root!.db.toArray()), + const [obstacles, errGettingObstacles] = tryNow( + () => getObstaclesFromSoup(this.root!.db.toArray() as any), // Remove as any when autorouting-dataset gets updated ) if (errGettingObstacles) { this.renderError({ - type: "pcb_error", + type: "pcb_trace_error", error_type: "pcb_trace_error", + pcb_trace_error_id: this.pcb_trace_id!, message: `Error getting obstacles for autorouting: ${errGettingObstacles.message}`, source_trace_id: this.source_trace_id!, center: { x: 0, y: 0 }, @@ -484,10 +485,11 @@ export class Trace extends PrimitiveComponent { traces = ijump.solveAndMapToTraces() } catch (e: any) { this.renderError({ - type: "pcb_error", + type: "pcb_trace_error", + pcb_trace_error_id: this.source_trace_id!, error_type: "pcb_trace_error", message: `error solving route: ${e.message}`, - source_trace_id: this.source_trace_id!, + source_trace_id: this.pcb_trace_id!, center: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }, pcb_port_ids: ports.map((p) => p.pcb_port_id!), pcb_trace_id: this.pcb_trace_id!, @@ -497,8 +499,9 @@ export class Trace extends PrimitiveComponent { if (!traces) return if (traces.length === 0) { this.renderError({ - type: "pcb_error", + type: "pcb_trace_error", error_type: "pcb_trace_error", + pcb_trace_error_id: this.pcb_trace_id!, message: `Could not find a route for ${this}`, source_trace_id: this.source_trace_id!, center: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }, @@ -533,9 +536,17 @@ export class Trace extends PrimitiveComponent { const mergedRoute = mergeRoutes(routes) + const pcb_trace = db.pcb_trace.insert({ + route: mergedRoute, + source_trace_id: this.source_trace_id!, + }) + this._portsRoutedOnPcb = ports + this.pcb_trace_id = pcb_trace.pcb_trace_id + for (const point of mergedRoute) { if (point.route_type === "via") { db.pcb_via.insert({ + pcb_trace_id: pcb_trace.pcb_trace_id, x: point.x, y: point.y, hole_diameter: 0.3, @@ -546,13 +557,6 @@ export class Trace extends PrimitiveComponent { }) } } - - const pcb_trace = db.pcb_trace.insert({ - route: mergedRoute, - source_trace_id: this.source_trace_id!, - }) - this._portsRoutedOnPcb = ports - this.pcb_trace_id = pcb_trace.pcb_trace_id } doInitialSchematicTraceRender(): void { diff --git a/lib/components/primitive-components/TraceHint.ts b/lib/components/primitive-components/TraceHint.ts index a3ffb63..1410a83 100644 --- a/lib/components/primitive-components/TraceHint.ts +++ b/lib/components/primitive-components/TraceHint.ts @@ -1,7 +1,7 @@ import { PrimitiveComponent } from "lib/components/base-components/PrimitiveComponent" import { traceHintProps } from "@tscircuit/props" import type { Port } from "./Port" -import type { RouteHintPoint } from "@tscircuit/soup" +import type { RouteHintPoint } from "circuit-json" import { applyToPoint } from "transformation-matrix" export class TraceHint extends PrimitiveComponent { diff --git a/lib/soup/underscorifyPinStyles.ts b/lib/soup/underscorifyPinStyles.ts index b941240..4656c20 100644 --- a/lib/soup/underscorifyPinStyles.ts +++ b/lib/soup/underscorifyPinStyles.ts @@ -1,5 +1,5 @@ import type { SchematicPinStyle } from "@tscircuit/props" -import { schematic_component } from "@tscircuit/soup" +import { schematic_component } from "circuit-json" import { z } from "zod" type UnderscorePinStyles = z.input["pin_styles"] diff --git a/lib/soup/underscorifyPortArrangement.ts b/lib/soup/underscorifyPortArrangement.ts index 969e240..2220548 100644 --- a/lib/soup/underscorifyPortArrangement.ts +++ b/lib/soup/underscorifyPortArrangement.ts @@ -1,4 +1,4 @@ -import type { SchematicComponentInput } from "@tscircuit/soup" +import type { SchematicComponentInput } from "circuit-json" import type { PortArrangement } from "lib/utils/schematic/getAllDimensionsForSchematicBox" export const underscorifyPortArrangement = ( diff --git a/lib/utils/autorouting/mergeRoutes.ts b/lib/utils/autorouting/mergeRoutes.ts index 4c77273..f0529a7 100644 --- a/lib/utils/autorouting/mergeRoutes.ts +++ b/lib/utils/autorouting/mergeRoutes.ts @@ -1,4 +1,4 @@ -import type { PCBTrace } from "@tscircuit/soup" +import type { PCBTrace } from "circuit-json" function pdist(a: any, b: any) { return Math.hypot(a.x - b.x, a.y - b.y) diff --git a/lib/utils/constants.ts b/lib/utils/constants.ts index 67044c9..4c565f1 100644 --- a/lib/utils/constants.ts +++ b/lib/utils/constants.ts @@ -1,4 +1,4 @@ -import type { AnySourceComponent } from "@tscircuit/soup" +import type { AnySourceComponent } from "circuit-json" import type { BaseSymbolName } from "schematic-symbols" /** diff --git a/lib/utils/createComponentsFromSoup.ts b/lib/utils/createComponentsFromSoup.ts index 6eabd4d..93524e6 100644 --- a/lib/utils/createComponentsFromSoup.ts +++ b/lib/utils/createComponentsFromSoup.ts @@ -1,4 +1,4 @@ -import type { AnySoupElement } from "@tscircuit/soup" +import type { AnyCircuitElement } from "circuit-json" import type { PrimitiveComponent } from "../components/base-components/PrimitiveComponent" import { SmtPad } from "lib/components/primitive-components/SmtPad" import { SilkscreenPath } from "lib/components/primitive-components/SilkscreenPath" @@ -6,7 +6,7 @@ import { PlatedHole } from "lib/components/primitive-components/PlatedHole" import { Keepout } from "lib/components/primitive-components/Keepout" export const createComponentsFromSoup = ( - soup: AnySoupElement[], + soup: AnyCircuitElement[], ): PrimitiveComponent[] => { const components: PrimitiveComponent[] = [] for (const elm of soup) { diff --git a/lib/utils/schematic/getAllDimensionsForSchematicBox.ts b/lib/utils/schematic/getAllDimensionsForSchematicBox.ts index 33b47de..ab771da 100644 --- a/lib/utils/schematic/getAllDimensionsForSchematicBox.ts +++ b/lib/utils/schematic/getAllDimensionsForSchematicBox.ts @@ -1,4 +1,4 @@ -import { current } from "@tscircuit/soup" +import { current } from "circuit-json" import { getSizeOfSidesFromPortArrangement } from "./getSizeOfSidesFromPortArrangement" import { schematicPortArrangement } from "@tscircuit/props" import { z } from "zod" diff --git a/package.json b/package.json index 903218f..c42ae60 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@types/react": "^18.3.3", "@types/react-reconciler": "^0.28.8", "bun-match-svg": "0.0.2", - "circuit-to-svg": "^0.0.36", + "circuit-to-svg": "^0.0.37", "debug": "^4.3.6", "howfat": "^0.3.8", "looks-same": "^9.0.1", @@ -35,10 +35,9 @@ "@tscircuit/infgrid-ijump-astar": "^0.0.21", "@tscircuit/math-utils": "^0.0.4", "@tscircuit/props": "^0.0.65", - "@tscircuit/soup": "^0.0.73", - "@tscircuit/soup-util": "^0.0.28", - "circuit-json": "^0.0.77", - "circuit-json-to-connectivity-map": "^0.0.15", + "circuit-json": "^0.0.78", + "@tscircuit/soup-util": "^0.0.31", + "circuit-json-to-connectivity-map": "^0.0.17", "footprinter": "^0.0.44", "nanoid": "^5.0.7", "performance-now": "^2.1.0", diff --git a/tests/fixtures/extend-expect-circuit-snapshot.ts b/tests/fixtures/extend-expect-circuit-snapshot.ts index fc04062..98fef09 100644 --- a/tests/fixtures/extend-expect-circuit-snapshot.ts +++ b/tests/fixtures/extend-expect-circuit-snapshot.ts @@ -1,10 +1,10 @@ -import { circuitJsonToPcbSvg, circuitJsonToSchematicSvg } from "circuit-to-svg" +import { circuitJsonToPcbSvg, circuitJsonToSchematicSvg, convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg } from "circuit-to-svg" import { it, expect, type CustomMatcher, type MatcherResult } from "bun:test" import * as fs from "node:fs" import * as path from "node:path" import looksSame from "looks-same" -import type { AnySoupElement } from "@tscircuit/soup" import { Circuit } from "lib/Circuit" +import type { AnyCircuitElement } from "circuit-json" async function saveSnapshotOfSoup({ soup, @@ -12,7 +12,7 @@ async function saveSnapshotOfSoup({ mode, updateSnapshot, }: { - soup: AnySoupElement[] + soup: AnyCircuitElement[] testPath: string mode: "pcb" | "schematic" updateSnapshot: boolean @@ -23,7 +23,7 @@ async function saveSnapshotOfSoup({ const filePath = path.join(snapshotDir, snapshotName) const svg = - mode === "pcb" ? circuitJsonToPcbSvg(soup) : circuitJsonToSchematicSvg(soup) + mode === "pcb" ? convertCircuitJsonToPcbSvg(soup) : convertCircuitJsonToSchematicSvg(soup) if (!fs.existsSync(snapshotDir)) { fs.mkdirSync(snapshotDir, { recursive: true }) @@ -78,7 +78,7 @@ expect.extend({ ): Promise { const soup = await (received instanceof Circuit ? received.getCircuitJson() - : (received as AnySoupElement[])) + : (received as AnyCircuitElement[])) return saveSnapshotOfSoup({ soup, @@ -99,7 +99,7 @@ expect.extend({ soup: received instanceof Circuit ? received.getSoup() - : (received as AnySoupElement[]), + : (received as AnyCircuitElement[]), testPath: args[0], mode: "schematic", updateSnapshot: