mirror of https://codeberg.org/topola/topola.git
egui,autorouter: display message once command completes
This commit is contained in:
parent
c12eea5b4d
commit
33206567e3
|
|
@ -17,15 +17,17 @@ use super::{
|
||||||
|
|
||||||
pub enum CompareDetoursStatus {
|
pub enum CompareDetoursStatus {
|
||||||
Running,
|
Running,
|
||||||
Finished(f64),
|
Finished(f64, f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<f64> for CompareDetoursStatus {
|
impl TryInto<(f64, f64)> for CompareDetoursStatus {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
fn try_into(self) -> Result<f64, ()> {
|
fn try_into(self) -> Result<(f64, f64), ()> {
|
||||||
match self {
|
match self {
|
||||||
CompareDetoursStatus::Running => Err(()),
|
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
|
// 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.
|
// 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
|
for CompareDetours
|
||||||
{
|
{
|
||||||
fn step(
|
fn step(
|
||||||
|
|
@ -69,7 +71,8 @@ impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterErro
|
||||||
) -> Result<CompareDetoursStatus, AutorouterError> {
|
) -> Result<CompareDetoursStatus, AutorouterError> {
|
||||||
if self.done {
|
if self.done {
|
||||||
return Ok(CompareDetoursStatus::Finished(
|
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]);
|
autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1]);
|
||||||
|
|
||||||
Ok(CompareDetoursStatus::Finished(
|
Ok(CompareDetoursStatus::Finished(
|
||||||
self.total_length1.unwrap() - self.total_length2.unwrap(),
|
self.total_length1.unwrap(),
|
||||||
|
self.total_length2.unwrap(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@ pub enum InvokerError {
|
||||||
Autorouter(#[from] AutorouterError),
|
Autorouter(#[from] AutorouterError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum InvokerStatus {
|
pub enum InvokerStatus {
|
||||||
Running,
|
Running,
|
||||||
Finished,
|
Finished(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<()> for InvokerStatus {
|
impl TryInto<()> for InvokerStatus {
|
||||||
|
|
@ -61,7 +61,7 @@ impl TryInto<()> for InvokerStatus {
|
||||||
fn try_into(self) -> Result<(), ()> {
|
fn try_into(self) -> Result<(), ()> {
|
||||||
match self {
|
match self {
|
||||||
InvokerStatus::Running => Err(()),
|
InvokerStatus::Running => Err(()),
|
||||||
InvokerStatus::Finished => Ok(()),
|
InvokerStatus::Finished(..) => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,19 +91,30 @@ impl Execute {
|
||||||
Execute::Autoroute(autoroute) => match autoroute.step(&mut invoker.autorouter)? {
|
Execute::Autoroute(autoroute) => match autoroute.step(&mut invoker.autorouter)? {
|
||||||
AutorouteStatus::Running => Ok(InvokerStatus::Running),
|
AutorouteStatus::Running => Ok(InvokerStatus::Running),
|
||||||
AutorouteStatus::Routed(..) => 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) => {
|
Execute::PlaceVia(place_via) => {
|
||||||
place_via.doit(&mut invoker.autorouter)?;
|
place_via.doit(&mut invoker.autorouter)?;
|
||||||
Ok(InvokerStatus::Finished)
|
Ok(InvokerStatus::Finished(String::from(
|
||||||
|
"finished placing via",
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
Execute::RemoveBands(remove_bands) => {
|
Execute::RemoveBands(remove_bands) => {
|
||||||
remove_bands.doit(&mut invoker.autorouter)?;
|
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)? {
|
Execute::CompareDetours(compare) => match compare.step(&mut invoker.autorouter)? {
|
||||||
CompareDetoursStatus::Running => Ok(InvokerStatus::Running),
|
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> {
|
fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> {
|
||||||
match self.step_catch_err(invoker) {
|
match self.step_catch_err(invoker) {
|
||||||
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),
|
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),
|
||||||
Ok(InvokerStatus::Finished) => {
|
Ok(InvokerStatus::Finished(msg)) => {
|
||||||
if let Some(command) = invoker.ongoing_command.take() {
|
if let Some(command) = invoker.ongoing_command.take() {
|
||||||
invoker.history.do_(command);
|
invoker.history.do_(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(InvokerStatus::Finished)
|
Ok(InvokerStatus::Finished(msg))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
invoker.ongoing_command = None;
|
invoker.ongoing_command = None;
|
||||||
|
|
@ -146,12 +157,12 @@ impl ExecuteWithStatus {
|
||||||
invoker: &mut Invoker<M>,
|
invoker: &mut Invoker<M>,
|
||||||
) -> Result<InvokerStatus, InvokerError> {
|
) -> Result<InvokerStatus, InvokerError> {
|
||||||
let status = self.execute.step(invoker)?;
|
let status = self.execute.step(invoker)?;
|
||||||
self.maybe_status = Some(status);
|
self.maybe_status = Some(status.clone());
|
||||||
Ok(status)
|
Ok(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_status(&self) -> Option<InvokerStatus> {
|
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),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let InvokerStatus::Finished = status {
|
if let InvokerStatus::Finished(..) = status {
|
||||||
self.history.set_undone(std::iter::empty());
|
self.history.set_undone(std::iter::empty());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +280,7 @@ impl<M: AccessMesadata> Invoker<M> {
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let InvokerStatus::Finished = status {
|
if let InvokerStatus::Finished(..) = status {
|
||||||
return Ok(self.history.redo()?);
|
return Ok(self.history.redo()?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,8 @@ impl eframe::App for App {
|
||||||
&self.maybe_layers,
|
&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)) {
|
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use topola::autorouter::invoker::{Execute, ExecuteWithStatus, InvokerStatus};
|
||||||
|
|
||||||
use crate::viewport::Viewport;
|
use crate::viewport::Viewport;
|
||||||
|
|
||||||
pub struct Bottom {}
|
pub struct Bottom {}
|
||||||
|
|
@ -7,13 +9,31 @@ impl Bottom {
|
||||||
Self {}
|
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| {
|
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||||
let transform = egui::emath::RectTransform::from_to(viewport.from_rect, viewport_rect);
|
let transform = egui::emath::RectTransform::from_to(viewport.from_rect, viewport_rect);
|
||||||
let latest_pos = transform
|
let latest_pos = transform
|
||||||
.inverse()
|
.inverse()
|
||||||
.transform_pos(ctx.input(|i| i.pointer.latest_pos().unwrap_or_default()));
|
.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
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ impl Top {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
} else if autoroute.consume_key_triggered(ctx, ui) {
|
} else if autoroute.consume_key_triggered(ctx, ui) {
|
||||||
if maybe_execute.as_mut().map_or(true, |execute| {
|
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)) = (
|
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
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 place_via.consume_key_enabled(ctx, ui, &mut self.is_placing_via) {
|
||||||
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
||||||
if maybe_execute.as_mut().map_or(true, |execute| {
|
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)) = (
|
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||||
|
|
@ -253,7 +253,7 @@ impl Top {
|
||||||
}
|
}
|
||||||
} else if compare_detours.consume_key_triggered(ctx, ui) {
|
} else if compare_detours.consume_key_triggered(ctx, ui) {
|
||||||
if maybe_execute.as_mut().map_or(true, |execute| {
|
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)) = (
|
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue