diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 2836825..0108d3c 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -31,6 +31,8 @@ pub enum AutorouteContinueStatus { Running, /// A specific segment has been successfully routed. Routed(BandTermsegIndex), + /// A specific segment was already routed and has been skipped. + Skipped(BandTermsegIndex), } /// Manages the autorouting process across multiple ratlines. @@ -106,30 +108,36 @@ impl Step, Option, AutorouteContinu let (source, target) = autorouter.ratline_endpoints(curr_ratline); - let band_termseg = { - let mut router = - Router::new(autorouter.board.layout_mut(), self.options.router_options); + let ret = if let Some(band_termseg) = autorouter.board.band_between_nodes(source, target) { + AutorouteContinueStatus::Skipped(band_termseg[false]) + } else { + let band_termseg = { + let mut router = + Router::new(autorouter.board.layout_mut(), self.options.router_options); - let ControlFlow::Break(band_termseg) = route.step(&mut router)? else { - return Ok(ControlFlow::Continue(AutorouteContinueStatus::Running)); + let ControlFlow::Break(band_termseg) = route.step(&mut router)? else { + return Ok(ControlFlow::Continue(AutorouteContinueStatus::Running)); + }; + band_termseg }; - band_termseg + + let band = autorouter + .board + .layout() + .drawing() + .loose_band_uid(band_termseg.into()); + + autorouter + .ratsnest + .assign_band_termseg_to_ratline(self.curr_ratline.unwrap(), band_termseg); + + autorouter + .board + .try_set_band_between_nodes(source, target, band); + + AutorouteContinueStatus::Routed(band_termseg) }; - let band = autorouter - .board - .layout() - .drawing() - .loose_band_uid(band_termseg.into()); - - autorouter - .ratsnest - .assign_band_termseg_to_ratline(self.curr_ratline.unwrap(), band_termseg); - - autorouter - .board - .try_set_band_between_nodes(source, target, band); - if let Some(new_ratline) = self.ratlines_iter.next() { let (source, target) = autorouter.ratline_endpoints(new_ratline); let mut router = @@ -154,9 +162,7 @@ impl Step, Option, AutorouteContinu self.curr_ratline = None; } - Ok(ControlFlow::Continue(AutorouteContinueStatus::Routed( - band_termseg, - ))) + Ok(ControlFlow::Continue(ret)) } } diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index 17d0eaf..a678a8b 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -69,9 +69,9 @@ impl Step, (f64, f64)> for CompareDetoursExecut } match self.autoroute.step(autorouter)? { - ControlFlow::Continue(AutorouteContinueStatus::Running) => { - Ok(ControlFlow::Continue(())) - } + ControlFlow::Continue( + AutorouteContinueStatus::Running | AutorouteContinueStatus::Skipped(_), + ) => Ok(ControlFlow::Continue(())), ControlFlow::Continue(AutorouteContinueStatus::Routed(band_termseg)) => { let length = band_termseg .ref_(autorouter.board.layout().drawing()) diff --git a/src/board/mod.rs b/src/board/mod.rs index ccbfb8f..321fd38 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -189,7 +189,7 @@ impl Board { source: FixedDotIndex, target: FixedDotIndex, band: BandUid, - ) { + ) -> bool { let source_pinname = self .node_pinname(&GenericNode::Primitive(source.into())) .unwrap() @@ -198,8 +198,27 @@ impl Board { .node_pinname(&GenericNode::Primitive(target.into())) .unwrap() .to_string(); - self.band_bandname - .insert(band, BandName::from((source_pinname, target_pinname))); + let bandname = BandName::from((source_pinname, target_pinname)); + if self.band_bandname.get_by_right(&bandname).is_some() { + false + } else { + self.band_bandname.insert(band, bandname); + true + } + } + + pub fn band_between_nodes( + &self, + source: FixedDotIndex, + target: FixedDotIndex, + ) -> Option { + let source_pinname = self + .node_pinname(&GenericNode::Primitive(source.into())) + .unwrap(); + let target_pinname = self + .node_pinname(&GenericNode::Primitive(target.into())) + .unwrap(); + self.band_between_pins(source_pinname, target_pinname) } /// Finds a band between two pin names. diff --git a/src/drawing/band.rs b/src/drawing/band.rs index 9ae98f8..d0e6950 100644 --- a/src/drawing/band.rs +++ b/src/drawing/band.rs @@ -6,7 +6,7 @@ use enum_dispatch::enum_dispatch; use petgraph::stable_graph::NodeIndex; use crate::{ - geometry::shape::MeasureLength, + geometry::{shape::MeasureLength, GetLayer}, graph::{GetPetgraphIndex, MakeRef}, }; @@ -67,6 +67,16 @@ impl<'a, CW: 'a, Cel: 'a, R: 'a> BandRef<'a, CW, Cel, R> { } } +impl GetLayer for BandRef<'_, CW, Cel, R> { + fn layer(&self) -> usize { + match self.first_seg { + BandTermsegIndex::Straight(seg) => seg.primitive(self.drawing), + BandTermsegIndex::Bended(seg) => seg.primitive(self.drawing), + } + .layer() + } +} + impl MeasureLength for BandRef<'_, CW, Cel, R> { fn length(&self) -> f64 { match self.first_seg {