autorouter: create new command for placing vias

Undoing it is not implemented yet.
This commit is contained in:
Mikolaj Wielgus 2024-06-10 02:38:24 +02:00
parent 6b6affb3fc
commit b09ffad9b3
8 changed files with 65 additions and 6 deletions

View File

@ -23,7 +23,6 @@ disable_contracts = ["contracts/disable_contracts"]
[dependencies] [dependencies]
thiserror = "1.0.56" thiserror = "1.0.56"
anyhow = "1.0.79" anyhow = "1.0.79"
geo = "0.25.1"
rstar = "0.11.0" rstar = "0.11.0"
petgraph = "0.6.3" petgraph = "0.6.3"
spade = "2.2.0" spade = "2.2.0"
@ -34,6 +33,10 @@ contracts = "0.6.3"
bimap = "0.6.3" bimap = "0.6.3"
log = "0.4" log = "0.4"
[dependencies.geo]
version = "0.25.1"
features = ["use-serde"]
[dependencies.serde] [dependencies.serde]
version = "1" version = "1"
features = ["derive"] features = ["derive"]

View File

@ -15,6 +15,7 @@ use thiserror::Error;
use crate::{ use crate::{
autorouter::{ autorouter::{
autoroute::Autoroute, autoroute::Autoroute,
place_via::PlaceVia,
ratsnest::{Ratsnest, RatvertexIndex}, ratsnest::{Ratsnest, RatvertexIndex},
selection::Selection, selection::Selection,
}, },
@ -23,7 +24,8 @@ use crate::{
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{GetLayer, GetMaybeNet}, graph::{GetLayer, GetMaybeNet},
}, },
layout::Layout, layout::{via::ViaWeight, Layout},
math::Circle,
router::{ router::{
navmesh::{Navmesh, NavmeshError}, navmesh::{Navmesh, NavmeshError},
Router, RouterError, RouterObserverTrait, Router, RouterError, RouterObserverTrait,
@ -93,6 +95,19 @@ impl<M: MesadataTrait> Autorouter<M> {
} }
} }
pub fn place_via(&mut self, weight: ViaWeight) -> Result<(), AutorouterError> {
self.board.layout_mut().add_via(weight);
Ok(())
}
pub fn place_via_walk(&self, weight: ViaWeight) -> Result<PlaceVia, AutorouterError> {
PlaceVia::new(weight)
}
pub fn undo_place_via(&mut self, weight: ViaWeight) {
todo!();
}
pub fn ratline_endpoints( pub fn ratline_endpoints(
&mut self, &mut self,
ratline: EdgeIndex<usize>, ratline: EdgeIndex<usize>,

View File

@ -5,10 +5,12 @@ use crate::{
autorouter::{ autorouter::{
autoroute::Autoroute, autoroute::Autoroute,
history::{History, HistoryError}, history::{History, HistoryError},
place_via::PlaceVia,
selection::Selection, selection::Selection,
Autorouter, AutorouterError, AutorouterStatus, Autorouter, AutorouterError, AutorouterStatus,
}, },
board::mesadata::MesadataTrait, board::mesadata::MesadataTrait,
layout::via::ViaWeight,
router::{EmptyRouterObserver, RouterObserverTrait}, router::{EmptyRouterObserver, RouterObserverTrait},
}; };
@ -28,10 +30,12 @@ pub enum InvokerStatus {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Command { pub enum Command {
Autoroute(Selection), Autoroute(Selection),
PlaceVia(ViaWeight),
} }
pub enum Execute { pub enum Execute {
Autoroute(Autoroute), Autoroute(Autoroute),
PlaceVia(PlaceVia),
} }
impl Execute { impl Execute {
@ -47,6 +51,10 @@ impl Execute {
AutorouterStatus::Finished => Ok(InvokerStatus::Finished), AutorouterStatus::Finished => Ok(InvokerStatus::Finished),
} }
} }
Execute::PlaceVia(place_via) => {
place_via.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished)
}
} }
} }
} }
@ -100,9 +108,12 @@ impl<M: MesadataTrait> Invoker<M> {
fn dispatch_command(&mut self, command: &Command) -> Execute { fn dispatch_command(&mut self, command: &Command) -> Execute {
match command { match command {
Command::Autoroute(ref selection) => { Command::Autoroute(selection) => {
Execute::Autoroute(self.autorouter.autoroute_walk(selection).unwrap()) Execute::Autoroute(self.autorouter.autoroute_walk(selection).unwrap())
} }
Command::PlaceVia(weight) => {
Execute::PlaceVia(self.autorouter.place_via_walk(*weight).unwrap())
}
} }
} }
@ -111,6 +122,7 @@ impl<M: MesadataTrait> Invoker<M> {
match command { match command {
Command::Autoroute(ref selection) => self.autorouter.undo_autoroute(selection), Command::Autoroute(ref selection) => self.autorouter.undo_autoroute(selection),
Command::PlaceVia(weight) => self.autorouter.undo_place_via(*weight),
} }
Ok(self.history.undo()?) Ok(self.history.undo()?)

View File

@ -2,6 +2,7 @@ pub mod autoroute;
mod autorouter; mod autorouter;
pub mod history; pub mod history;
pub mod invoker; pub mod invoker;
pub mod place_via;
pub mod ratsnest; pub mod ratsnest;
pub mod selection; pub mod selection;

View File

@ -0,0 +1,24 @@
use geo::Point;
use crate::{
autorouter::{Autorouter, AutorouterError},
board::mesadata::MesadataTrait,
layout::via::ViaWeight,
};
pub struct PlaceVia {
weight: ViaWeight,
}
impl PlaceVia {
pub fn new(weight: ViaWeight) -> Result<Self, AutorouterError> {
Ok(Self { weight })
}
pub fn doit(
&mut self,
autorouter: &mut Autorouter<impl MesadataTrait>,
) -> Result<(), AutorouterError> {
autorouter.place_via(self.weight)
}
}

View File

@ -1,6 +1,7 @@
use futures::executor; use futures::executor;
use geo::point; use geo::point;
use petgraph::visit::{EdgeRef, IntoEdgeReferences}; use petgraph::visit::{EdgeRef, IntoEdgeReferences};
use serde::{Deserialize, Serialize};
use std::{ use std::{
fs::File, fs::File,
future::Future, future::Future,
@ -52,7 +53,7 @@ struct SharedData {
} }
/// Deserialize/Serialize is needed to persist app state between restarts. /// Deserialize/Serialize is needed to persist app state between restarts.
#[derive(serde::Deserialize, serde::Serialize)] #[derive(Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct App { pub struct App {
#[serde(skip)] #[serde(skip)]

View File

@ -1,3 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::{ use crate::{
drawing::{graph::GetMaybeNet, primitive::MakePrimitiveShape, rules::RulesTrait}, drawing::{graph::GetMaybeNet, primitive::MakePrimitiveShape, rules::RulesTrait},
geometry::{ geometry::{
@ -42,7 +44,7 @@ impl<'a, R: RulesTrait> MakePrimitiveShape for Via<'a, R> {
} }
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct ViaWeight { pub struct ViaWeight {
pub from_layer: u64, pub from_layer: u64,
pub to_layer: u64, pub to_layer: u64,

View File

@ -1,4 +1,5 @@
use geo::{geometry::Point, point, EuclideanDistance, Line}; use geo::{geometry::Point, point, EuclideanDistance, Line};
use serde::{Deserialize, Serialize};
use std::ops::Sub; use std::ops::Sub;
use thiserror::Error; use thiserror::Error;
@ -13,7 +14,7 @@ pub struct CanonicalLine {
pub c: f64, pub c: f64,
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Circle { pub struct Circle {
pub pos: Point, pub pos: Point,
pub r: f64, pub r: f64,