diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index fc231c1..81a4f92 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -2,12 +2,13 @@ use petgraph::graph::EdgeIndex; use crate::{ board::mesadata::AccessMesadata, + drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, router::{navmesh::Navmesh, route::Route, trace::Trace, Router, RouterStatus}, }; use super::{ - invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace}, + invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles}, Autorouter, AutorouterError, AutorouterStatus, }; @@ -104,3 +105,9 @@ impl GetGhosts for Autoroute { self.route.as_ref().map_or(&[], |route| route.ghosts()) } } + +impl GetObstacles for Autoroute { + fn obstacles(&self) -> &[PrimitiveIndex] { + self.route.as_ref().map_or(&[], |route| route.obstacles()) + } +} diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 67d5adf..8d42e69 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -33,6 +33,11 @@ pub trait GetGhosts { fn ghosts(&self) -> &[PrimitiveShape]; } +#[enum_dispatch] +pub trait GetObstacles { + fn obstacles(&self) -> &[PrimitiveIndex]; +} + #[derive(Error, Debug, Clone)] pub enum InvokerError { #[error(transparent)] @@ -53,7 +58,7 @@ pub enum Command { PlaceVia(ViaWeight), } -#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts)] +#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)] pub enum Execute { Autoroute(Autoroute), PlaceVia(PlaceVia), @@ -142,6 +147,12 @@ impl GetGhosts for ExecuteWithStatus { } } +impl GetObstacles for ExecuteWithStatus { + fn obstacles(&self) -> &[PrimitiveIndex] { + self.execute.obstacles() + } +} + pub struct Invoker { autorouter: Autorouter, history: History, diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index ed151ec..f0cf97a 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -7,7 +7,7 @@ use crate::{ }; use super::{ - invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace}, + invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles}, Autorouter, AutorouterError, }; @@ -46,3 +46,9 @@ impl GetGhosts for PlaceVia { &[] } } + +impl GetObstacles for PlaceVia { + fn obstacles(&self) -> &[PrimitiveIndex] { + &[] + } +} diff --git a/src/bin/topola-egui/viewport.rs b/src/bin/topola-egui/viewport.rs index 8022688..9ecba75 100644 --- a/src/bin/topola-egui/viewport.rs +++ b/src/bin/topola-egui/viewport.rs @@ -5,7 +5,8 @@ use petgraph::{ }; use topola::{ autorouter::invoker::{ - Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, Invoker, + Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, + Invoker, }, board::mesadata::AccessMesadata, drawing::{ @@ -111,7 +112,15 @@ impl Viewport { { layers.highlight_colors[i] } else { - layers.colors[i] + if let Some(execute) = maybe_execute { + if execute.obstacles().contains(&primitive) { + layers.highlight_colors[i] + } else { + layers.colors[i] + } + } else { + layers.colors[i] + } }; painter.paint_primitive(&shape, color); diff --git a/src/router/route.rs b/src/router/route.rs index 982d2a4..6e5da73 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -37,6 +37,7 @@ pub struct Route { astar: Astar, trace: Trace, ghosts: Vec, + obstacles: Vec, } impl Route { @@ -65,11 +66,13 @@ impl Route { let mut strategy = RouterAstarStrategy::new(tracer, &mut trace, target); let astar = Astar::new(navmesh, source_navvertex, &mut strategy); let ghosts = vec![]; + let obstacles = vec![]; Self { astar, trace, ghosts, + obstacles, } } @@ -86,7 +89,8 @@ impl Route { AstarStatus::Finished(_cost, _path, band) => Ok(RouterStatus::Finished(band)), }; - self.ghosts = strategy.ghosts; + self.ghosts = strategy.last_ghosts; + self.obstacles = strategy.last_obstacles; result } @@ -101,4 +105,8 @@ impl Route { pub fn ghosts(&self) -> &[PrimitiveShape] { &self.ghosts } + + pub fn obstacles(&self) -> &[PrimitiveIndex] { + &self.obstacles + } } diff --git a/src/router/router.rs b/src/router/router.rs index 298ddfe..df34897 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -47,7 +47,8 @@ pub struct RouterAstarStrategy<'a, R: AccessRules> { pub tracer: Tracer<'a, R>, pub trace: &'a mut Trace, pub target: FixedDotIndex, - pub ghosts: Vec, + pub last_ghosts: Vec, + pub last_obstacles: Vec, } impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { @@ -56,7 +57,8 @@ impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { tracer, trace, target, - ghosts: vec![], + last_ghosts: vec![], + last_obstacles: vec![], } } @@ -124,7 +126,7 @@ impl<'a, R: AccessRules> AstarStrategy DrawException::CannotWrapAround(.., layout_err) => layout_err, }; - let (ghost, ..) = match layout_err { + let (ghost, obstacle) = match layout_err { LayoutException::NoTangents(..) => return None, LayoutException::Infringement(Infringement(ghost, obstacle)) => { (ghost, obstacle) @@ -133,7 +135,8 @@ impl<'a, R: AccessRules> AstarStrategy LayoutException::AlreadyConnected(..) => return None, }; - self.ghosts = vec![ghost]; + self.last_ghosts = vec![ghost]; + self.last_obstacles = vec![obstacle]; } None }