diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index c9a61d4..1c02b57 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -4,9 +4,9 @@ use spade::InsertionError; use crate::{ autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex}, - drawing::rules::RulesTrait, - layout::Layout, - router::Router, + drawing::{dot::FixedDotIndex, rules::RulesTrait}, + layout::{connectivity::BandIndex, Layout}, + router::{Router, RouterObserverTrait, RoutingError}, triangulation::GetVertexIndex, }; @@ -23,13 +23,13 @@ impl Autorouter { }) } - pub fn autoroute(&mut self) { + pub fn autoroute(&mut self, observer: &mut impl RouterObserverTrait) { //for ratline in self.overlay.ratsnest().graph().edge_references() { // For now, let's only take the first ratline. let ratline = self.ratsnest.graph().edge_references().next().unwrap(); - self.route( + /*self.route( self.ratsnest .graph() .node_weight(ratline.source()) @@ -40,13 +40,29 @@ impl Autorouter { .node_weight(ratline.target()) .unwrap() .vertex_index(), - ); + observer, + );*/ //} } - fn route(&mut self, from: RatsnestVertexIndex, to: RatsnestVertexIndex) { - todo!(); + fn route( + &mut self, + from: RatsnestVertexIndex, + to: RatsnestVertexIndex, + observer: &mut impl RouterObserverTrait, + ) -> Result { + let from_dot = self.terminating_dot(from); + let to_dot = self.terminating_dot(to); + + self.router.route_band(from_dot, to_dot, 3.0, observer) + } + + fn terminating_dot(&mut self, vertex: RatsnestVertexIndex) -> FixedDotIndex { + match vertex { + RatsnestVertexIndex::FixedDot(dot) => dot, + RatsnestVertexIndex::Zone(zone) => self.router.layout_mut().zone_apex(zone), + } } pub fn router(&self) -> &Router { diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 128b544..a3971ea 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -8,7 +8,7 @@ use std::{ use topola::{ autorouter::Autorouter, - drawing::{graph::MakePrimitive, primitive::MakePrimitiveShape, Drawing}, + drawing::{graph::MakePrimitive, primitive::MakePrimitiveShape, rules::RulesTrait, Drawing}, dsn::{design::DsnDesign, rules::DsnRules}, geometry::{ compound::CompoundManagerTrait, @@ -17,6 +17,12 @@ use topola::{ }, layout::{zone::MakePolyShape, Layout}, math::Circle, + router::{ + draw::DrawException, + navmesh::{NavmeshEdgeReference, VertexIndex}, + tracer::{Trace, Tracer}, + RouterObserverTrait, + }, }; use crate::{overlay::Overlay, painter::Painter}; @@ -61,6 +67,22 @@ impl App { } } +struct EmptyRouterObserver; + +impl RouterObserverTrait for EmptyRouterObserver { + fn on_rework(&mut self, _tracer: &Tracer, _trace: &Trace) {} + fn before_probe(&mut self, _tracer: &Tracer, _trace: &Trace, _edge: NavmeshEdgeReference) {} + fn on_probe( + &mut self, + _tracer: &Tracer, + _trace: &Trace, + _edge: NavmeshEdgeReference, + _result: Result<(), DrawException>, + ) { + } + fn on_estimate(&mut self, _tracer: &Tracer, _vertex: VertexIndex) {} +} + impl eframe::App for App { /// Called to save state before shutdown. fn save(&mut self, storage: &mut dyn eframe::Storage) { @@ -112,7 +134,16 @@ impl eframe::App for App { } } }); - ui.add_space(16.0); + + ui.separator(); + + if ui.button("Autoroute").clicked() { + if let Some(ref mut autorouter) = &mut self.autorouter { + autorouter.autoroute(&mut EmptyRouterObserver {}); + } + } + + ui.separator(); egui::widgets::global_dark_light_mode_buttons(ui); }); diff --git a/src/router/router.rs b/src/router/router.rs index aa66d96..59e6490 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -197,4 +197,8 @@ impl Router { pub fn layout(&self) -> &Layout { &self.layout } + + pub fn layout_mut(&mut self) -> &mut Layout { + &mut self.layout + } }