specctra: pass errors to app instead of panicking

This commit is contained in:
Tomasz Cichoń 2024-06-16 20:01:38 +02:00
parent aa0616840c
commit f37e7ce88d
2 changed files with 11 additions and 17 deletions

View File

@ -9,9 +9,9 @@ use crate::{
layout::{zone::SolidZoneWeight, Layout}, layout::{zone::SolidZoneWeight, Layout},
math::Circle, math::Circle,
specctra::{ specctra::{
read, read::{self, ListTokenizer},
mesadata::SpecctraMesadata, mesadata::SpecctraMesadata,
structure::{self, Layer, Pcb, Shape, SpecctraFile}, structure::{self, Layer, Pcb, Shape, DsnFile},
}, },
}; };
@ -33,8 +33,12 @@ impl SpecctraDesign {
let file = std::fs::File::open(filename)?; let file = std::fs::File::open(filename)?;
let reader = std::io::BufReader::new(file); let reader = std::io::BufReader::new(file);
let mut list_reader = read::ListTokenizer::new(reader); let mut list_reader = read::ListTokenizer::new(reader);
let dsn = list_reader.read_value::<DsnFile>()?;
Ok(Self {
pcb: dsn.pcb,
})
if let Ok(file) = list_reader.read_value::<structure::SpecctraFile>() {
//use super::structure::*; //use super::structure::*;
// (this entire if let block does not belong here) // (this entire if let block does not belong here)
@ -101,24 +105,14 @@ impl SpecctraDesign {
};*/ };*/
//println!("{:?}", list_writer.write_value(&ses)); //println!("{:?}", list_writer.write_value(&ses));
Ok(Self { pcb: file.pcb })
} else {
todo!();
}
} }
pub fn load_from_string(contents: String) -> Result<Self, LoadingError> { pub fn load_from_string(contents: String) -> Result<Self, LoadingError> {
/*let dsn = de::from_str::<DsnFile>(&contents) let mut list_reader = ListTokenizer::new(contents.as_bytes());
.map_err(|err| LoadingError::Syntax(err))? let dsn = list_reader.read_value::<DsnFile>()?;
.pcb;
Ok(Self { pcb })*/
let mut list_reader = read::ListTokenizer::new(contents.as_bytes());
let dsn = list_reader.read_value::<structure::SpecctraFile>();
Ok(Self { Ok(Self {
pcb: dsn.unwrap().pcb, pcb: dsn.pcb,
}) })
} }

View File

@ -45,7 +45,7 @@ pub struct NetOut {
} }
#[derive(ReadDsn, WriteSes, Debug)] #[derive(ReadDsn, WriteSes, Debug)]
pub struct SpecctraFile { pub struct DsnFile {
pub pcb: Pcb, pub pcb: Pcb,
} }