Skip to content
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
9 changes: 8 additions & 1 deletion lib/components/primitive-components/Trace/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export class Trace
this._portsRoutedOnPcb = []
}

/**
* Get the explicit trace thickness, supporting 'width' as an alias for 'thickness'
*/
_getExplicitTraceThickness(): number | undefined {
return this._parsedProps.thickness ?? this._parsedProps.width
}

get config() {
return {
zodProps: traceProps,
Expand Down Expand Up @@ -276,7 +283,7 @@ export class Trace
{ db },
) ?? props.maxLength,
display_name: displayName,
min_trace_thickness: props.thickness,
min_trace_thickness: this._getExplicitTraceThickness(),
})

this.source_trace_id = trace.source_trace_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function Trace_doInitialPcbManualTraceRender(trace: Trace) {
const { _parsedProps: props } = trace
const subcircuit = trace.getSubcircuit()

if (!props.pcbPath || props.pcbPath.length === 0) return
if (!props.pcbPath) return

const { allPortsFound, ports, portsWithSelectors } =
trace._findConnectedPorts()
Expand Down Expand Up @@ -57,7 +57,9 @@ export function Trace_doInitialPcbManualTraceRender(trace: Trace) {

const layer = anchorPort.getAvailablePcbLayers()[0] || "top"
const width =
props.thickness ?? trace.getSubcircuit()._parsedProps.minTraceWidth ?? 0.16
trace._getExplicitTraceThickness() ??
trace.getSubcircuit()._parsedProps.minTraceWidth ??
0.16

const anchorPos = anchorPort._getGlobalPcbPositionAfterLayout()
const otherPos = otherPort._getGlobalPcbPositionAfterLayout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ export function Trace_doInitialPcbTraceRender(trace: Trace) {
const pcbPortB = "pcb_port_id" in b ? b.pcb_port_id : null

const minTraceWidth =
trace.getSubcircuit()._parsedProps.minTraceWidth ?? 0.16
trace._getExplicitTraceThickness() ??
trace.getSubcircuit()._parsedProps.minTraceWidth ??
0.16

const ijump = new MultilayerIjump({
OBSTACLE_MARGIN: minTraceWidth * 2,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/autorouting/SimpleRouteJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type Obstacle = {
export interface SimpleRouteConnection {
name: string
source_trace_id?: string
width?: number // Trace width/thickness, falls back to minTraceWidth if not specified
pointsToConnect: Array<{
x: number
y: number
Expand Down
1 change: 1 addition & 0 deletions lib/utils/autorouting/getSimpleRouteJsonFromCircuitJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export const getSimpleRouteJsonFromCircuitJson = ({
connMap.getNetConnectedToId(trace.source_trace_id) ??
"",
source_trace_id: trace.source_trace_id,
width: trace.min_trace_thickness,
pointsToConnect: [
{
x: portA.x!,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@tscircuit/matchpack": "^0.0.16",
"@tscircuit/math-utils": "^0.0.29",
"@tscircuit/miniflex": "^0.0.4",
"@tscircuit/props": "0.0.371",
"@tscircuit/props": "0.0.378",
"@tscircuit/schematic-autolayout": "^0.0.6",
"@tscircuit/schematic-match-adapt": "^0.0.16",
"@tscircuit/schematic-trace-solver": "^0.0.41",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("trace pcbPath selectors can set thickness", async () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<resistor
name="R1"
resistance="10k"
footprint="0402"
pcbX={-3}
pcbY={0}
/>
<resistor name="R2" resistance="10k" footprint="0402" pcbX={3} pcbY={0} />
<trace
from=".R1 > .pin2"
to=".R2 > .pin1"
pcbPathRelativeTo=".R1 > .pin2"
pcbPath={[]}
thickness="0.5mm"
/>
</board>,
)

await circuit.renderUntilSettled()

const pcbTrace = circuit.db.pcb_trace.list()[0]
expect(pcbTrace).toBeDefined()
if (!pcbTrace) throw new Error("Expected trace to be routed")
expect(
pcbTrace.route
.filter((segment) => segment.route_type === "wire")
.every((segment) => segment.width === 0.5),
).toBe(true)

await expect(circuit).toMatchPcbSnapshot(
`${import.meta.path}-selectors-thickness`,
)
})
38 changes: 38 additions & 0 deletions tests/components/primitive-components/trace-width-alias.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("trace width prop works as alias for thickness", async () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<resistor
name="R1"
resistance="10k"
footprint="0402"
pcbX={-3}
pcbY={0}
/>
<resistor name="R2" resistance="10k" footprint="0402" pcbX={3} pcbY={0} />
<trace
from=".R1 > .pin2"
to=".R2 > .pin1"
pcbPath={[]}
{...({ width: "0.5mm" } as any)}
/>
</board>,
)

await circuit.renderUntilSettled()

const pcbTrace = circuit.db.pcb_trace.list()[0]
expect(pcbTrace).toBeDefined()
if (!pcbTrace) throw new Error("Expected trace to be routed")
expect(
pcbTrace.route
.filter((segment) => segment.route_type === "wire")
.every((segment) => segment.width === 0.5),
).toBe(true)

await expect(circuit).toMatchPcbSnapshot(import.meta.path)
})