From b09ffad9b3756ca973696230d0a4f109101d979f Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 10 Jun 2024 02:38:24 +0200 Subject: [PATCH] autorouter: create new command for placing vias Undoing it is not implemented yet. --- Cargo.toml | 5 ++++- src/autorouter/autorouter.rs | 17 ++++++++++++++++- src/autorouter/invoker.rs | 14 +++++++++++++- src/autorouter/mod.rs | 1 + src/autorouter/place_via.rs | 24 ++++++++++++++++++++++++ src/bin/topola-egui/app.rs | 3 ++- src/layout/via.rs | 4 +++- src/math.rs | 3 ++- 8 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/autorouter/place_via.rs diff --git a/Cargo.toml b/Cargo.toml index a44e5a8..5929391 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 864ca8f..20bf559 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -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 Autorouter { } } + 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::new(weight) + } + + pub fn undo_place_via(&mut self, weight: ViaWeight) { + todo!(); + } + pub fn ratline_endpoints( &mut self, ratline: EdgeIndex, diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 9093563..2757caf 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -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 Invoker { 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 Invoker { match command { Command::Autoroute(ref selection) => self.autorouter.undo_autoroute(selection), + Command::PlaceVia(weight) => self.autorouter.undo_place_via(*weight), } Ok(self.history.undo()?) diff --git a/src/autorouter/mod.rs b/src/autorouter/mod.rs index 5cf5308..092afce 100644 --- a/src/autorouter/mod.rs +++ b/src/autorouter/mod.rs @@ -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; diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs new file mode 100644 index 0000000..d9cdc8b --- /dev/null +++ b/src/autorouter/place_via.rs @@ -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 { + Ok(Self { weight }) + } + + pub fn doit( + &mut self, + autorouter: &mut Autorouter, + ) -> Result<(), AutorouterError> { + autorouter.place_via(self.weight) + } +} diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index b1aa631..72ab3fd 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -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)] diff --git a/src/layout/via.rs b/src/layout/via.rs index 93267f9..4823574 100644 --- a/src/layout/via.rs +++ b/src/layout/via.rs @@ -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, diff --git a/src/math.rs b/src/math.rs index b62134d..91cd696 100644 --- a/src/math.rs +++ b/src/math.rs @@ -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,