From 6884ca6531104c33927c35c3c60c428c2e5f8623 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 10 Jun 2024 16:49:05 +0200 Subject: [PATCH] egui: add button to modally invoke via placement --- src/bin/topola-egui/app.rs | 45 +++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 72ab3fd..21d4f80 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -30,7 +30,7 @@ use topola::{ shape::ShapeTrait, GenericNode, }, - layout::{zone::MakePolyShape, Layout}, + layout::{via::ViaWeight, zone::MakePolyShape, Layout}, math::Circle, router::{ draw::DrawException, @@ -71,6 +71,9 @@ pub struct App { #[serde(skip)] from_rect: egui::emath::Rect, + #[serde(skip)] + is_placing_via: bool, + #[serde(skip)] show_ratsnest: bool, } @@ -83,6 +86,7 @@ impl Default for App { shared_data: Default::default(), text_channel: channel(), from_rect: egui::Rect::from_x_y_ranges(0.0..=1000000.0, 0.0..=500000.0), + is_placing_via: false, show_ratsnest: true, } } @@ -291,6 +295,10 @@ impl eframe::App for App { } } + ui.toggle_value(&mut self.is_placing_via, "Place Via"); + + ui.separator(); + if ui.button("Undo").clicked() || ctx.input_mut(|i| i.consume_key(egui::Modifiers::CTRL, egui::Key::Z)) { @@ -355,6 +363,34 @@ impl eframe::App for App { let mut painter = Painter::new(ui, transform); if let Some(invoker_arc_mutex) = &self.invoker { + if ctx.input(|i| i.pointer.any_click()) { + if self.is_placing_via { + let invoker_arc_mutex = invoker_arc_mutex.clone(); + + execute(async move { + let mut invoker = invoker_arc_mutex.lock().unwrap(); + invoker.execute( + Command::PlaceVia(ViaWeight { + from_layer: 0, + to_layer: 0, + circle: Circle { + pos: point! {x: latest_pos.x as f64, y: -latest_pos.y as f64}, + r: 100.0, + }, + maybe_net: None, + }), + &mut EmptyRouterObserver, + ); + }); + } else if let Some(overlay) = &mut self.overlay { + let invoker = invoker_arc_mutex.lock().unwrap(); + overlay.click( + invoker.autorouter().board(), + point! {x: latest_pos.x as f64, y: -latest_pos.y as f64}, + ); + } + } + if let (invoker, shared_data, Some(overlay)) = ( &invoker_arc_mutex.lock().unwrap(), self.shared_data.lock().unwrap(), @@ -362,13 +398,6 @@ impl eframe::App for App { ) { let board = invoker.autorouter().board(); - if ctx.input(|i| i.pointer.any_click()) { - overlay.click( - board, - point! {x: latest_pos.x as f64, y: -latest_pos.y as f64}, - ); - } - for primitive in board.layout().drawing().layer_primitive_nodes(1) { let shape = primitive.primitive(board.layout().drawing()).shape();