Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pcb_trace_id unique for the same wire segment #88

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function convertDsnSessionToCircuitJson(
}

const sessionElements: AnyCircuitElement[] = []
const routeSegments: Array<PcbTrace | SourceTrace> = []

// Process nets for vias and wires
for (const net of dsnSession.routes.network_out.nets) {
Expand All @@ -87,18 +86,10 @@ export function convertDsnSessionToCircuitJson(
// Process wires and vias together in routes
net.wires?.forEach((wire, wireIdx) => {
if ("path" in wire) {
routeSegments.push(
...convertWiringPathToPcbTraces({
wire,
transformUmToMm,
netName: net.name,
}),
)

const traces = convertWiringPathToPcbTraces({
wire,
transformUmToMm,
netName: net.name,
netName: `${net.name}_${wireIdx}`,
})

// Update trace IDs to maintain proper linkage
Expand Down
9 changes: 8 additions & 1 deletion tests/dsn-pcb/convert-session-to-circuit-json.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { convertDsnJsonToCircuitJson } from "../../lib/dsn-pcb/dsn-json-to-circuit-json/convert-dsn-json-to-circuit-json.ts"
import { expect, test } from "bun:test"
import {
parseDsnToDsnJson,
Expand All @@ -21,6 +20,7 @@ import pcbDsnFile from "../assets/freerouting-sessions/circuit1.dsn" with {
import { circuitJsonToTable } from "../debug-utils/circuit-json-to-table.ts"
import { sessionFileToTable } from "../debug-utils/index.ts"
import Debug from "debug"
import { su } from "@tscircuit/soup-util"

test("convert session to circuit json", async () => {
const debug = Debug("tscircuit:dsn-converter")
Expand All @@ -33,6 +33,13 @@ test("convert session to circuit json", async () => {
sessionJson,
)

const pcb_traces = su(circuitJsonFromSession).pcb_trace.list()
const pcb_traces_by_id = [
...new Set(pcb_traces.map((trace) => trace.pcb_trace_id)),
]

expect(pcb_traces_by_id.length).toBe(3)

if (debug.enabled) {
circuitJsonToTable(
circuitJson,
Expand Down