refactor(stepper): Join progress estimation into one method

This commit is contained in:
Mikolaj Wielgus 2025-10-31 02:08:42 +01:00
parent 7b66db1672
commit c0f4319a13
14 changed files with 85 additions and 116 deletions

View File

@ -4,7 +4,7 @@
use std::ops::ControlFlow; use std::ops::ControlFlow;
use topola::{interactor::activity::ActivityStepperWithStatus, stepper::EstimateProgress}; use topola::{interactor::activity::ActivityStepperWithStatus, stepper::EstimateLinearProgress};
use crate::{translator::Translator, viewport::Viewport}; use crate::{translator::Translator, viewport::Viewport};
@ -40,8 +40,9 @@ impl StatusBar {
)); ));
if let Some(activity) = maybe_activity { if let Some(activity) = maybe_activity {
let value = activity.estimate_progress_value(); let linear_progress = activity.estimate_linear_progress();
let maximum = activity.estimate_progress_maximum(); let value = linear_progress.value();
let maximum = linear_progress.maximum();
ui.add( ui.add(
egui::ProgressBar::new((value / maximum) as f32).text(format!( egui::ProgressBar::new((value / maximum) as f32).text(format!(

View File

@ -16,7 +16,7 @@ use crate::{
board::{edit::BoardEdit, AccessMesadata}, board::{edit::BoardEdit, AccessMesadata},
layout::via::ViaWeight, layout::via::ViaWeight,
router::ng, router::ng,
stepper::{Abort, EstimateProgress, Step}, stepper::{Abort, EstimateLinearProgress, LinearProgress, Step},
}; };
use super::{ use super::{
@ -173,33 +173,20 @@ impl<M: AccessMesadata + Clone> Abort<Invoker<M>> for ExecutionStepper<M> {
// Since enum_dispatch does not really support generics, we implement this the // Since enum_dispatch does not really support generics, we implement this the
// long way. // long way.
impl<M> EstimateProgress for ExecutionStepper<M> { impl<M> EstimateLinearProgress for ExecutionStepper<M> {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
match self {
ExecutionStepper::MultilayerAutoroute(autoroute) => autoroute.estimate_progress_value(),
ExecutionStepper::PlanarAutoroute(autoroute) => autoroute.estimate_progress_value(),
ExecutionStepper::TopoAutoroute(toporoute) => toporoute.estimate_progress_value(),
ExecutionStepper::PlaceVia(place_via) => place_via.estimate_progress_value(),
ExecutionStepper::RemoveBands(remove_bands) => remove_bands.estimate_progress_value(),
ExecutionStepper::MeasureLength(measure_length) => {
measure_length.estimate_progress_value()
}
}
}
fn estimate_progress_maximum(&self) -> f64 {
match self { match self {
ExecutionStepper::MultilayerAutoroute(autoroute) => { ExecutionStepper::MultilayerAutoroute(autoroute) => {
autoroute.estimate_progress_maximum() autoroute.estimate_linear_progress()
} }
ExecutionStepper::PlanarAutoroute(autoroute) => autoroute.estimate_progress_maximum(), ExecutionStepper::PlanarAutoroute(autoroute) => autoroute.estimate_linear_progress(),
ExecutionStepper::TopoAutoroute(toporoute) => toporoute.estimate_progress_maximum(), ExecutionStepper::TopoAutoroute(toporoute) => toporoute.estimate_linear_progress(),
ExecutionStepper::PlaceVia(place_via) => place_via.estimate_progress_maximum(), ExecutionStepper::PlaceVia(place_via) => place_via.estimate_linear_progress(),
ExecutionStepper::RemoveBands(remove_bands) => remove_bands.estimate_progress_maximum(), ExecutionStepper::RemoveBands(remove_bands) => remove_bands.estimate_linear_progress(),
ExecutionStepper::MeasureLength(measure_length) => { ExecutionStepper::MeasureLength(measure_length) => {
measure_length.estimate_progress_maximum() measure_length.estimate_linear_progress()
} }
} }
} }

View File

@ -8,7 +8,7 @@
use crate::{ use crate::{
board::AccessMesadata, geometry::shape::MeasureLength as MeasureLengthTrait, graph::MakeRef, board::AccessMesadata, geometry::shape::MeasureLength as MeasureLengthTrait, graph::MakeRef,
stepper::EstimateProgress, stepper::EstimateLinearProgress,
}; };
use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError}; use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError};
@ -48,7 +48,7 @@ impl MeasureLengthExecutionStepper {
} }
} }
impl EstimateProgress for MeasureLengthExecutionStepper { impl EstimateLinearProgress for MeasureLengthExecutionStepper {
type Value = f64; type Value = f64;
} }
impl GetDebugOverlayData for MeasureLengthExecutionStepper {} impl GetDebugOverlayData for MeasureLengthExecutionStepper {}

View File

@ -21,7 +21,9 @@ use crate::{
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::{edit::Edit, primitive::PrimitiveShape}, geometry::{edit::Edit, primitive::PrimitiveShape},
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{
Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step,
},
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -117,15 +119,11 @@ impl<M: AccessMesadata> Reconfigure<Autorouter<M>> for MultilayerAutorouteExecut
} }
} }
impl EstimateProgress for MultilayerAutorouteExecutionStepper { impl EstimateLinearProgress for MultilayerAutorouteExecutionStepper {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
self.planar.estimate_progress_value() self.planar.estimate_linear_progress()
}
fn estimate_progress_maximum(&self) -> f64 {
self.planar.estimate_progress_maximum()
} }
} }

