Skip to content

Commit

Permalink
fix: autorouter is inhertited by the subcircuit child (#610)
Browse files Browse the repository at this point in the history
* fix: autorouter is inhertited by the subcircuit child

* formatbot: Automatically format code

* use the fake auto cloud

* using the subcircuit prop

* inherit from parent

* formatbot: Automatically format code

---------

Co-authored-by: tscircuitbot <[email protected]>
  • Loading branch information
imrishabh18 and tscircuitbot authored Feb 9, 2025
1 parent 0b88964 commit b0c8b57
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 156 deletions.
10 changes: 6 additions & 4 deletions lib/components/primitive-components/Group/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,12 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
* or if using a "fullview" or "rip and replace" autorouting mode
*/
_shouldUseTraceByTraceRouting(): boolean {
const props = this._parsedProps as SubcircuitGroupProps
if (props.autorouter === "auto-local") return true
if (props.autorouter === "sequential-trace") return true
if (props.autorouter) return false
// Inherit from parent if not set by props
const autorouter =
this._parsedProps.autorouter ?? this.getInheritedProperty("autorouter")
if (autorouter === "auto-local") return true
if (autorouter === "sequential-trace") return true
if (autorouter) return false
return true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
209 changes: 72 additions & 137 deletions tests/examples/example19-subcircuit-overlap-traces.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"
import { su } from "@tscircuit/soup-util"
import { getTestAutoroutingServer } from "tests/fixtures/get-test-autorouting-server"

test("If the subcircuit is routing disabled, it should not have traces from the autorouter but it does have", async () => {
test.skip("If the subcircuit is routing disabled, it should not have traces from the autorouter but it does have", async () => {
const { circuit } = getTestFixture()

circuit.add(
Expand Down Expand Up @@ -82,11 +83,18 @@ test("If the subcircuit is routing disabled, it should not have traces from the
`)
})

test("It is having traces from both autorouter and freerouting (Not in the final circuit json)", async () => {
test("Autorouter should not create traces if the parent subcircuit has async autorouter enabled", async () => {
const { circuit } = getTestFixture()
const { autoroutingServerUrl } = getTestAutoroutingServer()

const cloudAutorouterConfig = {
serverUrl: autoroutingServerUrl,
serverMode: "solve-endpoint",
inputFormat: "simplified",
} as const

circuit.add(
<board width="10mm" height="10mm" autorouter="auto-cloud">
<board width="10mm" height="10mm" autorouter={cloudAutorouterConfig}>
<group subcircuit>
<resistor footprint="0402" resistance={1000} name="R1" pcbX={-2} />
<resistor footprint="0402" resistance={1000} name="R2" pcbX={2} />
Expand All @@ -99,139 +107,66 @@ test("It is having traces from both autorouter and freerouting (Not in the final

const pcb_traces = su(circuit.getCircuitJson()).pcb_trace.list()
expect(pcb_traces).toMatchInlineSnapshot(`
[
{
"pcb_trace_id": "pcb_trace_0",
"route": [
{
"layer": "top",
"route_type": "wire",
"start_pcb_port_id": "pcb_port_0",
"width": 0.16,
"x": -2.5,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 1.3,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 1.3,
},
{
"end_pcb_port_id": "pcb_port_2",
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 0,
},
],
"source_trace_id": "source_trace_0",
"trace_length": 6.6,
"type": "pcb_trace",
},
{
"pcb_trace_id": "pcb_trace_source_trace_0--Pad1_R1_source_component_0--Pad1_R2_source_component_1",
"route": [
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.5,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 1.3,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 1.3,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 0,
},
],
"source_trace_id": "source_trace_0",
"trace_length": 6.6,
"type": "pcb_trace",
},
{
"pcb_trace_id": "pcb_trace_Net-(R1_source_component_0-Pad1)",
"route": [
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.5,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.12,
"y": 1.3,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 1.3,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 0,
},
],
"source_trace_id": "source_trace_0",
"trace_length": 6.6,
"type": "pcb_trace",
},
]
`)
[
{
"pcb_trace_id": "pcb_trace_Net-(R1_source_component_0-Pad1)",
"route": [
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 1.5,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 0.9483,
"y": 0,
},
],
"source_trace_id": "source_trace_0",
"trace_length": 0.5517,
"type": "pcb_trace",
},
{
"pcb_trace_id": "pcb_trace_Net-(R1_source_component_0-Pad1)",
"route": [
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 0.9483,
"y": 0,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": 0.3966,
"y": -0.5517,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -1.9483,
"y": -0.5517,
},
{
"layer": "top",
"route_type": "wire",
"width": 0.16,
"x": -2.5,
"y": 0,
},
],
"source_trace_id": "source_trace_0",
"trace_length": 3.9053,
"type": "pcb_trace",
},
]
`)
expect(circuit.getCircuitJson()).toMatchPcbSnapshot(import.meta.path)
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 18 additions & 13 deletions tests/subcircuits/subcircuit3-dependent-autorouting.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ test("subcircuit3-dependent-autorouting", async () => {
// Check the order of the async effect, should be S1 then board, and S2 is
// synchronously routed so has no effect
expect(asyncEffectEndEvents).toMatchInlineSnapshot(`
[
{
"componentDisplayName": "<group# name=".S1" />",
"effectName": "make-http-autorouting-request",
"phase": "PcbTraceRender",
},
{
"componentDisplayName": "<board# />",
"effectName": "make-http-autorouting-request",
"phase": "PcbTraceRender",
},
]
`)
[
{
"componentDisplayName": "<group# name=".S1" />",
"effectName": "make-http-autorouting-request",
"phase": "PcbTraceRender",
},
{
"componentDisplayName": "<board# />",
"effectName": "make-http-autorouting-request",
"phase": "PcbTraceRender",
},
{
"componentDisplayName": "<group# name=".S2" />",
"effectName": "make-http-autorouting-request",
"phase": "PcbTraceRender",
},
]
`)

// Check if the circuit matches the expected PCB snapshot
expect(circuit).toMatchPcbSnapshot(import.meta.path)
Expand Down

0 comments on commit b0c8b57

Please sign in to comment.