egui,autorouter: display message once command completes

This commit is contained in:
Mikolaj Wielgus 2024-08-06 02:34:54 +02:00
parent c12eea5b4d
commit 33206567e3
5 changed files with 62 additions and 26 deletions

View File

@ -17,15 +17,17 @@ use super::{
pub enum CompareDetoursStatus {
Running,
Finished(f64),
Finished(f64, f64),
}
impl TryInto<f64> for CompareDetoursStatus {
impl TryInto<(f64, f64)> for CompareDetoursStatus {
type Error = ();
fn try_into(self) -> Result<f64, ()> {
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<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterError, f64>
impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterError, (f64, f64)>
for CompareDetours
{
fn step(
@ -69,7 +71,8 @@ impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterErro
) -> Result<CompareDetoursStatus, AutorouterError> {
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<M: AccessMesadata> Step<Autorouter<M>, 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(),
))
}
}

View File

@ -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<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, InvokerError, ()> for Ex
fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> {
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<M>,
) -> Result<InvokerStatus, InvokerError> {
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<InvokerStatus> {
self.maybe_status
self.maybe_status.clone()
}
}
@ -212,7 +223,7 @@ impl<M: AccessMesadata> Invoker<M> {
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<M: AccessMesadata> Invoker<M> {
Err(err) => return Err(err),
};
if let InvokerStatus::Finished = status {
if let InvokerStatus::Finished(..) = status {
return Ok(self.history.redo()?);
}
}

View File

@ -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);

View File

@ -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<ExecuteWithStatus>,
) {
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
));
});
}
}

View File

@ -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(),