-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tscircuit/tracehints
Trace Hint Implementation (single layer)
- Loading branch information
Showing
13 changed files
with
449 additions
and
13 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
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 |
---|---|---|
@@ -1,4 +1,60 @@ | ||
import { PrimitiveComponent } from "lib/components/base-components/PrimitiveComponent" | ||
import { traceProps } from "@tscircuit/props" | ||
import { traceHintProps } from "@tscircuit/props" | ||
import type { Port } from "./Port" | ||
import type { RouteHintPoint } from "@tscircuit/soup" | ||
import { applyToPoint } from "transformation-matrix" | ||
|
||
export class TraceHint extends PrimitiveComponent<typeof traceProps> {} | ||
export class TraceHint extends PrimitiveComponent<typeof traceHintProps> { | ||
matchedPort: Port | null = null | ||
|
||
doInitialPortMatching(): void { | ||
const { db } = this.project! | ||
const { _parsedProps: props, parent } = this | ||
|
||
if (!parent) return | ||
|
||
if (parent.componentName === "Trace") { | ||
this.renderError( | ||
`Port inference inside trace is not yet supported (${this})`, | ||
) | ||
return | ||
} | ||
|
||
if (!parent) throw new Error("TraceHint has no parent") | ||
|
||
if (!props.for) { | ||
this.renderError(`TraceHint has no for property (${this})`) | ||
return | ||
} | ||
|
||
const port = parent.selectOne(props.for, { type: "port" }) as Port | ||
|
||
if (!port) { | ||
this.renderError( | ||
`${this} could not find port for selector "${props.for}"`, | ||
) | ||
} | ||
|
||
this.matchedPort = port | ||
port.registerMatch(this) | ||
} | ||
|
||
getPcbRouteHints(): Array<RouteHintPoint> { | ||
const { _parsedProps: props } = this | ||
|
||
const offsets = props.offset ? [props.offset] : props.offsets | ||
|
||
if (!offsets) return [] | ||
|
||
const globalTransform = this.computePcbGlobalTransform() | ||
|
||
return offsets.map( | ||
(offset): RouteHintPoint => ({ | ||
...applyToPoint(globalTransform, offset), | ||
via: offset.via, | ||
to_layer: offset.to_layer, | ||
trace_width: offset.trace_width, | ||
}), | ||
) | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
lib/utils/autorouting/findPossibleTraceLayerCombinations.ts
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,102 @@ | ||
interface Hint { | ||
via?: boolean | ||
optional_via?: boolean | ||
layers?: Array<string> | ||
} | ||
|
||
const LAYER_SELECTION_PREFERENCE = ["top", "bottom", "inner1", "inner2"] | ||
|
||
/** | ||
* ORDERING OF CANDIDATES: Example: | ||
* top -> top -> bottom -> bottom | ||
* bottom -> bottom -> top -> top | ||
* top -> bottom -> bottom -> top | ||
* bottom -> top -> top -> bottom | ||
*/ | ||
interface CandidateTraceLayerCombination { | ||
layer_path: string[] | ||
} | ||
|
||
/** | ||
* Given a set of hints that contain layers or indication there should be a via, | ||
* this function returns all combinations of layers that could be traversed. | ||
* | ||
* EXAMPLE 1: | ||
* INPUT: | ||
* [top,bottom] -> unspecified -> unspecified/via -> [top, bottom] | ||
* OUTPUT: | ||
* top -> top -> bottom -> bottom | ||
* bottom -> bottom -> top -> top * | ||
* EXAMPLE 2: | ||
* INPUT: | ||
* [top,bottom] -> unspecified -> unspecified/via -> unspecified/via -> [top, bottom] | ||
* OUTPUT: | ||
* top -> top -> bottom -> top -> top | ||
* bottom -> bottom -> top-> bottom -> bottom | ||
* bottom -> bottom -> inner-1 -> inner-1 -> bottom | ||
*/ | ||
export const findPossibleTraceLayerCombinations = ( | ||
hints: Hint[], | ||
layer_path: string[] = [], | ||
): CandidateTraceLayerCombination[] => { | ||
const candidates: CandidateTraceLayerCombination[] = [] | ||
if (layer_path.length === 0) { | ||
const starting_layers = hints[0].layers! | ||
for (const layer of starting_layers) { | ||
candidates.push( | ||
...findPossibleTraceLayerCombinations(hints.slice(1), [layer]), | ||
) | ||
} | ||
return candidates | ||
} | ||
|
||
if (hints.length === 0) return [] | ||
const current_hint = hints[0] | ||
const is_possibly_via = current_hint.via || current_hint.optional_via | ||
const last_layer = layer_path[layer_path.length - 1] | ||
|
||
if (hints.length === 1) { | ||
const last_hint = current_hint | ||
if (last_hint.layers && is_possibly_via) { | ||
return last_hint.layers.map((layer) => ({ | ||
layer_path: [...layer_path, layer], | ||
})) | ||
} | ||
if (last_hint.layers?.includes(last_layer)) { | ||
return [{ layer_path: [...layer_path, last_layer] }] | ||
} | ||
return [] | ||
} | ||
|
||
if (!is_possibly_via) { | ||
if (current_hint.layers) { | ||
if (!current_hint.layers.includes(last_layer)) { | ||
return [] | ||
} | ||
} | ||
|
||
return findPossibleTraceLayerCombinations( | ||
hints.slice(1), | ||
layer_path.concat([last_layer]), | ||
) | ||
} | ||
|
||
const candidate_next_layers = ( | ||
current_hint.optional_via | ||
? LAYER_SELECTION_PREFERENCE | ||
: LAYER_SELECTION_PREFERENCE.filter((layer) => layer !== last_layer) | ||
).filter( | ||
(layer) => !current_hint.layers || current_hint.layers?.includes(layer), | ||
) | ||
|
||
for (const candidate_next_layer of candidate_next_layers) { | ||
candidates.push( | ||
...findPossibleTraceLayerCombinations( | ||
hints.slice(1), | ||
layer_path.concat(candidate_next_layer), | ||
), | ||
) | ||
} | ||
|
||
return candidates | ||
} |
Oops, something went wrong.