mirror of https://codeberg.org/topola/topola.git
egui,autorouter,router: highlight current obstacle
This commit is contained in:
parent
b6cb89c017
commit
def3f84d6a
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<M: AccessMesadata> {
|
||||
autorouter: Autorouter<M>,
|
||||
history: History,
|
||||
|
|
|
|||
|
|
@ -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] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub struct Route {
|
|||
astar: Astar<Navmesh, f64>,
|
||||
trace: Trace,
|
||||
ghosts: Vec<PrimitiveShape>,
|
||||
obstacles: Vec<PrimitiveIndex>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<PrimitiveShape>,
|
||||
pub last_ghosts: Vec<PrimitiveShape>,
|
||||
pub last_obstacles: Vec<PrimitiveIndex>,
|
||||
}
|
||||
|
||||
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<Navmesh, f64, BandFirstSegIndex>
|
|||
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<Navmesh, f64, BandFirstSegIndex>
|
|||
LayoutException::AlreadyConnected(..) => return None,
|
||||
};
|
||||
|
||||
self.ghosts = vec![ghost];
|
||||
self.last_ghosts = vec![ghost];
|
||||
self.last_obstacles = vec![obstacle];
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue