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

feat: add trace width #101

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions package-lock.json

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

1 change: 0 additions & 1 deletion src/lib/builder/net-builder/net-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class NetBuilderClass implements NetBuilder {
is_digital_signal: this.props.is_digital_signal,
is_power: this.props.is_power,
is_ground: this.props.is_ground,
trace_width: this.props.trace_width,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nets should also have a trace width!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically there's a priority system, net comes last in priorities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so you can say "the 5V net should generally have this traceWidth, but this hint should override that because this point gets hot..."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah! this was giving type error and to fix that I removed it for a while. I think because of some version mismatch. I will add this back

},
]
}
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 @@
}

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 @@
}
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 @@

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 @@
pcb_port_id: pcb_port.pcb_port_id,
pcb_component_id: pcb_port.pcb_component_id,
route,
trace_width: this.props.traceWidth ?? 0.1,

Check failure on line 109 in src/lib/builder/trace-hint-builder/index.ts

View workflow job for this annotation

GitHub Actions / build-check

Object literal may only specify known properties, and 'trace_width' does not exist in type '{ type: "pcb_trace_hint"; pcb_component_id: string; pcb_port_id: string; route: { x: number; y: number; via?: boolean | undefined; to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined; }[]; pcb_trace_hint_id: string; }'.

Check failure on line 109 in src/lib/builder/trace-hint-builder/index.ts

View workflow job for this annotation

GitHub Actions / build-check

Property 'traceWidth' does not exist on type 'Partial<{ for: string; order?: number | undefined; offset?: { x: string | number; y: string | number; via?: boolean | undefined; to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | ... 4 more ... | undefined; } | undefined; offsets?: { ...; }[] | undefined; }>'.

Check failure on line 109 in src/lib/builder/trace-hint-builder/index.ts

View workflow job for this annotation

GitHub Actions / prettier-check

Object literal may only specify known properties, and 'trace_width' does not exist in type '{ type: "pcb_trace_hint"; pcb_component_id: string; pcb_port_id: string; route: { x: number; y: number; via?: boolean | undefined; to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6" | undefined; }[]; pcb_trace_hint_id: string; }'.

Check failure on line 109 in src/lib/builder/trace-hint-builder/index.ts

View workflow job for this annotation

GitHub Actions / prettier-check

Property 'traceWidth' does not exist on type 'Partial<{ for: string; order?: number | undefined; offset?: { x: string | number; y: string | number; via?: boolean | undefined; to_layer?: "top" | "bottom" | "inner1" | "inner2" | "inner3" | ... 4 more ... | undefined; } | undefined; offsets?: { ...; }[] | undefined; }>'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't give trace hints a default width

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(because we want to have the priority system- if a trace hint width isn't defined then we'll use the default for the net, or the pad type etc.)

Copy link
Member Author

@imrishabh18 imrishabh18 Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seveibar What is the difference between the net and pad type? And how are they coming into the picture while we are manually adding trace hint?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea good question, a "net" is really generally, like "the 5v net" usually refers to any connection that makes contact with a 5v line. Usually that's going to be like every chip that has power. Lowest priority for trace width

Then there's a trace, which refers to the full set of lines/route that connect two or more pads together.

Then theres a "tracehint point" which refers to a single point along a tracehint. Each of these points can individually have an associated width.

Will draw up a diagram in a moment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is trace only between the chip and power? then for ex. what are those between two resistors or a chip and resistor?

We use these trace_hints to make a optimised trace and optimised width usage for trace?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally you don't need to vary the trace width for non-power traces, but a circuit will often have 2-5 different traces that represent some kind of power at different voltage levels or "noise levels"

Not every trace will have an explicitly defined net too. If you don't have an explicit net then you just use the "board's default trace width". An explicit net is a net that's actually written in the code. Most nets are not explicit, they're created "on the fly" or "as needed"

A trace that isn't connected to power is generally called a "signal trace" because it carries either data or a signal related to data.

}

return [trace_hint]
Expand Down
Loading