From dfb2c20f1d16fa1c575c8934b4cc1ab83cfe9411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Cicho=C5=84?= Date: Sat, 28 Sep 2024 11:16:47 +0200 Subject: [PATCH] specctra: a hack to attempt loading layers from EasyEDA --- src/specctra/design.rs | 3 ++- src/specctra/mesadata.rs | 17 +++++++++++------ src/specctra/structure.rs | 8 ++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/specctra/design.rs b/src/specctra/design.rs index ff57941..213a7b2 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -55,7 +55,8 @@ impl SpecctraDesign { /// pub fn load(reader: impl std::io::BufRead) -> Result { let mut list_reader = ListTokenizer::new(reader); - let dsn = list_reader.read_value::()?; + let mut dsn = list_reader.read_value::()?; + dsn.pcb.structure.layers.append(&mut dsn.pcb.structure.layers_easyeda); // temporary hack Ok(Self { pcb: dsn.pcb }) } diff --git a/src/specctra/mesadata.rs b/src/specctra/mesadata.rs index 33bd4d4..9f60583 100644 --- a/src/specctra/mesadata.rs +++ b/src/specctra/mesadata.rs @@ -72,12 +72,17 @@ impl SpecctraMesadata { /// layer-to-layer name mappings, net-to-net name mappings, and net class rules. /// pub fn from_pcb(pcb: &Pcb) -> Self { - let layer_layername = BiHashMap::from_iter( - pcb.structure - .layers - .iter() - .map(|layer| (layer.property.index, layer.name.clone())), - ); + let mut highest_layer: usize = 0; + let mut layer_layername = BiHashMap::new(); + + for layer in &pcb.structure.layers { + let index = if layer.property.is_some() { + layer.property.as_ref().unwrap().index + } else { + layer.name.parse().unwrap() + }; + layer_layername.insert(index, layer.name.clone()); + } // keeping this as a separate iter pass because it might be moved into a different struct later? let net_netname = BiHashMap::from_iter( diff --git a/src/specctra/structure.rs b/src/specctra/structure.rs index 2868453..cb1604c 100644 --- a/src/specctra/structure.rs +++ b/src/specctra/structure.rs @@ -94,6 +94,10 @@ pub struct Structure { // (in class rules it outputs a single rule with all clearances like KiCad) #[vec("rule")] pub rules: Vec, + // EasyEDA outputs these last... + // this is a horrible hack to see what else causes trouble + #[vec("layer")] + pub layers_easyeda: Vec, } #[derive(ReadDsn, WriteSes, Debug)] @@ -101,7 +105,7 @@ pub struct Layer { #[anon] pub name: String, pub r#type: String, - pub property: Property, + pub property: Option, } #[derive(ReadDsn, WriteSes, Debug)] @@ -224,7 +228,7 @@ pub struct Padstack { pub name: String, #[vec("shape")] pub shapes: Vec, - pub attach: bool, + pub attach: Option, } // TODO: derive for enums if more than this single one is needed