View File

@ -29,7 +29,9 @@ use crate::{
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{
Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step,
},
}; };
pub type MultilayerReconfiguratorStatus = pub type MultilayerReconfiguratorStatus =
@ -139,17 +141,11 @@ impl<M: AccessMesadata> Abort<Autorouter<M>> for MultilayerAutorouteReconfigurat
} }
} }
impl EstimateProgress for MultilayerAutorouteReconfigurator { impl EstimateLinearProgress for MultilayerAutorouteReconfigurator {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
// TODO. self.stepper.estimate_linear_progress()
self.stepper.estimate_progress_value()
}
fn estimate_progress_maximum(&self) -> f64 {
// TODO.
self.stepper.estimate_progress_maximum()
} }
} }

View File

@ -12,7 +12,7 @@ use crate::{
AccessMesadata, AccessMesadata,
}, },
layout::{via::ViaWeight, LayoutEdit}, layout::{via::ViaWeight, LayoutEdit},
stepper::EstimateProgress, stepper::EstimateLinearProgress,
}; };
use super::{invoker::GetDebugOverlayData, Autorouter, AutorouterError}; use super::{invoker::GetDebugOverlayData, Autorouter, AutorouterError};
@ -53,7 +53,7 @@ impl PlaceViaExecutionStepper {
} }
} }
impl EstimateProgress for PlaceViaExecutionStepper { impl EstimateLinearProgress for PlaceViaExecutionStepper {
type Value = f64; type Value = f64;
} }
impl GetDebugOverlayData for PlaceViaExecutionStepper {} impl GetDebugOverlayData for PlaceViaExecutionStepper {}

View File

@ -21,7 +21,7 @@ use crate::{
router::{ router::{
navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router, navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router,
}, },
stepper::{Abort, EstimateProgress, Reconfigure, Step}, stepper::{Abort, EstimateLinearProgress, LinearProgress, Reconfigure, Step},
}; };
use super::{ use super::{
@ -303,18 +303,18 @@ impl<M: AccessMesadata> Reconfigure<Autorouter<M>> for PlanarAutorouteExecutionS
} }
} }
impl EstimateProgress for PlanarAutorouteExecutionStepper { impl EstimateLinearProgress for PlanarAutorouteExecutionStepper {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
self.curr_ratline_index as f64 LinearProgress::new(
+ self.route.as_ref().map_or(0.0, |route| { self.curr_ratline_index as f64
route.estimate_progress_value() / route.estimate_progress_maximum() + self.route.as_ref().map_or(0.0, |route| {
}) route.estimate_linear_progress().value()
} / route.estimate_linear_progress().maximum()
}),
fn estimate_progress_maximum(&self) -> f64 { self.configuration().ratlines.len() as f64,
self.configuration().ratlines.len() as f64 )
} }
} }

