-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update the source_trace name to save more info for later stage
- Loading branch information
1 parent
1fd1a9b
commit 2aefadb
Showing
5 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { | ||
AnyCircuitElement, | ||
SourceComponentBase, | ||
SourcePort, | ||
} from "circuit-json" | ||
|
||
interface SourcePortInfo { | ||
displayName: string | ||
} | ||
|
||
export function getCombinedSourcePortName( | ||
circuitElements: AnyCircuitElement[], | ||
connectedSourcePortIds: string[], | ||
): string { | ||
const portInfos: SourcePortInfo[] = [] | ||
|
||
for (const portId of connectedSourcePortIds) { | ||
// Find the source port | ||
const sourcePort = circuitElements.find( | ||
(el) => el.type === "source_port" && el.source_port_id === portId, | ||
) as SourcePort | undefined | ||
|
||
if (!sourcePort) continue | ||
|
||
// Find the associated component | ||
const sourceComponent = circuitElements.find( | ||
(el) => | ||
el.type === "source_component" && | ||
el.source_component_id === sourcePort.source_component_id, | ||
) as SourceComponentBase | ||
|
||
if (!sourceComponent) continue | ||
|
||
// Construct display name combining component name and port name | ||
const componentName = | ||
sourceComponent.name || sourceComponent.source_component_id | ||
const portName = | ||
sourcePort.name || sourcePort.pin_number?.toString() || portId | ||
|
||
portInfos.push({ | ||
displayName: `Pad${portName.replace("pin", "")}_${componentName}_${sourcePort.source_component_id}`, | ||
}) | ||
} | ||
|
||
return portInfos.map((p) => p.displayName).join("--") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect, test } from "bun:test" | ||
import { convertCircuitJsonToDsnString, parseDsnToCircuitJson } from "lib" | ||
import threeSubcircuitCircuitConnectedToSamePorts from "../assets/repro/three-subcircuit-connected-to-same-ports.json" | ||
import { su } from "@tscircuit/soup-util" | ||
|
||
test("circuit json -> dsn -> circuit json", async () => { | ||
const dsnFile = convertCircuitJsonToDsnString(threeSubcircuitCircuitConnectedToSamePorts as any) | ||
const circuitJson = parseDsnToCircuitJson(dsnFile) | ||
|
||
const source_trace = su(circuitJson).source_trace.list() | ||
expect(source_trace.length).toBe(2) | ||
|
||
const pcb_trace = su(circuitJson).pcb_trace.list() | ||
expect(pcb_trace.length).toBe(1) | ||
expect(pcb_trace[0].source_trace_id).toBe(source_trace[0].source_trace_id) | ||
|
||
// The other source_trace is having multiple connected_source_port_ids | ||
expect(source_trace[1].connected_source_port_ids.length).toBe(3) | ||
}) |