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

View File

@ -15,6 +15,7 @@ use thiserror::Error;
use crate::{
autorouter::{
autoroute::Autoroute,
place_via::PlaceVia,
ratsnest::{Ratsnest, RatvertexIndex},
selection::Selection,
},
@ -23,7 +24,8 @@ use crate::{
dot::FixedDotIndex,
graph::{GetLayer, GetMaybeNet},
},
layout::Layout,
layout::{via::ViaWeight, Layout},
math::Circle,
router::{
navmesh::{Navmesh, NavmeshError},
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(
&mut self,
ratline: EdgeIndex<usize>,

View File

@ -5,10 +5,12 @@ use crate::{
autorouter::{
autoroute::Autoroute,
history::{History, HistoryError},
place_via::PlaceVia,
selection::Selection,
Autorouter, AutorouterError, AutorouterStatus,
},
board::mesadata::MesadataTrait,
layout::via::ViaWeight,
router::{EmptyRouterObserver, RouterObserverTrait},
};
@ -28,10 +30,12 @@ pub enum InvokerStatus {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Command {
Autoroute(Selection),
PlaceVia(ViaWeight),
}
pub enum Execute {
Autoroute(Autoroute),
PlaceVia(PlaceVia),
}
impl Execute {
@ -47,6 +51,10 @@ impl Execute {
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 {
match command {
Command::Autoroute(ref selection) => {
Command::Autoroute(selection) => {
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 {
Command::Autoroute(ref selection) => self.autorouter.undo_autoroute(selection),
Command::PlaceVia(weight) => self.autorouter.undo_place_via(*weight),
}
Ok(self.history.undo()?)

View File

@ -2,6 +2,7 @@ pub mod autoroute;
mod autorouter;
pub mod history;
pub mod invoker;
pub mod place_via;
pub mod ratsnest;
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 geo::point;
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
use serde::{Deserialize, Serialize};
use std::{
fs::File,
future::Future,
@ -52,7 +53,7 @@ struct SharedData {
}
/// Deserialize/Serialize is needed to persist app state between restarts.
#[derive(serde::Deserialize, serde::Serialize)]
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct App {
#[serde(skip)]

View File

@ -1,3 +1,5 @@
use serde::{Deserialize, Serialize};
use crate::{
drawing::{graph::GetMaybeNet, primitive::MakePrimitiveShape, rules::RulesTrait},
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 from_layer: u64,
pub to_layer: u64,

View File

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