From 88c353896c589dd2db23bbd0ae54b77e92c6de85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Cicho=C5=84?= Date: Tue, 27 Feb 2024 04:39:39 +0100 Subject: [PATCH] dsn: fix net assignment for imported pins --- src/dsn/design.rs | 36 ++++++++++++++++++++++++------------ src/dsn/structure.rs | 4 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/dsn/design.rs b/src/dsn/design.rs index 03ae632..8fd2c57 100644 --- a/src/dsn/design.rs +++ b/src/dsn/design.rs @@ -40,7 +40,26 @@ impl DsnDesign { .map(|(id, net)| (net.clone(), id)), ); - let continent100 = layout.add_continent(100); // TODO: remove this placeholder. + // mapping of pin id -> net id prepared for adding pins + let pin_nets = if let Some(nets) = self.pcb.network.nets.as_ref() { + HashMap::::from_iter( + nets.iter() + .map(|net| { + // resolve the id so we don't work with strings + let net_id = net_ids.get(&net.name).unwrap(); + + // take the list of pins + // and for each pin id output (pin id, net id) + net.pins.ids + .iter() + .map(|id| (id.clone(), *net_id)) + }) + // flatten the nested iters into a single stream of tuples + .flatten() + ) + } else { + HashMap::::new() + }; // add pins from components //self.pcb.placement.components.iter().map(|component| { @@ -55,16 +74,9 @@ impl DsnDesign { .unwrap(); for pin in &image.pins { - //let pin_name = format!("{}-{}", place.name, pin.id); - /*let net = self - .pcb - .network - .nets - .unwrap() - .find(|net| net.pins[0].ids.contains(&pin_name)); - let net_id = net_ids.get(&net).unwrap(); - let continent = layout.add_continent(*net_id as i64);*/ - //let continent = layout.add_continent(*net_id as i64); + let pin_name = format!("{}-{}", place.name, pin.id); + let net_id = pin_nets.get(&pin_name).unwrap(); + let continent = layout.add_continent(*net_id as i64); let padstack = &self .pcb @@ -83,7 +95,7 @@ impl DsnDesign { layout .add_fixed_dot(FixedDotWeight { - continent: continent100, + continent: continent, geodata: DotGeodata { circle }, }) .unwrap(); diff --git a/src/dsn/structure.rs b/src/dsn/structure.rs index f810082..a679ac8 100644 --- a/src/dsn/structure.rs +++ b/src/dsn/structure.rs @@ -179,8 +179,8 @@ pub struct Network { #[serde(rename = "net")] // dsn names this "net", but it's a structure unrelated to "net" in wiring or elsewhere pub struct NetPinAssignments { - pub net: String, - pub pins: Vec, + pub name: String, + pub pins: Pins, } #[derive(Deserialize, Debug)]