Revert "egui: perform routing in separate thread or task"

This reverts commit 4144ee361f.

Instead of mutexing the autorouter, we'll mutex the layout.
This commit is contained in:
Mikolaj Wielgus 2024-05-04 15:03:36 +02:00
parent 4144ee361f
commit ea854abfc7
1 changed files with 96 additions and 108 deletions

View File

@ -3,10 +3,7 @@ use geo::point;
use petgraph::visit::{EdgeRef, IntoEdgeReferences}; use petgraph::visit::{EdgeRef, IntoEdgeReferences};
use std::{ use std::{
future::Future, future::Future,
sync::{ sync::mpsc::{channel, Receiver, Sender},
mpsc::{channel, Receiver, Sender},
Arc, Mutex,
},
}; };
use topola::{ use topola::{
@ -43,7 +40,7 @@ pub struct App {
overlay: Option<Overlay>, overlay: Option<Overlay>,
#[serde(skip)] #[serde(skip)]
autorouter: Option<Arc<Mutex<Autorouter<DsnRules>>>>, autorouter: Option<Autorouter<DsnRules>>,
#[serde(skip)] #[serde(skip)]
text_channel: (Sender<String>, Receiver<String>), text_channel: (Sender<String>, Receiver<String>),
@ -111,14 +108,14 @@ impl eframe::App for App {
let design = DsnDesign::load_from_string(file_contents).unwrap(); let design = DsnDesign::load_from_string(file_contents).unwrap();
let layout = design.make_layout(); let layout = design.make_layout();
self.overlay = Some(Overlay::new(&layout).unwrap()); self.overlay = Some(Overlay::new(&layout).unwrap());
self.autorouter = Some(Arc::new(Mutex::new(Autorouter::new(layout).unwrap()))); self.autorouter = Some(Autorouter::new(layout).unwrap());
} }
} else { } else {
if let Ok(path) = self.text_channel.1.try_recv() { if let Ok(path) = self.text_channel.1.try_recv() {
let design = DsnDesign::load_from_file(&path).unwrap(); let design = DsnDesign::load_from_file(&path).unwrap();
let layout = design.make_layout(); let layout = design.make_layout();
self.overlay = Some(Overlay::new(&layout).unwrap()); self.overlay = Some(Overlay::new(&layout).unwrap());
self.autorouter = Some(Arc::new(Mutex::new(Autorouter::new(layout).unwrap()))); self.autorouter = Some(Autorouter::new(layout).unwrap());
} }
} }
@ -153,12 +150,8 @@ impl eframe::App for App {
ui.separator(); ui.separator();
if ui.button("Autoroute").clicked() { if ui.button("Autoroute").clicked() {
if let Some(autorouter_arc_mutex) = &self.autorouter { if let Some(ref mut autorouter) = &mut self.autorouter {
let autorouter_mutex = autorouter_arc_mutex.clone();
execute(async move {
let mut autorouter = autorouter_mutex.lock().unwrap();
autorouter.autoroute(&mut EmptyRouterObserver {}); autorouter.autoroute(&mut EmptyRouterObserver {});
});
} }
} }
@ -199,10 +192,7 @@ impl eframe::App for App {
let transform = egui::emath::RectTransform::from_to(self.from_rect, viewport_rect); let transform = egui::emath::RectTransform::from_to(self.from_rect, viewport_rect);
let mut painter = Painter::new(ui, transform); let mut painter = Painter::new(ui, transform);
if let (Some(autorouter_arc_mutex), Some(overlay)) = if let (Some(autorouter), Some(overlay)) = (&self.autorouter, &mut self.overlay) {
(&self.autorouter, &mut self.overlay)
{
if let Ok(autorouter) = autorouter_arc_mutex.try_lock() {
if ctx.input(|i| i.pointer.any_click()) { if ctx.input(|i| i.pointer.any_click()) {
overlay.click( overlay.click(
autorouter.router().layout(), autorouter.router().layout(),
@ -232,8 +222,7 @@ impl eframe::App for App {
} }
for zone in autorouter.router().layout().layer_zone_nodes(1) { for zone in autorouter.router().layout().layer_zone_nodes(1) {
let color = let color = if overlay.selection().contains(&GenericNode::Compound(zone)) {
if overlay.selection().contains(&GenericNode::Compound(zone)) {
egui::Color32::from_rgb(100, 100, 255) egui::Color32::from_rgb(100, 100, 255)
} else { } else {
egui::Color32::from_rgb(52, 52, 200) egui::Color32::from_rgb(52, 52, 200)
@ -266,8 +255,7 @@ impl eframe::App for App {
} }
for zone in autorouter.router().layout().layer_zone_nodes(0) { for zone in autorouter.router().layout().layer_zone_nodes(0) {
let color = let color = if overlay.selection().contains(&GenericNode::Compound(zone)) {
if overlay.selection().contains(&GenericNode::Compound(zone)) {
egui::Color32::from_rgb(255, 100, 100) egui::Color32::from_rgb(255, 100, 100)
} else { } else {
egui::Color32::from_rgb(200, 52, 52) egui::Color32::from_rgb(200, 52, 52)
@ -294,7 +282,7 @@ impl eframe::App for App {
painter.paint_edge(from, to, egui::Color32::from_rgb(90, 90, 200)); painter.paint_edge(from, to, egui::Color32::from_rgb(90, 90, 200));
} }
} //unreachable!();
} }
}) })
}); });