Skip to content
Open
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
34 changes: 28 additions & 6 deletions lib/solvers/TraceCleanupSolver/TraceCleanupSolver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { InputProblem } from "lib/types/InputProblem"
import type { GraphicsObject, Line } from "graphics-debug"
import { minimizeTurnsWithFilteredLabels } from "./minimizeTurnsWithFilteredLabels"
import { balanceZShapes } from "./balanceZShapes"
import { BaseSolver } from "lib/solvers/BaseSolver/BaseSolver"
import type { SolvedTracePath } from "lib/solvers/SchematicTraceLinesSolver/SchematicTraceLinesSolver"
import { visualizeInputProblem } from "lib/solvers/SchematicTracePipelineSolver/visualizeInputProblem"
import type { InputProblem } from "lib/types/InputProblem"
import type { NetLabelPlacement } from "../NetLabelPlacementSolver/NetLabelPlacementSolver"
import { alignSameNetTraceSegments } from "./alignSameNetTraceSegments"
import { balanceZShapes } from "./balanceZShapes"
import { minimizeTurnsWithFilteredLabels } from "./minimizeTurnsWithFilteredLabels"

/**
* Defines the input structure for the TraceCleanupSolver.
Expand All @@ -18,13 +19,14 @@ interface TraceCleanupSolverInput {
paddingBuffer: number
}

import { UntangleTraceSubsolver } from "./sub-solver/UntangleTraceSubsolver"
import { is4PointRectangle } from "./is4PointRectangle"
import { UntangleTraceSubsolver } from "./sub-solver/UntangleTraceSubsolver"

/**
* Represents the different stages or steps within the trace cleanup pipeline.
*/
type PipelineStep =
| "aligning_same_net_segments"
| "minimizing_turns"
| "balancing_l_shapes"
| "untangling_traces"
Expand Down Expand Up @@ -66,10 +68,10 @@ export class TraceCleanupSolver extends BaseSolver {
this.outputTraces = output.traces
this.tracesMap = new Map(this.outputTraces.map((t) => [t.mspPairId, t]))
this.activeSubSolver = null
this.pipelineStep = "minimizing_turns"
this.pipelineStep = "aligning_same_net_segments"
} else if (this.activeSubSolver.failed) {
this.activeSubSolver = null
this.pipelineStep = "minimizing_turns"
this.pipelineStep = "aligning_same_net_segments"
}
return
}
Expand All @@ -78,6 +80,9 @@ export class TraceCleanupSolver extends BaseSolver {
case "untangling_traces":
this._runUntangleTracesStep()
break
case "aligning_same_net_segments":
this._runAlignSameNetSegmentsStep()
break
case "minimizing_turns":
this._runMinimizeTurnsStep()
break
Expand All @@ -94,6 +99,23 @@ export class TraceCleanupSolver extends BaseSolver {
})
}

private _runAlignSameNetSegmentsStep() {
const result = alignSameNetTraceSegments({
traces: Array.from(this.tracesMap.values()),
inputProblem: this.input.inputProblem,
allLabelPlacements: this.input.allLabelPlacements,
mergedLabelNetIdMap: this.input.mergedLabelNetIdMap,
paddingBuffer: this.input.paddingBuffer,
})

if (result.changed) {
this.outputTraces = result.traces
this.tracesMap = new Map(this.outputTraces.map((t) => [t.mspPairId, t]))
}

this.pipelineStep = "minimizing_turns"
}

private _runMinimizeTurnsStep() {
if (this.traceIdQueue.length === 0) {
this.pipelineStep = "balancing_l_shapes"
Expand Down
Loading
Loading