diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index fe559f1..0368dc0 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -17,15 +17,17 @@ use super::{ pub enum CompareDetoursStatus { Running, - Finished(f64), + Finished(f64, f64), } -impl TryInto for CompareDetoursStatus { +impl TryInto<(f64, f64)> for CompareDetoursStatus { type Error = (); - fn try_into(self) -> Result { + fn try_into(self) -> Result<(f64, f64), ()> { match self { CompareDetoursStatus::Running => Err(()), - CompareDetoursStatus::Finished(delta) => Ok(delta), + CompareDetoursStatus::Finished(total_length1, total_length2) => { + Ok((total_length1, total_length2)) + } } } } @@ -60,7 +62,7 @@ impl CompareDetours { // XXX: Do we really need this to be a stepper? We don't use at the moment, as sorting functions // aren't steppable either. It may be useful for debugging later on tho. -impl Step, CompareDetoursStatus, AutorouterError, f64> +impl Step, CompareDetoursStatus, AutorouterError, (f64, f64)> for CompareDetours { fn step( @@ -69,7 +71,8 @@ impl Step, CompareDetoursStatus, AutorouterErro ) -> Result { if self.done { return Ok(CompareDetoursStatus::Finished( - self.total_length1.unwrap() - self.total_length2.unwrap(), + self.total_length1.unwrap(), + self.total_length2.unwrap(), )); } @@ -101,7 +104,8 @@ impl Step, CompareDetoursStatus, AutorouterErro autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1]); Ok(CompareDetoursStatus::Finished( - self.total_length1.unwrap() - self.total_length2.unwrap(), + self.total_length1.unwrap(), + self.total_length2.unwrap(), )) } } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 9fc389c..fe79172 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -50,10 +50,10 @@ pub enum InvokerError { Autorouter(#[from] AutorouterError), } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub enum InvokerStatus { Running, - Finished, + Finished(String), } impl TryInto<()> for InvokerStatus { @@ -61,7 +61,7 @@ impl TryInto<()> for InvokerStatus { fn try_into(self) -> Result<(), ()> { match self { InvokerStatus::Running => Err(()), - InvokerStatus::Finished => Ok(()), + InvokerStatus::Finished(..) => Ok(()), } } } @@ -91,19 +91,30 @@ impl Execute { Execute::Autoroute(autoroute) => match autoroute.step(&mut invoker.autorouter)? { AutorouteStatus::Running => Ok(InvokerStatus::Running), AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running), - AutorouteStatus::Finished => Ok(InvokerStatus::Finished), + AutorouteStatus::Finished => Ok(InvokerStatus::Finished(String::from( + "finished autorouting", + ))), }, Execute::PlaceVia(place_via) => { place_via.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished) + Ok(InvokerStatus::Finished(String::from( + "finished placing via", + ))) } Execute::RemoveBands(remove_bands) => { remove_bands.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished) + Ok(InvokerStatus::Finished(String::from( + "finished removing bands", + ))) } Execute::CompareDetours(compare) => match compare.step(&mut invoker.autorouter)? { CompareDetoursStatus::Running => Ok(InvokerStatus::Running), - CompareDetoursStatus::Finished(delta) => Ok(InvokerStatus::Finished), + CompareDetoursStatus::Finished(total_length1, total_length2) => { + Ok(InvokerStatus::Finished(String::from(format!( + "total detour lengths are {} and {}", + total_length1, total_length2 + )))) + } }, } } @@ -113,12 +124,12 @@ impl Step, InvokerStatus, InvokerError, ()> for Ex fn step(&mut self, invoker: &mut Invoker) -> Result { match self.step_catch_err(invoker) { Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running), - Ok(InvokerStatus::Finished) => { + Ok(InvokerStatus::Finished(msg)) => { if let Some(command) = invoker.ongoing_command.take() { invoker.history.do_(command); } - Ok(InvokerStatus::Finished) + Ok(InvokerStatus::Finished(msg)) } Err(err) => { invoker.ongoing_command = None; @@ -146,12 +157,12 @@ impl ExecuteWithStatus { invoker: &mut Invoker, ) -> Result { let status = self.execute.step(invoker)?; - self.maybe_status = Some(status); + self.maybe_status = Some(status.clone()); Ok(status) } pub fn maybe_status(&self) -> Option { - self.maybe_status + self.maybe_status.clone() } } @@ -212,7 +223,7 @@ impl Invoker { Err(err) => return Err(err), }; - if let InvokerStatus::Finished = status { + if let InvokerStatus::Finished(..) = status { self.history.set_undone(std::iter::empty()); return Ok(()); } @@ -269,7 +280,7 @@ impl Invoker { Err(err) => return Err(err), }; - if let InvokerStatus::Finished = status { + if let InvokerStatus::Finished(..) = status { return Ok(self.history.redo()?); } } diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index b01ea78..89900c0 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -188,7 +188,8 @@ impl eframe::App for App { &self.maybe_layers, ); - self.bottom.update(ctx, &self.viewport, viewport_rect); + self.bottom + .update(ctx, &self.viewport, viewport_rect, &self.maybe_execute); if ctx.input(|i| i.key_pressed(egui::Key::Escape)) { ctx.send_viewport_cmd(egui::ViewportCommand::Close); diff --git a/src/bin/topola-egui/bottom.rs b/src/bin/topola-egui/bottom.rs index f295d12..dca3096 100644 --- a/src/bin/topola-egui/bottom.rs +++ b/src/bin/topola-egui/bottom.rs @@ -1,3 +1,5 @@ +use topola::autorouter::invoker::{Execute, ExecuteWithStatus, InvokerStatus}; + use crate::viewport::Viewport; pub struct Bottom {} @@ -7,13 +9,31 @@ impl Bottom { Self {} } - pub fn update(&mut self, ctx: &egui::Context, viewport: &Viewport, viewport_rect: egui::Rect) { + pub fn update( + &mut self, + ctx: &egui::Context, + viewport: &Viewport, + viewport_rect: egui::Rect, + maybe_execute: &Option, + ) { egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| { let transform = egui::emath::RectTransform::from_to(viewport.from_rect, viewport_rect); let latest_pos = transform .inverse() .transform_pos(ctx.input(|i| i.pointer.latest_pos().unwrap_or_default())); - ui.label(format!("x: {} y: {}", latest_pos.x, -latest_pos.y)); + + let mut message = String::from(""); + + if let Some(execute) = maybe_execute { + if let Some(InvokerStatus::Finished(msg)) = execute.maybe_status() { + message = msg; + } + } + + ui.label(format!( + "x: {} y: {} \t {}", + latest_pos.x, -latest_pos.y, message + )); }); } } diff --git a/src/bin/topola-egui/top.rs b/src/bin/topola-egui/top.rs index 720153d..5d85b7d 100644 --- a/src/bin/topola-egui/top.rs +++ b/src/bin/topola-egui/top.rs @@ -213,7 +213,7 @@ impl Top { ctx.send_viewport_cmd(egui::ViewportCommand::Close); } else if autoroute.consume_key_triggered(ctx, ui) { if maybe_execute.as_mut().map_or(true, |execute| { - matches!(execute.maybe_status(), Some(InvokerStatus::Finished)) + matches!(execute.maybe_status(), Some(InvokerStatus::Finished(..))) }) { if let (Some(invoker), Some(ref mut overlay)) = ( arc_mutex_maybe_invoker.lock().unwrap().as_mut(), @@ -230,7 +230,7 @@ impl Top { } else if place_via.consume_key_enabled(ctx, ui, &mut self.is_placing_via) { } else if remove_bands.consume_key_triggered(ctx, ui) { if maybe_execute.as_mut().map_or(true, |execute| { - matches!(execute.maybe_status(), Some(InvokerStatus::Finished)) + matches!(execute.maybe_status(), Some(InvokerStatus::Finished(..))) }) { if let (Some(invoker), Some(ref mut overlay)) = ( arc_mutex_maybe_invoker.lock().unwrap().as_mut(), @@ -253,7 +253,7 @@ impl Top { } } else if compare_detours.consume_key_triggered(ctx, ui) { if maybe_execute.as_mut().map_or(true, |execute| { - matches!(execute.maybe_status(), Some(InvokerStatus::Finished)) + matches!(execute.maybe_status(), Some(InvokerStatus::Finished(..))) }) { if let (Some(invoker), Some(ref mut overlay)) = ( arc_mutex_maybe_invoker.lock().unwrap().as_mut(),