diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 618cedc..7eb79bf 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -1,7 +1,10 @@ use std::sync::{Arc, Mutex}; use geo::Point; -use petgraph::visit::{EdgeRef, IntoEdgeReferences}; +use petgraph::{ + graph::EdgeIndices, + visit::{EdgeRef, IntoEdgeReferences}, +}; use spade::InsertionError; use crate::{ @@ -12,6 +15,57 @@ use crate::{ triangulation::GetVertexIndex, }; +pub struct Autoroute { + edge_indices: EdgeIndices, +} + +impl Autoroute { + pub fn next( + &mut self, + autorouter: &mut Autorouter, + observer: &mut impl RouterObserverTrait, + ) -> Option<()> { + let Some(ratline) = self.edge_indices.next() else { + return None; + }; + let (from, to) = autorouter.ratsnest.graph().edge_endpoints(ratline).unwrap(); + + let (from_dot, to_dot) = { + let layout = autorouter.router.layout(); + let mut layout = layout.lock().unwrap(); + + let from_dot = match autorouter + .ratsnest + .graph() + .node_weight(from) + .unwrap() + .vertex_index() + { + RatsnestVertexIndex::FixedDot(dot) => dot, + RatsnestVertexIndex::Zone(zone) => layout.zone_apex(zone), + }; + + let to_dot = match autorouter + .ratsnest + .graph() + .node_weight(to) + .unwrap() + .vertex_index() + { + RatsnestVertexIndex::FixedDot(dot) => dot, + RatsnestVertexIndex::Zone(zone) => layout.zone_apex(zone), + }; + + (from_dot, to_dot) + }; + + autorouter + .router + .route_band(from_dot, to_dot, 100.0, observer); + Some(()) + } +} + pub struct Autorouter { ratsnest: Ratsnest, router: Router, @@ -27,38 +81,15 @@ impl Autorouter { } pub fn autoroute(&mut self, observer: &mut impl RouterObserverTrait) { - for ratline in self.ratsnest.graph().edge_references() { - let from = self - .ratsnest - .graph() - .node_weight(ratline.source()) - .unwrap() - .vertex_index(); - let to = self - .ratsnest - .graph() - .node_weight(ratline.target()) - .unwrap() - .vertex_index(); + let mut it = self.autoroute_iter(); + while let Some(()) = it.next(self, observer) { + // + } + } - let (from_dot, to_dot) = { - let layout = self.router.layout(); - let mut layout = layout.lock().unwrap(); - - let from_dot = match from { - RatsnestVertexIndex::FixedDot(dot) => dot, - RatsnestVertexIndex::Zone(zone) => layout.zone_apex(zone), - }; - - let to_dot = match to { - RatsnestVertexIndex::FixedDot(dot) => dot, - RatsnestVertexIndex::Zone(zone) => layout.zone_apex(zone), - }; - - (from_dot, to_dot) - }; - - self.router.route_band(from_dot, to_dot, 100.0, observer); + pub fn autoroute_iter(&mut self) -> Autoroute { + Autoroute { + edge_indices: self.ratsnest.graph().edge_indices(), } } diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index b626a7a..6f0b945 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -4,9 +4,9 @@ use enum_dispatch::enum_dispatch; use geo::Point; use petgraph::{ data::{Element, FromElements}, - stable_graph::{NodeIndex, StableGraph, StableUnGraph}, + graph::{NodeIndex, UnGraph}, unionfind::UnionFind, - visit::{self, EdgeRef, IntoEdgeReferences, NodeIndexable}, + visit::{EdgeRef, IntoEdgeReferences, NodeIndexable}, }; use spade::{HasPosition, InsertionError, Point2}; @@ -53,7 +53,7 @@ impl HasPosition for VertexWeight { } pub struct Ratsnest { - graph: StableUnGraph, + graph: UnGraph, } impl Ratsnest { @@ -65,7 +65,7 @@ impl Ratsnest { } let mut this = Self { - graph: StableUnGraph::default(), + graph: UnGraph::default(), }; let mut triangulations = HashMap::new(); @@ -149,7 +149,7 @@ impl Ratsnest { Ok(this) } - pub fn graph(&self) -> &StableUnGraph { + pub fn graph(&self) -> &UnGraph { &self.graph } }