specctra: clean up the hack related to layer import

This commit is contained in:
Tomasz Cichoń 2024-09-29 00:04:18 +02:00
parent d86ef12e83
commit 947ecf2e1c
2 changed files with 22 additions and 7 deletions

View File

@ -55,8 +55,7 @@ impl SpecctraDesign {
/// ///
pub fn load(reader: impl std::io::BufRead) -> Result<SpecctraDesign, LoadingError> { pub fn load(reader: impl std::io::BufRead) -> Result<SpecctraDesign, LoadingError> {
let mut list_reader = ListTokenizer::new(reader); let mut list_reader = ListTokenizer::new(reader);
let mut dsn = list_reader.read_value::<DsnFile>()?; let dsn = list_reader.read_value::<DsnFile>()?;
dsn.pcb.structure.layers.append(&mut dsn.pcb.structure.layers_easyeda); // temporary hack
Ok(Self { pcb: dsn.pcb }) Ok(Self { pcb: dsn.pcb })
} }

View File

@ -80,7 +80,7 @@ pub struct Resolution {
pub value: f32, pub value: f32,
} }
#[derive(ReadDsn, WriteSes, Debug)] #[derive(WriteSes, Debug)]
pub struct Structure { pub struct Structure {
#[vec("layer")] #[vec("layer")]
pub layers: Vec<Layer>, pub layers: Vec<Layer>,
@ -95,10 +95,26 @@ pub struct Structure {
// (in class rules it outputs a single rule with all clearances like KiCad) // (in class rules it outputs a single rule with all clearances like KiCad)
#[vec("rule")] #[vec("rule")]
pub rules: Vec<StructureRule>, pub rules: Vec<StructureRule>,
// EasyEDA outputs these last... }
// this is a horrible hack to see what else causes trouble
#[vec("layer")] // custom impl to handle layers appearing late
pub layers_easyeda: Vec<Layer>, impl<R: std::io::BufRead> ReadDsn<R> for Structure {
fn read_dsn(
tokenizer: &mut ListTokenizer<R>,
) -> Result<Self, ParseErrorContext> {
let mut value = Self {
layers: tokenizer.read_named_array("layer")?,
boundary: tokenizer.read_named("boundary")?,
planes: tokenizer.read_named_array("plane")?,
via: tokenizer.read_named("via")?,
grids: tokenizer.read_named_array("grid")?,
rules: tokenizer.read_named_array("rule")?,
};
value.layers.append(&mut tokenizer.read_named_array("layer")?);
Ok(value)
}
} }
#[derive(ReadDsn, WriteSes, Debug)] #[derive(ReadDsn, WriteSes, Debug)]