refactor(autorouter/multilayer_reconfigurator): Wrap multilayer autoroute inputs in new structs

This commit is contained in:
Mikolaj Wielgus 2025-10-23 02:44:28 +02:00
parent 630c3f0202
commit 0311aee613
4 changed files with 54 additions and 23 deletions

View File

@ -13,9 +13,13 @@ use thiserror::Error;
use crate::{ use crate::{
autorouter::{ autorouter::{
multilayer_autoroute::MultilayerAutorouteOptions, multilayer_autoroute::MultilayerAutorouteOptions,
multilayer_reconfigurator::MultilayerAutorouteReconfigurator, multilayer_reconfigurator::{
planar_autoroute::PlanarAutorouteConfiguration, MultilayerAutorouteReconfigurator, MultilayerAutorouteReconfiguratorInput,
planar_reconfigurator::PlanarAutorouteReconfigurator, ratsnests::Ratsnests, },
planar_reconfigurator::{
PlanarAutorouteReconfigurator, PlanarAutorouteReconfiguratorInput,
},
ratsnests::Ratsnests,
}, },
board::{AccessMesadata, Board}, board::{AccessMesadata, Board},
drawing::{band::BandTermsegIndex, graph::MakePrimitiveRef}, drawing::{band::BandTermsegIndex, graph::MakePrimitiveRef},
@ -121,7 +125,9 @@ impl<M: AccessMesadata> Autorouter<M> {
) -> Result<MultilayerAutorouteReconfigurator, AutorouterError> { ) -> Result<MultilayerAutorouteReconfigurator, AutorouterError> {
MultilayerAutorouteReconfigurator::new( MultilayerAutorouteReconfigurator::new(
self, self,
self.selected_ratlines(selection, options.planar.principal_layer), MultilayerAutorouteReconfiguratorInput {
ratlines: self.selected_ratlines(selection, options.planar.principal_layer),
},
options, options,
) )
} }
@ -133,7 +139,7 @@ impl<M: AccessMesadata> Autorouter<M> {
) -> Result<PlanarAutorouteReconfigurator, AutorouterError> { ) -> Result<PlanarAutorouteReconfigurator, AutorouterError> {
PlanarAutorouteReconfigurator::new( PlanarAutorouteReconfigurator::new(
self, self,
PlanarAutorouteConfiguration { PlanarAutorouteReconfiguratorInput {
ratlines: self.selected_planar_ratlines(selection, options.principal_layer), ratlines: self.selected_planar_ratlines(selection, options.principal_layer),
}, },
options, options,

View File

@ -11,9 +11,10 @@ use crate::{
autorouter::{ autorouter::{
anterouter::{Anterouter, AnterouterOptions, AnterouterPlan}, anterouter::{Anterouter, AnterouterOptions, AnterouterPlan},
invoker::GetDebugOverlayData, invoker::GetDebugOverlayData,
planar_autoroute::PlanarAutorouteConfiguration, planar_reconfigurator::{
planar_reconfigurator::{PlanarAutorouteReconfigurator, PlanarReconfiguratorStatus}, PlanarAutorouteReconfigurator, PlanarAutorouteReconfiguratorInput,
ratline::RatlineUid, PlanarReconfiguratorStatus,
},
Autorouter, AutorouterError, PlanarAutorouteOptions, Autorouter, AutorouterError, PlanarAutorouteOptions,
}, },
board::edit::BoardEdit, board::edit::BoardEdit,
@ -23,6 +24,12 @@ use crate::{
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step},
}; };
#[derive(Clone, Debug)]
pub struct MultilayerAutorouteConfiguration {
pub plan: AnterouterPlan,
pub planar: PlanarAutorouteReconfiguratorInput,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct MultilayerAutorouteOptions { pub struct MultilayerAutorouteOptions {
pub anterouter: AnterouterOptions, pub anterouter: AnterouterOptions,
@ -38,18 +45,17 @@ pub struct MultilayerAutorouteExecutionStepper {
impl MultilayerAutorouteExecutionStepper { impl MultilayerAutorouteExecutionStepper {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: Vec<RatlineUid>, configuration: MultilayerAutorouteConfiguration,
plan: AnterouterPlan,
options: MultilayerAutorouteOptions, options: MultilayerAutorouteOptions,
) -> Result<Self, AutorouterError> { ) -> Result<Self, AutorouterError> {
let mut anterouter = Anterouter::new(plan); let mut anterouter = Anterouter::new(configuration.plan);
let mut anteroute_edit = BoardEdit::new(); let mut anteroute_edit = BoardEdit::new();
anterouter.anteroute(autorouter, &mut anteroute_edit, &options.anterouter); anterouter.anteroute(autorouter, &mut anteroute_edit, &options.anterouter);
Ok(Self { Ok(Self {
planar: PlanarAutorouteReconfigurator::new( planar: PlanarAutorouteReconfigurator::new(
autorouter, autorouter,
PlanarAutorouteConfiguration { ratlines }, configuration.planar,
options.planar, options.planar,
)?, )?,
anteroute_edit, anteroute_edit,

View File

@ -9,9 +9,12 @@ use specctra_core::mesadata::AccessMesadata;
use crate::{ use crate::{
autorouter::{ autorouter::{
invoker::GetDebugOverlayData, invoker::GetDebugOverlayData,
multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions}, multilayer_autoroute::{
MultilayerAutorouteConfiguration, MultilayerAutorouteExecutionStepper,
MultilayerAutorouteOptions,
},
multilayer_reconfigurer::MultilayerReconfigurer, multilayer_reconfigurer::MultilayerReconfigurer,
planar_reconfigurator::PlanarReconfiguratorStatus, planar_reconfigurator::{PlanarAutorouteReconfiguratorInput, PlanarReconfiguratorStatus},
planner::Planner, planner::Planner,
ratline::RatlineUid, ratline::RatlineUid,
Autorouter, AutorouterError, Autorouter, AutorouterError,
@ -23,6 +26,10 @@ use crate::{
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step},
}; };
pub struct MultilayerAutorouteReconfiguratorInput {
pub ratlines: Vec<RatlineUid>,
}
pub type MultilayerReconfiguratorStatus = ReconfiguratorStatus<(), PlanarReconfiguratorStatus>; pub type MultilayerReconfiguratorStatus = ReconfiguratorStatus<(), PlanarReconfiguratorStatus>;
pub struct MultilayerAutorouteReconfigurator { pub struct MultilayerAutorouteReconfigurator {
@ -36,17 +43,22 @@ pub struct MultilayerAutorouteReconfigurator {
impl MultilayerAutorouteReconfigurator { impl MultilayerAutorouteReconfigurator {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: Vec<RatlineUid>, input: MultilayerAutorouteReconfiguratorInput,
options: MultilayerAutorouteOptions, options: MultilayerAutorouteOptions,
) -> Result<Self, AutorouterError> { ) -> Result<Self, AutorouterError> {
let planner = Planner::new(autorouter, &ratlines); let planner = Planner::new(autorouter, &input.ratlines);
let reconfigurer = MultilayerReconfigurer::new(autorouter, ratlines.clone(), &options); let preconfiguration = MultilayerAutorouteConfiguration {
plan: planner.plan().clone(),
planar: PlanarAutorouteReconfiguratorInput {
ratlines: input.ratlines.clone(),
},
};
let reconfigurer = MultilayerReconfigurer::new(autorouter, input.ratlines, &options);
Ok(Self { Ok(Self {
stepper: MultilayerAutorouteExecutionStepper::new( stepper: MultilayerAutorouteExecutionStepper::new(
autorouter, autorouter,
ratlines, preconfiguration,
planner.plan().clone(),
options, options,
)?, )?,
reconfigurer, reconfigurer,

View File

@ -15,6 +15,7 @@ use crate::{
}, },
planar_reconfigurer::{PermuteRatlines, PlanarReconfigurer}, planar_reconfigurer::{PermuteRatlines, PlanarReconfigurer},
presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter}, presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter},
ratline::RatlineUid,
Autorouter, AutorouterError, PlanarAutorouteOptions, Autorouter, AutorouterError, PlanarAutorouteOptions,
}, },
board::edit::BoardEdit, board::edit::BoardEdit,
@ -23,6 +24,12 @@ use crate::{
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step},
}; };
#[derive(Clone, Debug)]
pub struct PlanarAutorouteReconfiguratorInput {
pub ratlines: Vec<RatlineUid>,
}
pub type PlanarReconfiguratorStatus = pub type PlanarReconfiguratorStatus =
ReconfiguratorStatus<PlanarAutorouteConfigurationResult, PlanarAutorouteContinueStatus>; ReconfiguratorStatus<PlanarAutorouteConfigurationResult, PlanarAutorouteContinueStatus>;
@ -35,12 +42,12 @@ pub struct PlanarAutorouteReconfigurator {
impl PlanarAutorouteReconfigurator { impl PlanarAutorouteReconfigurator {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
input_configuration: PlanarAutorouteConfiguration, input: PlanarAutorouteReconfiguratorInput,
options: PlanarAutorouteOptions, options: PlanarAutorouteOptions,
) -> Result<Self, AutorouterError> { ) -> Result<Self, AutorouterError> {
let presorter = SccIntersectionsAndLengthPresorter::new( let presorter = SccIntersectionsAndLengthPresorter::new(
autorouter, autorouter,
&input_configuration.ratlines, &input.ratlines,
&PresortParams { &PresortParams {
intersector_count_weight: 1.0, intersector_count_weight: 1.0,
length_weight: 0.001, length_weight: 0.001,
@ -48,10 +55,10 @@ impl PlanarAutorouteReconfigurator {
&options, &options,
); );
let preconfiguration = PlanarAutorouteConfiguration { let preconfiguration = PlanarAutorouteConfiguration {
ratlines: presorter.presort_ratlines(autorouter, &input_configuration.ratlines), ratlines: presorter.presort_ratlines(autorouter, &input.ratlines),
}; };
let reconfigurer = let reconfigurer =
PlanarReconfigurer::new(autorouter, input_configuration, presorter, &options); PlanarReconfigurer::new(autorouter, preconfiguration.clone(), presorter, &options);
Ok(Self { Ok(Self {
stepper: PlanarAutorouteExecutionStepper::new(autorouter, preconfiguration, options)?, stepper: PlanarAutorouteExecutionStepper::new(autorouter, preconfiguration, options)?,