View File

@ -24,7 +24,9 @@ use crate::{
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, stepper::{
Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step,
},
}; };
pub type PlanarAutorouteReconfiguratorStatus = pub type PlanarAutorouteReconfiguratorStatus =
@ -118,17 +120,11 @@ impl<M: AccessMesadata> Abort<Autorouter<M>> for PlanarAutorouteReconfigurator {
} }
} }
impl EstimateProgress for PlanarAutorouteReconfigurator { impl EstimateLinearProgress for PlanarAutorouteReconfigurator {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
// TODO. self.stepper.estimate_linear_progress()
self.stepper.estimate_progress_value()
}
fn estimate_progress_maximum(&self) -> f64 {
// TODO.
self.stepper.estimate_progress_maximum()
} }
} }

View File

@ -6,7 +6,7 @@
use crate::{ use crate::{
board::{edit::BoardEdit, AccessMesadata}, board::{edit::BoardEdit, AccessMesadata},
stepper::EstimateProgress, stepper::EstimateLinearProgress,
}; };
use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError}; use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError};
@ -48,7 +48,7 @@ impl RemoveBandsExecutionStepper {
} }
} }
impl EstimateProgress for RemoveBandsExecutionStepper { impl EstimateLinearProgress for RemoveBandsExecutionStepper {
type Value = f64; type Value = f64;
} }
impl GetDebugOverlayData for RemoveBandsExecutionStepper {} impl GetDebugOverlayData for RemoveBandsExecutionStepper {}

View File

@ -25,7 +25,7 @@ use crate::{
ng, ng,
thetastar::ThetastarStepper, thetastar::ThetastarStepper,
}, },
stepper::{Abort, EstimateProgress, OnEvent, Step}, stepper::{Abort, EstimateLinearProgress, LinearProgress, OnEvent, Step},
}; };
/// Stores the interactive input data from the user. /// Stores the interactive input data from the user.
@ -100,20 +100,13 @@ impl<M: AccessMesadata + Clone> Abort<Invoker<M>> for ActivityStepper<M> {
// Since enum_dispatch does not really support generics, we implement this the // Since enum_dispatch does not really support generics, we implement this the
// long way. // long way.
impl<M> EstimateProgress for ActivityStepper<M> { impl<M> EstimateLinearProgress for ActivityStepper<M> {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
match self { match self {
ActivityStepper::Interaction(..) => 0.0, ActivityStepper::Interaction(..) => LinearProgress::new(0.0, 0.0),
ActivityStepper::Execution(execution) => execution.estimate_progress_value(), ActivityStepper::Execution(execution) => execution.estimate_linear_progress(),
}
}
fn estimate_progress_maximum(&self) -> f64 {
match self {
ActivityStepper::Interaction(..) => 0.0,
ActivityStepper::Execution(execution) => execution.estimate_progress_maximum(),
} }
} }
} }
@ -199,15 +192,11 @@ impl<M: AccessMesadata + Clone> OnEvent<ActivityContext<'_, M>, InteractiveEvent
} }
} }
impl<M> EstimateProgress for ActivityStepperWithStatus<M> { impl<M> EstimateLinearProgress for ActivityStepperWithStatus<M> {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
self.activity.estimate_progress_value() self.activity.estimate_linear_progress()
}
fn estimate_progress_maximum(&self) -> f64 {
self.activity.estimate_progress_maximum()
} }
} }

View File

