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
7 changes: 7 additions & 0 deletions lib/components/primitive-components/Breakout/Breakout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import type { z } from "zod"
import { createBreakoutPointSolverInput } from "./createBreakoutPointSolverInput"

export class Breakout extends Group<typeof breakoutProps> {
get config() {
return {
...super.config,
zodProps: breakoutProps,
}
}

constructor(props: z.input<typeof breakoutProps>) {
super({
...props,
Expand Down
82 changes: 63 additions & 19 deletions lib/components/primitive-components/Group/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
type NormalizedAutorouterConfig,
getPresetAutoroutingConfig,
} from "lib/utils/autorouting/getPresetAutoroutingConfig"
import { getLocalAutorouterStrategy } from "lib/utils/autorouting/localAutorouterStrategies"
import { getLocalAutoroutingStages } from "lib/utils/autorouting/localAutorouterStrategies"
import { shouldSkipAutoroutingBecauseOfPlacementErrors } from "lib/utils/autorouting/should-skip-autorouting-because-of-placement-errors"
import { getBoundsOfPcbComponents } from "lib/utils/get-bounds-of-pcb-components"
import { getViaBoardLayers } from "lib/utils/getViaSpanLayers"
Expand Down Expand Up @@ -931,6 +931,22 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
})
const routingPhasePlans = this._getRoutingPhasePlans()
const hasPhasedAutorouting = Group_hasPhasedAutorouting(routingPhasePlans)
const routingStages = routingPhasePlans.flatMap((routingPhasePlan) => {
const phaseAutorouterConfig: NormalizedAutorouterConfig =
routingPhasePlan.autorouter
? getPresetAutoroutingConfig(
routingPhasePlan.autorouter,
this.root?.platform,
)
: autorouterConfig
return getLocalAutoroutingStages(
phaseAutorouterConfig,
this.root?.platform,
).map((stage) => ({
...stage,
routingPhasePlan,
}))
})
const outputTraces: SimplifiedPcbTrace[] = []
const outputJumpers: Array<{
jumper_footprint: string
Expand Down Expand Up @@ -978,15 +994,27 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
})
}

for (const routingPhasePlan of routingPhasePlans) {
const phaseAutorouterConfig: NormalizedAutorouterConfig =
routingPhasePlan.autorouter
? getPresetAutoroutingConfig(
routingPhasePlan.autorouter,
this.root?.platform,
)
: autorouterConfig
let simpleRouteJson = baseSimpleRouteJson
let previousStageOutputSimpleRouteJson: SimpleRouteJson | undefined

for (const {
routingPhasePlan,
autorouterConfig: phaseAutorouterConfig,
strategy: localAutorouterStrategy,
usesPreviousStageOutput,
} of routingStages) {
if (!usesPreviousStageOutput) {
previousStageOutputSimpleRouteJson = undefined
}
if (
usesPreviousStageOutput &&
previousStageOutputSimpleRouteJson === undefined
) {
throw new Error(
"Autorouting follow-up stage is missing the preceding stage output",
)
}
let simpleRouteJson =
previousStageOutputSimpleRouteJson ?? baseSimpleRouteJson
const isRegionReroutePhase = Boolean(
routingPhasePlan.reroute && routingPhasePlan.region,
)
Expand All @@ -1003,15 +1031,19 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
}
: null

if (isRegionReroutePhase && rerouteOriginalSrj) {
if (
!usesPreviousStageOutput &&
isRegionReroutePhase &&
rerouteOriginalSrj
) {
simpleRouteJson = getRerouteSimpleRouteJson(
rerouteOriginalSrj as AutorouterSimpleRouteJson,
{
shape: "rect",
...routingPhasePlan.region,
} as RerouteRectRegion,
) as SimpleRouteJson
} else if (isConnectionReroutePhase) {
} else if (!usesPreviousStageOutput && isConnectionReroutePhase) {
simpleRouteJson = Group_filterSimpleRouteJsonForPhase(
baseSimpleRouteJson,
routingPhasePlan,
Expand All @@ -1025,7 +1057,7 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
baseSimpleRouteJson.layerCount,
),
]
} else if (hasPhasedAutorouting) {
} else if (!usesPreviousStageOutput && hasPhasedAutorouting) {
simpleRouteJson = Group_filterSimpleRouteJsonForPhase(
baseSimpleRouteJson,
routingPhasePlan,
Expand Down Expand Up @@ -1089,9 +1121,6 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
simpleRouteJson,
})

const localAutorouterStrategy = getLocalAutorouterStrategy(
phaseAutorouterConfig.preset,
)
const cacheEngine =
phaseAutorouterConfig.algorithmFn || !localAutorouterStrategy.cacheable
? undefined
Expand Down Expand Up @@ -1139,6 +1168,7 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
autorouter = localAutorouterStrategy.create({
simpleRouteJson,
commonAutorouterOptions,
busFanoutDirections: routingPhasePlan.busFanoutDirections,
})
}

Expand Down Expand Up @@ -1174,16 +1204,30 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
traces = await routingPromise
}

const transformedSimpleRouteJson =
autorouter?.getOutputSimpleRouteJson?.()
let stageOutputTraces = traces
if (transformedSimpleRouteJson?.traces) {
stageOutputTraces = transformedSimpleRouteJson.traces
} else if (usesPreviousStageOutput) {
stageOutputTraces = [...(simpleRouteJson.traces ?? []), ...traces]
}
const outputSimpleRouteJson = {
...simpleRouteJson,
traces,
...(transformedSimpleRouteJson ?? simpleRouteJson),
traces: stageOutputTraces,
}
previousStageOutputSimpleRouteJson = transformedSimpleRouteJson
? outputSimpleRouteJson
: undefined

if (!cachedResult && cacheKey) {
await cacheLocalAutoroutingPhaseResult({
cacheEngine,
cacheKey,
result: outputSimpleRouteJson,
result: {
...simpleRouteJson,
traces,
},
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RoutingPhasePlan {
reroute?: boolean
region?: AutoroutingPhaseProps["region"]
connectionSelectors?: string[]
busFanoutDirections?: AutoroutingPhaseProps["busFanoutDirections"]
drcTolerances?: RoutingPhaseDrcTolerances
nets: Net[]
traces: Trace[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export function Group_getRoutingPhasePlans(
plan.connectionSelectors = phaseProps
? getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps)
: undefined
plan.busFanoutDirections = phaseProps?.busFanoutDirections
plan.drcTolerances = phaseProps
? getDrcTolerancesFromAutoroutingPhaseProps(phaseProps)
: undefined
Expand Down
Loading
Loading