diff --git a/crates/topola-egui/src/status_bar.rs b/crates/topola-egui/src/status_bar.rs index 402dc27..0815ae4 100644 --- a/crates/topola-egui/src/status_bar.rs +++ b/crates/topola-egui/src/status_bar.rs @@ -43,15 +43,26 @@ impl StatusBar { let linear_progress = activity.estimate_linear_progress(); let value = linear_progress.value(); let maximum = linear_progress.maximum(); + let ratio = *value as f32 / *maximum as f32; - ui.add( - egui::ProgressBar::new((value / maximum) as f32).text(format!( - "{:.1} ({:.1}/{:.1})", - value / maximum * 100.0, - value, - maximum - )), - ); + ui.add(egui::ProgressBar::new(ratio).text(format!( + "{:.1}% ({:.1}/{:.1})", + ratio * 100.0, + value, + maximum + ))); + + let linear_subprogress = linear_progress.subscale(); + let value = linear_subprogress.value(); + let maximum = linear_subprogress.maximum(); + let ratio = *value as f32 / *maximum as f32; + + ui.add(egui::ProgressBar::new(ratio).text(format!( + "{:.1}% ({:.1}/{:.1})", + ratio * 100.0, + value, + maximum + ))); } }); } diff --git a/src/autorouter/execution.rs b/src/autorouter/execution.rs index c3cc522..4250283 100644 --- a/src/autorouter/execution.rs +++ b/src/autorouter/execution.rs @@ -16,7 +16,7 @@ use crate::{ board::{edit::BoardEdit, AccessMesadata}, layout::via::ViaWeight, router::ng, - stepper::{Abort, EstimateLinearProgress, LinearProgress, Step}, + stepper::{Abort, EstimateLinearProgress, LinearScale, Step}, }; use super::{ @@ -172,21 +172,28 @@ impl Abort> for ExecutionStepper { } // Since enum_dispatch does not really support generics, we implement this the -// long way. +// long way by using `match`. impl EstimateLinearProgress for ExecutionStepper { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { match self { ExecutionStepper::MultilayerAutoroute(autoroute) => { autoroute.estimate_linear_progress() } ExecutionStepper::PlanarAutoroute(autoroute) => autoroute.estimate_linear_progress(), - ExecutionStepper::TopoAutoroute(toporoute) => toporoute.estimate_linear_progress(), - ExecutionStepper::PlaceVia(place_via) => place_via.estimate_linear_progress(), - ExecutionStepper::RemoveBands(remove_bands) => remove_bands.estimate_linear_progress(), - ExecutionStepper::MeasureLength(measure_length) => { - measure_length.estimate_linear_progress() + ExecutionStepper::TopoAutoroute(..) => { + LinearScale::new(0, 0, LinearScale::new(0.0, 0.0, ())) + } + ExecutionStepper::PlaceVia(..) => { + LinearScale::new(0, 0, LinearScale::new(0.0, 0.0, ())) + } + ExecutionStepper::RemoveBands(..) => { + LinearScale::new(0, 0, LinearScale::new(0.0, 0.0, ())) + } + ExecutionStepper::MeasureLength(..) => { + LinearScale::new(0, 0, LinearScale::new(0.0, 0.0, ())) } } } diff --git a/src/autorouter/measure_length.rs b/src/autorouter/measure_length.rs index 9884e0e..1ccc269 100644 --- a/src/autorouter/measure_length.rs +++ b/src/autorouter/measure_length.rs @@ -8,7 +8,6 @@ use crate::{ board::AccessMesadata, geometry::shape::MeasureLength as MeasureLengthTrait, graph::MakeRef, - stepper::EstimateLinearProgress, }; use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError}; @@ -48,7 +47,4 @@ impl MeasureLengthExecutionStepper { } } -impl EstimateLinearProgress for MeasureLengthExecutionStepper { - type Value = f64; -} impl GetDebugOverlayData for MeasureLengthExecutionStepper {} diff --git a/src/autorouter/multilayer_autoroute.rs b/src/autorouter/multilayer_autoroute.rs index 320a6c5..0aff5c0 100644 --- a/src/autorouter/multilayer_autoroute.rs +++ b/src/autorouter/multilayer_autoroute.rs @@ -22,7 +22,7 @@ use crate::{ geometry::{edit::Edit, primitive::PrimitiveShape}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, stepper::{ - Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step, + Abort, EstimateLinearProgress, LinearScale, ReconfiguratorStatus, Reconfigure, Step, }, }; @@ -120,9 +120,10 @@ impl Reconfigure> for MultilayerAutorouteExecut } impl EstimateLinearProgress for MultilayerAutorouteExecutionStepper { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { self.planar.estimate_linear_progress() } } diff --git a/src/autorouter/multilayer_reconfigurator.rs b/src/autorouter/multilayer_reconfigurator.rs index bceac00..4623069 100644 --- a/src/autorouter/multilayer_reconfigurator.rs +++ b/src/autorouter/multilayer_reconfigurator.rs @@ -30,7 +30,7 @@ use crate::{ geometry::primitive::PrimitiveShape, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, stepper::{ - Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step, + Abort, EstimateLinearProgress, LinearScale, ReconfiguratorStatus, Reconfigure, Step, }, }; @@ -142,9 +142,10 @@ impl Abort> for MultilayerAutorouteReconfigurat } impl EstimateLinearProgress for MultilayerAutorouteReconfigurator { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { self.stepper.estimate_linear_progress() } } diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index 2092e19..b7c9c79 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -12,7 +12,6 @@ use crate::{ AccessMesadata, }, layout::{via::ViaWeight, LayoutEdit}, - stepper::EstimateLinearProgress, }; use super::{invoker::GetDebugOverlayData, Autorouter, AutorouterError}; @@ -53,7 +52,4 @@ impl PlaceViaExecutionStepper { } } -impl EstimateLinearProgress for PlaceViaExecutionStepper { - type Value = f64; -} impl GetDebugOverlayData for PlaceViaExecutionStepper {} diff --git a/src/autorouter/planar_autoroute.rs b/src/autorouter/planar_autoroute.rs index 27e6d5e..4e52c58 100644 --- a/src/autorouter/planar_autoroute.rs +++ b/src/autorouter/planar_autoroute.rs @@ -21,7 +21,7 @@ use crate::{ router::{ navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router, }, - stepper::{Abort, EstimateLinearProgress, LinearProgress, Reconfigure, Step}, + stepper::{Abort, EstimateLinearProgress, LinearScale, Reconfigure, Step}, }; use super::{ @@ -304,16 +304,22 @@ impl Reconfigure> for PlanarAutorouteExecutionS } impl EstimateLinearProgress for PlanarAutorouteExecutionStepper { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { - LinearProgress::new( - self.curr_ratline_index as f64 - + self.route.as_ref().map_or(0.0, |route| { - route.estimate_linear_progress().value() - / route.estimate_linear_progress().maximum() - }), - self.configuration().ratlines.len() as f64, + fn estimate_linear_progress(&self) -> LinearScale> { + LinearScale::new( + self.curr_ratline_index, + self.configuration().ratlines.len(), + LinearScale::new( + self.route + .as_ref() + .map_or(0.0, |route| *route.estimate_linear_progress().value()), + self.route + .as_ref() + .map_or(0.0, |route| *route.estimate_linear_progress().maximum()), + (), + ), ) } } diff --git a/src/autorouter/planar_reconfigurator.rs b/src/autorouter/planar_reconfigurator.rs index 856c853..3b305c4 100644 --- a/src/autorouter/planar_reconfigurator.rs +++ b/src/autorouter/planar_reconfigurator.rs @@ -25,7 +25,7 @@ use crate::{ geometry::primitive::PrimitiveShape, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, stepper::{ - Abort, EstimateLinearProgress, LinearProgress, ReconfiguratorStatus, Reconfigure, Step, + Abort, EstimateLinearProgress, LinearScale, ReconfiguratorStatus, Reconfigure, Step, }, }; @@ -121,9 +121,10 @@ impl Abort> for PlanarAutorouteReconfigurator { } impl EstimateLinearProgress for PlanarAutorouteReconfigurator { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { self.stepper.estimate_linear_progress() } } diff --git a/src/autorouter/remove_bands.rs b/src/autorouter/remove_bands.rs index 8ca81ae..0e500de 100644 --- a/src/autorouter/remove_bands.rs +++ b/src/autorouter/remove_bands.rs @@ -4,10 +4,7 @@ //! Provides functionality to remove bands from the layout. -use crate::{ - board::{edit::BoardEdit, AccessMesadata}, - stepper::EstimateLinearProgress, -}; +use crate::board::{edit::BoardEdit, AccessMesadata}; use super::{invoker::GetDebugOverlayData, selection::BandSelection, Autorouter, AutorouterError}; @@ -48,7 +45,4 @@ impl RemoveBandsExecutionStepper { } } -impl EstimateLinearProgress for RemoveBandsExecutionStepper { - type Value = f64; -} impl GetDebugOverlayData for RemoveBandsExecutionStepper {} diff --git a/src/interactor/activity.rs b/src/interactor/activity.rs index 787309c..ba13ad5 100644 --- a/src/interactor/activity.rs +++ b/src/interactor/activity.rs @@ -25,7 +25,7 @@ use crate::{ ng, thetastar::ThetastarStepper, }, - stepper::{Abort, EstimateLinearProgress, LinearProgress, OnEvent, Step}, + stepper::{Abort, EstimateLinearProgress, LinearScale, OnEvent, Step}, }; /// Stores the interactive input data from the user. @@ -101,11 +101,14 @@ impl Abort> for ActivityStepper { // Since enum_dispatch does not really support generics, we implement this the // long way. impl EstimateLinearProgress for ActivityStepper { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { match self { - ActivityStepper::Interaction(..) => LinearProgress::new(0.0, 0.0), + ActivityStepper::Interaction(..) => { + LinearScale::new(0, 0, LinearScale::new(0.0, 0.0, ())) + } ActivityStepper::Execution(execution) => execution.estimate_linear_progress(), } } @@ -193,9 +196,10 @@ impl OnEvent, InteractiveEvent } impl EstimateLinearProgress for ActivityStepperWithStatus { - type Value = f64; + type Value = usize; + type Subscale = LinearScale; - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale> { self.activity.estimate_linear_progress() } } diff --git a/src/router/ng/router.rs b/src/router/ng/router.rs index 5e328a7..683d40f 100644 --- a/src/router/ng/router.rs +++ b/src/router/ng/router.rs @@ -233,10 +233,6 @@ impl AutorouteExecutionStepp } } -impl EstimateLinearProgress for AutorouteExecutionStepper { - type Value = f64; -} - impl GetDebugOverlayData for AutorouteExecutionStepper { fn maybe_topo_navmesh(&self) -> Option> { Some(pie::navmesh::NavmeshRef { diff --git a/src/router/route.rs b/src/router/route.rs index 18d5d4c..3d476a4 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -19,7 +19,7 @@ use crate::{ thetastar::{ThetastarError, ThetastarStepper}, Router, RouterThetastarStrategy, }, - stepper::{EstimateLinearProgress, LinearProgress, Step}, + stepper::{EstimateLinearProgress, LinearScale, Step}, }; #[derive(Getters, Dissolve)] @@ -101,8 +101,9 @@ impl Step, BandTermsegIndex> for RouteStepper { impl EstimateLinearProgress for RouteStepper { type Value = f64; + type Subscale = (); - fn estimate_linear_progress(&self) -> LinearProgress { + fn estimate_linear_progress(&self) -> LinearScale { self.thetastar.estimate_linear_progress() } } diff --git a/src/router/thetastar.rs b/src/router/thetastar.rs index 2cbe91e..08bf52c 100644 --- a/src/router/thetastar.rs +++ b/src/router/thetastar.rs @@ -20,7 +20,7 @@ use thiserror::Error; use std::cmp::Ordering; -use crate::stepper::{EstimateLinearProgress, LinearProgress, Step}; +use crate::stepper::{EstimateLinearProgress, LinearScale, Step}; #[derive(Copy, Clone, Debug)] pub struct MinScored(pub K, pub T); @@ -451,8 +451,13 @@ where K: Measure + Copy + Sub, { type Value = K; + type Subscale = (); - fn estimate_linear_progress(&self) -> LinearProgress { - LinearProgress::new(self.progress_estimate_value, self.progress_estimate_maximum) + fn estimate_linear_progress(&self) -> LinearScale { + LinearScale::new( + self.progress_estimate_value, + self.progress_estimate_maximum, + (), + ) } } diff --git a/src/stepper.rs b/src/stepper.rs index 24919dc..d11801e 100644 --- a/src/stepper.rs +++ b/src/stepper.rs @@ -84,22 +84,36 @@ pub trait OnEvent { } #[derive(Clone, Copy, Debug, Getters)] -pub struct LinearProgress { +pub struct LinearScale { value: V, maximum: V, + subscale: S, } -impl LinearProgress { - pub fn new(value: V, maximum: V) -> Self { - Self { value, maximum } +impl LinearScale { + pub fn new(value: V, maximum: V, subscale: S) -> Self { + Self { + value, + maximum, + subscale, + } + } +} + +impl Default for LinearScale { + fn default() -> Self { + Self { + value: V::default(), + maximum: V::default(), + subscale: (), + } } } /// Some steppers report estimates of how far they are from completion. pub trait EstimateLinearProgress { - type Value: Default; + type Value; + type Subscale; - fn estimate_linear_progress(&self) -> LinearProgress { - LinearProgress::new(Self::Value::default(), Self::Value::default()) - } + fn estimate_linear_progress(&self) -> LinearScale; }