@ -16,7 +16,7 @@ use crate::{
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
graph::GenericIndex, graph::GenericIndex,
layout::{poly::PolyWeight, Layout}, layout::{poly::PolyWeight, Layout},
stepper::{Abort, EstimateProgress}, stepper::{Abort, EstimateLinearProgress},
}; };
use super::{ use super::{
@ -233,7 +233,7 @@ impl<R: AccessRules + Clone + std::panic::RefUnwindSafe> AutorouteExecutionStepp
} }
} }
impl<M> EstimateProgress for AutorouteExecutionStepper<M> { impl<M> EstimateLinearProgress for AutorouteExecutionStepper<M> {
type Value = f64; type Value = f64;
} }

View File

@ -19,7 +19,7 @@ use crate::{
thetastar::{ThetastarError, ThetastarStepper}, thetastar::{ThetastarError, ThetastarStepper},
Router, RouterThetastarStrategy, Router, RouterThetastarStrategy,
}, },
stepper::{EstimateProgress, Step}, stepper::{EstimateLinearProgress, LinearProgress, Step},
}; };
#[derive(Getters, Dissolve)] #[derive(Getters, Dissolve)]
@ -99,14 +99,10 @@ impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper {
} }
} }
impl EstimateProgress for RouteStepper { impl EstimateLinearProgress for RouteStepper {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_linear_progress(&self) -> LinearProgress<f64> {
self.thetastar.estimate_progress_value() self.thetastar.estimate_linear_progress()
}
fn estimate_progress_maximum(&self) -> f64 {
self.thetastar.estimate_progress_maximum()
} }
} }

View File

@ -20,7 +20,7 @@ use thiserror::Error;
use std::cmp::Ordering; use std::cmp::Ordering;
use crate::stepper::{EstimateProgress, Step}; use crate::stepper::{EstimateLinearProgress, LinearProgress, Step};
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct MinScored<K, T>(pub K, pub T); pub struct MinScored<K, T>(pub K, pub T);
@ -443,7 +443,7 @@ where
} }
} }
impl<G, K> EstimateProgress for ThetastarStepper<G, K> impl<G, K> EstimateLinearProgress for ThetastarStepper<G, K>
where where
G: GraphBase, G: GraphBase,
G::NodeId: Eq + Ord, G::NodeId: Eq + Ord,
@ -452,11 +452,7 @@ where
{ {
type Value = K; type Value = K;
fn estimate_progress_value(&self) -> K { fn estimate_linear_progress(&self) -> LinearProgress<Self::Value> {
self.progress_estimate_value LinearProgress::new(self.progress_estimate_value, self.progress_estimate_maximum)
}
fn estimate_progress_maximum(&self) -> K {
self.progress_estimate_maximum
} }
} }

View File

@ -4,6 +4,8 @@
use core::ops::ControlFlow; use core::ops::ControlFlow;
use derive_getters::Getters;
/// This trait represents a linearly advanceable state whose advancement may /// This trait represents a linearly advanceable state whose advancement may
/// break or fail with many different return values, and to which part of /// break or fail with many different return values, and to which part of
/// the information, called the context, has to be supplied on each call as a /// the information, called the context, has to be supplied on each call as a
@ -81,15 +83,23 @@ pub trait OnEvent<Ctx, Event> {
fn on_event(&mut self, context: &mut Ctx, event: Event) -> Self::Output; fn on_event(&mut self, context: &mut Ctx, event: Event) -> Self::Output;
} }
/// Some steppers report estimates of how far they are from completion. #[derive(Clone, Copy, Debug, Getters)]
pub trait EstimateProgress { pub struct LinearProgress<V> {
type Value: Default; value: V,
maximum: V,
}
fn estimate_progress_value(&self) -> Self::Value { impl<V> LinearProgress<V> {
Self::Value::default() pub fn new(value: V, maximum: V) -> Self {
} Self { value, maximum }
}
fn estimate_progress_maximum(&self) -> Self::Value { }
Self::Value::default()
/// Some steppers report estimates of how far they are from completion.
pub trait EstimateLinearProgress {
type Value: Default;
fn estimate_linear_progress(&self) -> LinearProgress<Self::Value> {
LinearProgress::new(Self::Value::default(), Self::Value::default())
} }
} }