Skip to content

Commit

Permalink
Merge pull request #101 from tscircuit/feature/traceHint-trace-width-…
Browse files Browse the repository at this point in the history
…prop

feat: add trace width
  • Loading branch information
imrishabh18 authored Aug 13, 2024
2 parents 964f52e + 260c688 commit b15e537
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
21 changes: 10 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"@semantic-release/release-notes-generator": "^10.0.3",
"@tscircuit/footprinter": "^0.0.44",
"@tscircuit/log-soup": "^1.0.2",
"@tscircuit/props": "^0.0.21",
"@tscircuit/props": "^0.0.27",
"@tscircuit/soup": "^0.0.49",
"@tscircuit/soup-util": "^0.0.13",
"@types/node": "^22.0.0",
"ava": "^4.3.3",
Expand Down
33 changes: 16 additions & 17 deletions src/lib/builder/trace-builder/build-pcb-trace-elements.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { BuildContext } from "lib/types"
import type {
AnySoupElement,
PCBTraceError,
SourcePort,
InputPoint,
PCBPort,
PCBTrace,
PCBTraceError,
PCBVia,
PCBPort,
SourcePort,
} from "@tscircuit/soup"
import { TracePcbRoutingContext } from "./pcb-routing/trace-pcb-routing-context"
import { su } from "@tscircuit/soup-util"
import { solveForRoute } from "./pcb-routing/solve-for-route"
import { findPossibleTraceLayerCombinations } from "./pcb-routing/find-possible-trace-layer-combinations"
import { createNoCommonLayersError } from "./pcb-errors"
import Debug from "debug"
import type { BuildContext } from "lib/types"
import { pairs } from "lib/utils/pairs"
import { mergeRoutes } from "./pcb-routing/merge-routes"
import { createNoCommonLayersError } from "./pcb-errors"
import { findPossibleTraceLayerCombinations } from "./pcb-routing/find-possible-trace-layer-combinations"
import { getPcbObstacles } from "./pcb-routing/get-pcb-obstacles"
import Debug from "debug"
import { mergeRoutes } from "./pcb-routing/merge-routes"
import { solveForRoute } from "./pcb-routing/solve-for-route"
import type { TracePcbRoutingContext } from "./pcb-routing/trace-pcb-routing-context"

const debug = Debug("tscircuit:builder:trace-builder")

Expand Down Expand Up @@ -98,11 +98,11 @@ export const buildPcbTraceElements = (
pcb_port_id: pcb_terminal_port_ids[1],
})

if (port0_hint) {
pcb_route_hints.push(...port0_hint.route)
if (port0_hint && port0_hint.route !== undefined) {
pcb_route_hints.push(...port0_hint.route.map((p) => p ?? { x: 0, y: 0 }))
}
if (port1_hint) {
pcb_route_hints.push(...[...port1_hint.route].reverse())
pcb_route_hints.push(...port1_hint.route.map((p) => p ?? { x: 0, y: 0 }))
}
}

Expand Down Expand Up @@ -140,21 +140,20 @@ export const buildPcbTraceElements = (
...t,
via_to_layer: layer_selection[idx],
}
} else {
return { ...t, layers: [layer_selection[idx]] }
}
return { ...t, layers: [layer_selection[idx]] }
}
)

for (let [a, b] of pairs(ordered_with_layer_hints)) {
for (const [a, b] of pairs(ordered_with_layer_hints)) {
routes.push(solveForRoute([a, b], pcb_routing_ctx))
}
if (routes.some((route) => route.length === 0)) {
pcb_errors.push({
pcb_error_id: bc.getId("pcb_error"),
type: "pcb_error",
error_type: "pcb_trace_error",
message: `No route could be found for terminals`,
message: "No route could be found for terminals",
pcb_trace_id,
source_trace_id,
pcb_component_ids: [], // TODO
Expand Down
24 changes: 9 additions & 15 deletions src/lib/builder/trace-hint-builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import {
route_hint_point,
type TraceHintProps as TraceHintPropsInput,
traceHintProps,
} from "@tscircuit/props"
import {
type AnySoupElement,
type PcbTraceHint,
type RouteHintPoint,
route_hint_point,
} from "@tscircuit/soup"
import { su } from "@tscircuit/soup-util"
import { applySelector } from "lib/apply-selector"
import type { BuildContext } from "lib/types"
import { z } from "zod"
import type { BuilderInterface } from "../builder-interface"
import type { ProjectBuilder } from "../project-builder"

const trace_hints_props = z.object({
for: z.string(),
order: z.number().optional(),
offset: route_hint_point.optional(),
offsets: z.array(route_hint_point).optional(),
})

type TraceHintProps = z.infer<typeof trace_hints_props>
type TraceHintPropsInput = z.input<typeof trace_hints_props>

export interface TraceHintBuilder extends BuilderInterface {
setProps(new_props: Partial<TraceHintPropsInput>): this
build(parent_elements: AnySoupElement[], bc: BuildContext): AnySoupElement[]
Expand All @@ -45,7 +38,7 @@ class TraceHintBuilderClass {
}

build(parent_elements: AnySoupElement[], bc: BuildContext): AnySoupElement[] {
const props = trace_hints_props.parse(this.props)
const props = traceHintProps.parse(this.props)
if (!props.for) {
// TODO source error
throw new Error("TraceHintBuilder requires a 'for' prop")
Expand All @@ -59,7 +52,7 @@ class TraceHintBuilderClass {
}
if (target_elms.length > 1) {
// TODO source error
throw new Error(`<tracehint /> does not yet support multiple selectors`)
throw new Error("<tracehint /> does not yet support multiple selectors")
}

const [target_elm] = target_elms
Expand Down Expand Up @@ -103,7 +96,7 @@ class TraceHintBuilderClass {

if (route.length === 0) {
// TODO source error
throw new Error(`No route defined for tracehint (try adding an offset)`)
throw new Error("No route defined for tracehint (try adding an offset)")
}

// Construct pcb_trace_hint
Expand All @@ -113,6 +106,7 @@ class TraceHintBuilderClass {
pcb_port_id: pcb_port.pcb_port_id,
pcb_component_id: pcb_port.pcb_component_id,
route,
trace_width: this.props.traceWidth,
}

return [trace_hint]
Expand Down
10 changes: 7 additions & 3 deletions tests/tracehint/trace-hint-1.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava"
import { su } from "@tscircuit/soup-util"
import test from "ava"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("trace hint 1: basic trace_hint for pad", async (t) => {
Expand All @@ -26,8 +26,12 @@ test("trace hint 1: basic trace_hint for pad", async (t) => {
// waiting for select
const pcb_port = su(soup).pcb_port.select(".R1 > .left")!

t.is(trace_hint.route[0].x, pcb_port.x - 1)
t.is(trace_hint.route[0].y, pcb_port.y + 1)
if (pcb_port) {
t.is(trace_hint.route[0]?.x, pcb_port.x - 1)
t.is(trace_hint.route[0]?.y, pcb_port.y + 1)
} else {
t.fail("pcb_port is undefined")
}

logSoup(soup)
})

0 comments on commit b15e537

Please sign in to comment.