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::{
|
use crate::{
|
||||||
board::mesadata::AccessMesadata,
|
board::mesadata::AccessMesadata,
|
||||||
|
drawing::graph::PrimitiveIndex,
|
||||||
geometry::primitive::PrimitiveShape,
|
geometry::primitive::PrimitiveShape,
|
||||||
router::{navmesh::Navmesh, route::Route, trace::Trace, Router, RouterStatus},
|
router::{navmesh::Navmesh, route::Route, trace::Trace, Router, RouterStatus},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace},
|
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles},
|
||||||
Autorouter, AutorouterError, AutorouterStatus,
|
Autorouter, AutorouterError, AutorouterStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -104,3 +105,9 @@ impl GetGhosts for Autoroute {
|
||||||
self.route.as_ref().map_or(&[], |route| route.ghosts())
|
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];
|
fn ghosts(&self) -> &[PrimitiveShape];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[enum_dispatch]
|
||||||
|
pub trait GetObstacles {
|
||||||
|
fn obstacles(&self) -> &[PrimitiveIndex];
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone)]
|
#[derive(Error, Debug, Clone)]
|
||||||
pub enum InvokerError {
|
pub enum InvokerError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|
@ -53,7 +58,7 @@ pub enum Command {
|
||||||
PlaceVia(ViaWeight),
|
PlaceVia(ViaWeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts)]
|
#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)]
|
||||||
pub enum Execute {
|
pub enum Execute {
|
||||||
Autoroute(Autoroute),
|
Autoroute(Autoroute),
|
||||||
PlaceVia(PlaceVia),
|
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> {
|
pub struct Invoker<M: AccessMesadata> {
|
||||||
autorouter: Autorouter<M>,
|
autorouter: Autorouter<M>,
|
||||||
history: History,
|
history: History,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace},
|
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles},
|
||||||
Autorouter, AutorouterError,
|
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::{
|
use topola::{
|
||||||
autorouter::invoker::{
|
autorouter::invoker::{
|
||||||
Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, Invoker,
|
Command, ExecuteWithStatus, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles,
|
||||||
|
Invoker,
|
||||||
},
|
},
|
||||||
board::mesadata::AccessMesadata,
|
board::mesadata::AccessMesadata,
|
||||||
drawing::{
|
drawing::{
|
||||||
|
|
@ -111,7 +112,15 @@ impl Viewport {
|
||||||
{
|
{
|
||||||
layers.highlight_colors[i]
|
layers.highlight_colors[i]
|
||||||
} else {
|
} 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);
|
painter.paint_primitive(&shape, color);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ pub struct Route {
|
||||||
astar: Astar<Navmesh, f64>,
|
astar: Astar<Navmesh, f64>,
|
||||||
trace: Trace,
|
trace: Trace,
|
||||||
ghosts: Vec<PrimitiveShape>,
|
ghosts: Vec<PrimitiveShape>,
|
||||||
|
obstacles: Vec<PrimitiveIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Route {
|
impl Route {
|
||||||
|
|
@ -65,11 +66,13 @@ impl Route {
|
||||||
let mut strategy = RouterAstarStrategy::new(tracer, &mut trace, target);
|
let mut strategy = RouterAstarStrategy::new(tracer, &mut trace, target);
|
||||||
let astar = Astar::new(navmesh, source_navvertex, &mut strategy);
|
let astar = Astar::new(navmesh, source_navvertex, &mut strategy);
|
||||||
let ghosts = vec![];
|
let ghosts = vec![];
|
||||||
|
let obstacles = vec![];
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
astar,
|
astar,
|
||||||
trace,
|
trace,
|
||||||
ghosts,
|
ghosts,
|
||||||
|
obstacles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +89,8 @@ impl Route {
|
||||||
AstarStatus::Finished(_cost, _path, band) => Ok(RouterStatus::Finished(band)),
|
AstarStatus::Finished(_cost, _path, band) => Ok(RouterStatus::Finished(band)),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.ghosts = strategy.ghosts;
|
self.ghosts = strategy.last_ghosts;
|
||||||
|
self.obstacles = strategy.last_obstacles;
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,4 +105,8 @@ impl Route {
|
||||||
pub fn ghosts(&self) -> &[PrimitiveShape] {
|
pub fn ghosts(&self) -> &[PrimitiveShape] {
|
||||||
&self.ghosts
|
&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 tracer: Tracer<'a, R>,
|
||||||
pub trace: &'a mut Trace,
|
pub trace: &'a mut Trace,
|
||||||
pub target: FixedDotIndex,
|
pub target: FixedDotIndex,
|
||||||
pub ghosts: Vec<PrimitiveShape>,
|
pub last_ghosts: Vec<PrimitiveShape>,
|
||||||
|
pub last_obstacles: Vec<PrimitiveIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> {
|
impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> {
|
||||||
|
|
@ -56,7 +57,8 @@ impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> {
|
||||||
tracer,
|
tracer,
|
||||||
trace,
|
trace,
|
||||||
target,
|
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,
|
DrawException::CannotWrapAround(.., layout_err) => layout_err,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (ghost, ..) = match layout_err {
|
let (ghost, obstacle) = match layout_err {
|
||||||
LayoutException::NoTangents(..) => return None,
|
LayoutException::NoTangents(..) => return None,
|
||||||
LayoutException::Infringement(Infringement(ghost, obstacle)) => {
|
LayoutException::Infringement(Infringement(ghost, obstacle)) => {
|
||||||
(ghost, obstacle)
|
(ghost, obstacle)
|
||||||
|
|
@ -133,7 +135,8 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandFirstSegIndex>
|
||||||
LayoutException::AlreadyConnected(..) => return None,
|
LayoutException::AlreadyConnected(..) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.ghosts = vec![ghost];
|
self.last_ghosts = vec![ghost];
|
||||||
|
self.last_obstacles = vec![obstacle];
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue