diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 0d208f1..5f38575 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -17,11 +17,10 @@ use crate::{ ratsnest::{Ratsnest, RatvertexIndex}, selection::Selection, }, - board::Board, + board::{mesadata::MesadataTrait, Board}, drawing::{ dot::FixedDotIndex, graph::{GetLayer, GetMaybeNet}, - rules::RulesTrait, }, layout::Layout, router::{ @@ -55,7 +54,7 @@ pub struct Autoroute { impl Autoroute { pub fn new( ratlines: impl IntoIterator> + 'static, - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, ) -> Result { let mut ratlines_iter = Box::new(ratlines.into_iter()); @@ -75,10 +74,10 @@ impl Autoroute { Ok(this) } - pub fn step( + pub fn step( &mut self, - autorouter: &mut Autorouter, - observer: &mut impl RouterObserverTrait, + autorouter: &mut Autorouter, + observer: &mut impl RouterObserverTrait, ) -> Result { let (new_navmesh, new_ratline) = if let Some(cur_ratline) = self.ratlines_iter.next() { let (source, target) = autorouter.ratline_endpoints(cur_ratline); @@ -121,13 +120,13 @@ impl Autoroute { } } -pub struct Autorouter { - board: Board, +pub struct Autorouter { + board: Board, ratsnest: Ratsnest, } -impl Autorouter { - pub fn new(board: Board) -> Result { +impl Autorouter { + pub fn new(board: Board) -> Result { let ratsnest = Ratsnest::new(board.layout())?; Ok(Self { board, ratsnest }) } @@ -135,7 +134,7 @@ impl Autorouter { pub fn autoroute( &mut self, selection: &Selection, - observer: &mut impl RouterObserverTrait, + observer: &mut impl RouterObserverTrait, ) -> Result<(), AutorouterError> { let mut autoroute = self.autoroute_walk(selection)?; @@ -225,7 +224,7 @@ impl Autorouter { .collect() } - pub fn board(&self) -> &Board { + pub fn board(&self) -> &Board { &self.board } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index c747869..511dfcf 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -7,7 +7,7 @@ use crate::{ selection::Selection, Autoroute, Autorouter, AutorouterError, AutorouterStatus, }, - drawing::rules::RulesTrait, + board::mesadata::MesadataTrait, layout::Layout, router::{EmptyRouterObserver, RouterObserverTrait}, }; @@ -35,10 +35,10 @@ pub enum Execute { } impl Execute { - pub fn step( + pub fn step( &mut self, - invoker: &mut Invoker, - observer: &mut impl RouterObserverTrait, + invoker: &mut Invoker, + observer: &mut impl RouterObserverTrait, ) -> Result { match self { Execute::Autoroute(autoroute) => { @@ -51,31 +51,31 @@ impl Execute { } } -pub struct Invoker { - autorouter: Autorouter, +pub struct Invoker { + autorouter: Autorouter, history: History, } -impl Invoker { - pub fn new(autorouter: Autorouter) -> Self { +impl Invoker { + pub fn new(autorouter: Autorouter) -> Self { Self::new_with_history(autorouter, History::new()) } - pub fn new_with_history(autorouter: Autorouter, history: History) -> Self { + pub fn new_with_history(autorouter: Autorouter, history: History) -> Self { Self { autorouter, history, } } - pub fn destruct(self) -> (Autorouter, History) { + pub fn destruct(self) -> (Autorouter, History) { (self.autorouter, self.history) } pub fn execute( &mut self, command: Command, - observer: &mut impl RouterObserverTrait, + observer: &mut impl RouterObserverTrait, ) -> Result<(), InvokerError> { let mut execute = self.execute_walk(command); @@ -142,7 +142,7 @@ impl Invoker { self.history.set_undone(undone.into_iter()); } - pub fn autorouter(&self) -> &Autorouter { + pub fn autorouter(&self) -> &Autorouter { &self.autorouter } diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index 6f19ba1..45abf73 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -3,11 +3,8 @@ use std::collections::HashSet; use serde::{Deserialize, Serialize}; use crate::{ - board::Board, - drawing::{ - graph::{GetLayer, MakePrimitive, PrimitiveIndex}, - rules::RulesTrait, - }, + board::{mesadata::MesadataTrait, Board}, + drawing::graph::{GetLayer, MakePrimitive, PrimitiveIndex}, graph::GenericIndex, layout::NodeIndex, }; @@ -30,7 +27,7 @@ impl Selection { } } - pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { + pub fn toggle_at_node(&mut self, board: &Board, node: NodeIndex) { let Some(selector) = self.node_selector(board, node) else { return; }; @@ -42,15 +39,15 @@ impl Selection { } } - fn select(&mut self, board: &Board, selector: Selector) { + fn select(&mut self, board: &Board, selector: Selector) { self.selectors.insert(selector); } - fn deselect(&mut self, board: &Board, selector: &Selector) { + fn deselect(&mut self, board: &Board, selector: &Selector) { self.selectors.remove(selector); } - pub fn contains_node(&self, board: &Board, node: NodeIndex) -> bool { + pub fn contains_node(&self, board: &Board, node: NodeIndex) -> bool { let Some(selector) = self.node_selector(board, node) else { return false; }; @@ -58,7 +55,11 @@ impl Selection { self.selectors.contains(&selector) } - fn node_selector(&self, board: &Board, node: NodeIndex) -> Option { + fn node_selector( + &self, + board: &Board, + node: NodeIndex, + ) -> Option { let layer = match node { NodeIndex::Primitive(primitive) => { primitive.primitive(board.layout().drawing()).layer() diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 68ad320..16f1c3f 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -22,7 +22,7 @@ use topola::{ rules::RulesTrait, Drawing, Infringement, LayoutException, }, - dsn::{design::DsnDesign, rules::DsnRules}, + dsn::{design::DsnDesign, mesadata::DsnMesadata}, geometry::{ compound::CompoundManagerTrait, primitive::{BendShape, DotShape, PrimitiveShape, PrimitiveShapeTrait, SegShape}, @@ -59,7 +59,7 @@ pub struct App { overlay: Option, #[serde(skip)] - invoker: Option>>>, + invoker: Option>>>, #[serde(skip)] shared_data: Arc>, diff --git a/src/bin/topola-sdl2-demo/main.rs b/src/bin/topola-sdl2-demo/main.rs index e7b1464..6a4d9e6 100644 --- a/src/bin/topola-sdl2-demo/main.rs +++ b/src/bin/topola-sdl2-demo/main.rs @@ -21,7 +21,7 @@ use topola::drawing::rules::{Conditions, RulesTrait}; use topola::drawing::seg::FixedSegWeight; use topola::drawing::{Infringement, LayoutException}; use topola::dsn::design::DsnDesign; -use topola::dsn::rules::DsnRules; +use topola::dsn::mesadata::DsnMesadata; use topola::geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait}; use topola::geometry::shape::ShapeTrait; use topola::layout::zone::MakePolyShape; diff --git a/src/board/board.rs b/src/board/board.rs index b4aacef..87b095c 100644 --- a/src/board/board.rs +++ b/src/board/board.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use crate::{ + board::mesadata::MesadataTrait, drawing::{ band::BandIndex, dot::{FixedDotIndex, FixedDotWeight}, @@ -20,16 +21,16 @@ use crate::{ }; #[derive(Debug)] -pub struct Board { - layout: Layout, +pub struct Board { + layout: Layout, node_to_pinname: HashMap, layer_to_layername: HashMap, net_to_netname: HashMap, pinname_pair_to_band: HashMap<(String, String), BandIndex>, } -impl Board { - pub fn new(layout: Layout) -> Self { +impl Board { + pub fn new(layout: Layout) -> Self { Self { layout, node_to_pinname: HashMap::new(), @@ -122,7 +123,7 @@ impl Board { &mut self, navmesh: Navmesh, width: f64, - observer: &mut impl RouterObserverTrait, + observer: &mut impl RouterObserverTrait, ) -> Result { let source_pinname = self .node_pinname(GenericNode::Primitive(navmesh.source().into())) @@ -199,11 +200,11 @@ impl Board { } } - pub fn layout(&self) -> &Layout { + pub fn layout(&self) -> &Layout { &self.layout } - pub fn layout_mut(&mut self) -> &mut Layout { + pub fn layout_mut(&mut self) -> &mut Layout { &mut self.layout } } diff --git a/src/board/mesadata.rs b/src/board/mesadata.rs new file mode 100644 index 0000000..cdbf113 --- /dev/null +++ b/src/board/mesadata.rs @@ -0,0 +1,10 @@ +use crate::{drawing::rules::RulesTrait, layout::NodeIndex}; + +// TODO: use this trait. +pub trait MesadataTrait: RulesTrait { + /*fn node_pinname(&self, node: NodeIndex); + fn layer_layername(&self, layer: u64) -> &str; + fn layername_layer(&self, layername: &str) -> u64; + fn net_netname(&self, net: usize) -> &str; + fn netname_net(&self, netname: &str) -> usize;*/ +} diff --git a/src/board/mod.rs b/src/board/mod.rs index 928e4c1..34c3a1d 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -1,3 +1,4 @@ mod board; +pub mod mesadata; pub use board::*; diff --git a/src/dsn/design.rs b/src/dsn/design.rs index 4c030dc..1610ed7 100644 --- a/src/dsn/design.rs +++ b/src/dsn/design.rs @@ -8,7 +8,7 @@ use crate::{ drawing::{dot::FixedDotWeight, seg::FixedSegWeight, Drawing}, dsn::{ de, - rules::DsnRules, + mesadata::DsnMesadata, structure::{self, DsnFile, Layer, Pcb, Shape}, }, geometry::compound::CompoundManagerTrait, @@ -44,8 +44,8 @@ impl DsnDesign { Ok(Self { pcb }) } - pub fn make_board(&self) -> Board { - let rules = DsnRules::from_pcb(&self.pcb); + pub fn make_board(&self) -> Board { + let rules = DsnMesadata::from_pcb(&self.pcb); let mut board = Board::new(Layout::new(Drawing::new(rules))); // mapping of pin -> net prepared for adding pins @@ -341,7 +341,7 @@ impl DsnDesign { } fn layer( - board: &Board, + board: &Board, layer_vec: &Vec, layer_name: &str, front: bool, @@ -362,7 +362,7 @@ impl DsnDesign { } fn add_circle( - board: &mut Board, + board: &mut Board, place_pos: Point, place_rot: f64, pin_pos: Point, @@ -390,7 +390,7 @@ impl DsnDesign { } fn add_rect( - board: &mut Board, + board: &mut Board, place_pos: Point, place_rot: f64, pin_pos: Point, @@ -517,7 +517,7 @@ impl DsnDesign { } fn add_path( - board: &mut Board, + board: &mut Board, place_pos: Point, place_rot: f64, pin_pos: Point, @@ -600,7 +600,7 @@ impl DsnDesign { } fn add_polygon( - board: &mut Board, + board: &mut Board, place_pos: Point, place_rot: f64, pin_pos: Point, diff --git a/src/dsn/rules.rs b/src/dsn/mesadata.rs similarity index 95% rename from src/dsn/rules.rs rename to src/dsn/mesadata.rs index beba63d..267d3b7 100644 --- a/src/dsn/rules.rs +++ b/src/dsn/mesadata.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use crate::{ + board::mesadata::MesadataTrait, drawing::rules::{Conditions, RulesTrait}, dsn::structure::Pcb, }; @@ -21,7 +22,7 @@ impl DsnRule { } #[derive(Debug)] -pub struct DsnRules { +pub struct DsnMesadata { structure_rule: DsnRule, // net class name -> rule class_rules: HashMap, @@ -34,7 +35,7 @@ pub struct DsnRules { net_to_netclass: HashMap, } -impl DsnRules { +impl DsnMesadata { pub fn from_pcb(pcb: &Pcb) -> Self { let layer_ids = HashMap::from_iter( pcb.structure @@ -87,7 +88,7 @@ impl DsnRules { } } -impl RulesTrait for DsnRules { +impl RulesTrait for DsnMesadata { fn clearance(&self, conditions1: &Conditions, conditions2: &Conditions) -> f64 { let (Some(net1), Some(net2)) = (conditions1.maybe_net, conditions2.maybe_net) else { return 0.0; @@ -115,3 +116,7 @@ impl RulesTrait for DsnRules { largest } } + +impl MesadataTrait for DsnMesadata { + // +} diff --git a/src/dsn/mod.rs b/src/dsn/mod.rs index eb845a6..f1de5cf 100644 --- a/src/dsn/mod.rs +++ b/src/dsn/mod.rs @@ -1,4 +1,4 @@ mod de; pub mod design; -pub mod rules; +pub mod mesadata; mod structure; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4a7aac8..8073405 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -7,16 +7,13 @@ use topola::{ invoker::{Invoker, InvokerError}, Autorouter, }, - board::Board, - drawing::{ - graph::{GetLayer, GetMaybeNet}, - rules::RulesTrait, - }, - dsn::{design::DsnDesign, rules::DsnRules}, + board::{mesadata::MesadataTrait, Board}, + drawing::graph::{GetLayer, GetMaybeNet}, + dsn::{design::DsnDesign, mesadata::DsnMesadata}, graph::GetNodeIndex, }; -pub fn load_design_and_assert(filename: &str) -> Invoker { +pub fn load_design_and_assert(filename: &str) -> Invoker { let design = DsnDesign::load_from_file(filename).unwrap(); let mut invoker = Invoker::new(Autorouter::new(design.make_board()).unwrap()); @@ -32,7 +29,7 @@ pub fn load_design_and_assert(filename: &str) -> Invoker { invoker } -pub fn replay_and_assert(invoker: &mut Invoker, filename: &str) { +pub fn replay_and_assert(invoker: &mut Invoker, filename: &str) { let file = File::open(filename).unwrap(); invoker.replay(serde_json::from_reader(file).unwrap()); @@ -59,7 +56,7 @@ pub fn replay_and_assert(invoker: &mut Invoker, filename: &str) { } pub fn assert_single_layer_groundless_autoroute( - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, layername: &str, ) { let unionfind = unionfind(autorouter); @@ -125,7 +122,7 @@ pub fn assert_single_layer_groundless_autoroute( } /*pub fn assert_number_of_conncomps( - autorouter: &mut Autorouter, + autorouter: &mut Autorouter, conncomp_count: usize, ) { let unionfind = unionfind(autorouter); @@ -137,7 +134,7 @@ pub fn assert_single_layer_groundless_autoroute( }*/ pub fn assert_band_length( - board: &Board, + board: &Board, source: &str, target: &str, length: f64, @@ -149,7 +146,7 @@ pub fn assert_band_length( assert!((band_length - length).abs() < epsilon); } -fn unionfind(autorouter: &mut Autorouter) -> UnionFind> { +fn unionfind(autorouter: &mut Autorouter) -> UnionFind> { for ratline in autorouter.ratsnest().graph().edge_indices() { // Accessing endpoints may create new dots because apex construction is lazy, so we access // tem all before starting unionfind, as it requires a constant index bound.