diff --git a/src/drawing/segbend.rs b/src/drawing/cane.rs similarity index 86% rename from src/drawing/segbend.rs rename to src/drawing/cane.rs index 7f3c804..65b7099 100644 --- a/src/drawing/segbend.rs +++ b/src/drawing/cane.rs @@ -10,13 +10,13 @@ use crate::drawing::{ use super::rules::RulesTrait; #[derive(Debug, Clone, Copy)] -pub struct Segbend { +pub struct Cane { pub seg: SeqLooseSegIndex, pub dot: LooseDotIndex, pub bend: LooseBendIndex, } -impl Segbend { +impl Cane { pub fn from_dot(dot: LooseDotIndex, drawing: &Drawing) -> Self { let bend = LooseDot::new(dot, drawing).bend(); let dot = LooseBend::new(bend, drawing).other_joint(dot); @@ -25,13 +25,13 @@ impl Segbend { } } -impl GetInterior for Segbend { +impl GetInterior for Cane { fn interior(&self) -> Vec { vec![self.bend.into(), self.dot.into(), self.seg.into()] } } -impl GetJoints for Segbend { +impl GetJoints for Cane { fn joints(&self) -> (SeqLooseSegIndex, LooseBendIndex) { (self.seg, self.bend) } diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 024c3f9..b1dbee4 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -8,6 +8,7 @@ use thiserror::Error; use crate::drawing::{ band::BandIndex, bend::{BendIndex, BendWeight, FixedBendIndex, LooseBendIndex, LooseBendWeight}, + cane::Cane, collect::Collect, dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight}, @@ -22,7 +23,6 @@ use crate::drawing::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegIndex, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight, }, - segbend::Segbend, wraparoundable::{GetWraparound, Wraparoundable, WraparoundableIndex}, }; use crate::geometry::{ @@ -409,7 +409,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() >= old(self.geometry_with_rtree.graph().edge_count() + 5))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - pub fn insert_segbend( + pub fn insert_cane( &mut self, from: DotIndex, around: WraparoundableIndex, @@ -417,11 +417,11 @@ impl Drawing { seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, cw: bool, - ) -> Result { + ) -> Result { let maybe_wraparound = self.wraparoundable(around).wraparound(); let infringables = self.collect().wraparounded_bows(around); - let segbend = self.add_segbend_with_infringables( + let cane = self.add_cane_with_infringables( from, around, dot_weight, @@ -432,25 +432,25 @@ impl Drawing { )?; if let Some(wraparound) = maybe_wraparound { - self.reattach_bend(wraparound, Some(segbend.bend)); + self.reattach_bend(wraparound, Some(cane.bend)); } - if let Some(outer) = self.primitive(segbend.bend).outer() { + if let Some(outer) = self.primitive(cane.bend).outer() { self.update_this_and_outward_bows(outer).map_err(|err| { - let joint = self.primitive(segbend.bend).other_joint(segbend.dot); - self.remove_segbend(&segbend, joint.into()); + let joint = self.primitive(cane.bend).other_joint(cane.dot); + self.remove_cane(&cane, joint.into()); err })?; } // Segs must not cross. - if let Some(collision) = self.detect_collision(segbend.seg.into()) { - let joint = self.primitive(segbend.bend).other_joint(segbend.dot); - self.remove_segbend(&segbend, joint.into()); + if let Some(collision) = self.detect_collision(cane.seg.into()) { + let joint = self.primitive(cane.bend).other_joint(cane.dot); + self.remove_cane(&cane, joint.into()); return Err(collision.into()); } - Ok::(segbend) + Ok::(cane) } #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] @@ -563,7 +563,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() >= old(self.geometry_with_rtree.graph().edge_count() + 5))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - pub fn add_segbend( + pub fn add_cane( &mut self, from: DotIndex, around: WraparoundableIndex, @@ -571,8 +571,8 @@ impl Drawing { seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, cw: bool, - ) -> Result { - self.add_segbend_with_infringables( + ) -> Result { + self.add_cane_with_infringables( from, around, dot_weight, @@ -587,7 +587,7 @@ impl Drawing { #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() >= old(self.geometry_with_rtree.graph().edge_count() + 5))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] - fn add_segbend_with_infringables( + fn add_cane_with_infringables( &mut self, from: DotIndex, around: WraparoundableIndex, @@ -596,7 +596,7 @@ impl Drawing { bend_weight: LooseBendWeight, cw: bool, infringables: Option<&[PrimitiveIndex]>, - ) -> Result { + ) -> Result { let seg_to = self.add_dot_with_infringables(dot_weight, infringables)?; let seg = self .add_seg_with_infringables(from, seg_to.into(), seg_weight, infringables) @@ -624,7 +624,7 @@ impl Drawing { err })?; - Ok::(Segbend { + Ok::(Cane { seg, dot: seg_to, bend, @@ -632,30 +632,30 @@ impl Drawing { } #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() - 4))] - pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) { - let maybe_outer = self.primitive(segbend.bend).outer(); + pub fn remove_cane(&mut self, cane: &Cane, face: LooseDotIndex) { + let maybe_outer = self.primitive(cane.bend).outer(); // Removing a loose bend affects its outer bends. if let Some(outer) = maybe_outer { - self.reattach_bend(outer, self.primitive(segbend.bend).inner()); + self.reattach_bend(outer, self.primitive(cane.bend).inner()); } - self.geometry_with_rtree.remove_bend(segbend.bend.into()); - self.geometry_with_rtree.remove_seg(segbend.seg.into()); + self.geometry_with_rtree.remove_bend(cane.bend.into()); + self.geometry_with_rtree.remove_seg(cane.seg.into()); // We must remove the dots only after the segs and bends because we need dots to calculate // the shapes, which we first need unchanged to remove the segs and bends from the R-tree. self.geometry_with_rtree.remove_dot(face.into()); - self.geometry_with_rtree.remove_dot(segbend.dot.into()); + self.geometry_with_rtree.remove_dot(cane.dot.into()); if let Some(outer) = maybe_outer { self.update_this_and_outward_bows(outer).unwrap(); // Must never fail. } } - pub fn segbend(&self, dot: LooseDotIndex) -> Segbend { - Segbend::from_dot(dot, self) + pub fn cane(&self, dot: LooseDotIndex) -> Cane { + Cane::from_dot(dot, self) } #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] diff --git a/src/drawing/guide.rs b/src/drawing/guide.rs index 3baa43e..9780260 100644 --- a/src/drawing/guide.rs +++ b/src/drawing/guide.rs @@ -18,10 +18,10 @@ use crate::{ }; use super::{ + cane::Cane, graph::PrimitiveIndex, primitive::GetJoints, rules::{Conditions, RulesTrait}, - segbend::Segbend, }; #[enum_dispatch] @@ -33,7 +33,7 @@ pub trait HeadTrait { #[derive(Debug, Clone, Copy)] pub enum Head { Bare(BareHead), - Segbend(SegbendHead), + Cane(CaneHead), } #[derive(Debug, Clone, Copy)] @@ -48,12 +48,12 @@ impl HeadTrait for BareHead { } #[derive(Debug, Clone, Copy)] -pub struct SegbendHead { +pub struct CaneHead { pub face: LooseDotIndex, - pub segbend: Segbend, + pub cane: Cane, } -impl HeadTrait for SegbendHead { +impl HeadTrait for CaneHead { fn face(&self) -> DotIndex { self.face.into() } @@ -157,8 +157,8 @@ impl<'a, CW: Copy, R: RulesTrait> Guide<'a, CW, R> { } pub fn head_cw(&self, head: &Head) -> Option { - if let Head::Segbend(head) = head { - let joints = self.drawing.primitive(head.segbend.bend).joints(); + if let Head::Cane(head) = head { + let joints = self.drawing.primitive(head.cane.bend).joints(); if head.face() == joints.0.into() { Some(false) @@ -176,12 +176,12 @@ impl<'a, CW: Copy, R: RulesTrait> Guide<'a, CW, R> { pos: head.face().primitive(self.drawing).shape().center(), // TODO. r: 0.0, }, - Head::Segbend(head) => { - if let Some(inner) = self.drawing.primitive(head.segbend.bend).inner() { + Head::Cane(head) => { + if let Some(inner) = self.drawing.primitive(head.cane.bend).inner() { self.bend_circle(inner.into(), width, &self.conditions(head.face().into())) } else { self.dot_circle( - self.drawing.primitive(head.segbend.bend).core().into(), + self.drawing.primitive(head.cane.bend).core().into(), width, &self.conditions(head.face().into()), ) @@ -220,28 +220,28 @@ impl<'a, CW: Copy, R: RulesTrait> Guide<'a, CW, R> { } } - pub fn segbend_head(&self, dot: LooseDotIndex) -> SegbendHead { - SegbendHead { + pub fn cane_head(&self, dot: LooseDotIndex) -> CaneHead { + CaneHead { face: dot, - segbend: self.drawing.segbend(dot), + cane: self.drawing.cane(dot), } } pub fn rear_head(&self, dot: LooseDotIndex) -> Head { - self.head(self.rear(self.segbend_head(dot))) + self.head(self.rear(self.cane_head(dot))) } pub fn head(&self, dot: DotIndex) -> Head { match dot { DotIndex::Fixed(fixed) => BareHead { dot: fixed }.into(), - DotIndex::Loose(loose) => self.segbend_head(loose).into(), + DotIndex::Loose(loose) => self.cane_head(loose).into(), } } - fn rear(&self, head: SegbendHead) -> DotIndex { + fn rear(&self, head: CaneHead) -> DotIndex { self.drawing - .primitive(head.segbend.seg) - .other_joint(head.segbend.dot.into()) + .primitive(head.cane.seg) + .other_joint(head.cane.dot.into()) } fn conditions(&self, node: PrimitiveIndex) -> Conditions { diff --git a/src/drawing/mod.rs b/src/drawing/mod.rs index bad08de..a4f100c 100644 --- a/src/drawing/mod.rs +++ b/src/drawing/mod.rs @@ -2,6 +2,7 @@ pub mod graph; pub mod band; pub mod bend; +pub mod cane; pub mod collect; pub mod dot; mod drawing; @@ -10,7 +11,6 @@ pub mod loose; pub mod primitive; pub mod rules; pub mod seg; -pub mod segbend; pub mod wraparoundable; pub use drawing::*; diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 2710647..7e3c87a 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -7,6 +7,7 @@ use crate::{ drawing::{ band::BandIndex, bend::LooseBendWeight, + cane::Cane, dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight}, graph::{GetMaybeNet, PrimitiveIndex}, primitive::{GetJoints, GetOtherJoint}, @@ -15,7 +16,6 @@ use crate::{ FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex, SeqLooseSegWeight, }, - segbend::Segbend, wraparoundable::WraparoundableIndex, Drawing, Infringement, LayoutException, }, @@ -50,11 +50,11 @@ impl Layout { self.drawing.remove_band(band); } - pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) { - self.drawing.remove_segbend(segbend, face) + pub fn remove_cane(&mut self, cane: &Cane, face: LooseDotIndex) { + self.drawing.remove_cane(cane, face) } - pub fn insert_segbend( + pub fn insert_cane( &mut self, from: DotIndex, around: WraparoundableIndex, @@ -62,9 +62,9 @@ impl Layout { seg_weight: SeqLooseSegWeight, bend_weight: LooseBendWeight, cw: bool, - ) -> Result { + ) -> Result { self.drawing - .insert_segbend(from, around, dot_weight, seg_weight, bend_weight, cw) + .insert_cane(from, around, dot_weight, seg_weight, bend_weight, cw) } #[debug_ensures(ret.is_ok() -> self.drawing.node_count() == old(self.drawing.node_count()) + weight.to_layer - weight.from_layer)] diff --git a/src/router/draw.rs b/src/router/draw.rs index b5fbc04..874bfa9 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -8,7 +8,7 @@ use crate::{ bend::{BendIndex, LooseBendWeight}, dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, graph::{GetLayer, GetMaybeNet, MakePrimitive}, - guide::{Guide, Head, HeadTrait, SegbendHead}, + guide::{CaneHead, Guide, Head, HeadTrait}, primitive::GetOtherJoint, rules::RulesTrait, seg::{LoneLooseSegWeight, SeqLooseSegWeight}, @@ -41,7 +41,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { } pub fn start(&mut self, from: LooseDotIndex) -> Head { - self.guide().segbend_head(from).into() + self.guide().cane_head(from).into() } #[debug_ensures(ret.is_ok() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() + 1))] @@ -94,12 +94,12 @@ impl<'a, R: RulesTrait> Draw<'a, R> { #[debug_ensures(ret.is_ok() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() + 4))] #[debug_ensures(ret.is_err() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] - pub fn segbend_around_dot( + pub fn cane_around_dot( &mut self, head: Head, around: FixedDotIndex, width: f64, - ) -> Result { + ) -> Result { let mut tangents = self .guide() .head_around_dot_segments(&head, around.into(), width)?; @@ -116,7 +116,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { let mut errs = vec![]; for (i, tangent) in [tangents.0, tangents.1].iter().enumerate() { - match self.segbend_around( + match self.cane_around( head, around.into(), tangent.start_point(), @@ -139,12 +139,12 @@ impl<'a, R: RulesTrait> Draw<'a, R> { #[debug_ensures(ret.is_ok() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() + 4))] #[debug_ensures(ret.is_err() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] - pub fn segbend_around_bend( + pub fn cane_around_bend( &mut self, head: Head, around: BendIndex, width: f64, - ) -> Result { + ) -> Result { let mut tangents = self .guide() .head_around_bend_segments(&head, around.into(), width)?; @@ -161,7 +161,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { let mut errs = vec![]; for (i, tangent) in [tangents.0, tangents.1].iter().enumerate() { - match self.segbend_around( + match self.cane_around( head, around.into(), tangent.start_point(), @@ -184,7 +184,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { #[debug_ensures(ret.is_ok() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() + 4))] #[debug_ensures(ret.is_err() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] - fn segbend_around( + fn cane_around( &mut self, head: Head, around: WraparoundableIndex, @@ -193,16 +193,16 @@ impl<'a, R: RulesTrait> Draw<'a, R> { cw: bool, width: f64, offset: f64, - ) -> Result { + ) -> Result { let head = self.extend_head(head, from)?; - self.segbend(head, around, to, cw, width, offset) + self.cane(head, around, to, cw, width, offset) } #[debug_ensures(self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] fn extend_head(&mut self, head: Head, to: Point) -> Result { - if let Head::Segbend(head) = head { + if let Head::Cane(head) = head { self.layout.move_dot(head.face.into(), to)?; - Ok(Head::Segbend(head)) + Ok(Head::Cane(head)) } else { Ok(head) } @@ -210,7 +210,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { #[debug_ensures(ret.is_ok() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() + 4))] #[debug_ensures(ret.is_err() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] - fn segbend( + fn cane( &mut self, head: Head, around: WraparoundableIndex, @@ -218,10 +218,10 @@ impl<'a, R: RulesTrait> Draw<'a, R> { cw: bool, width: f64, offset: f64, - ) -> Result { + ) -> Result { let layer = head.face().primitive(self.layout.drawing()).layer(); let maybe_net = head.face().primitive(self.layout.drawing()).maybe_net(); - let segbend = self.layout.insert_segbend( + let cane = self.layout.insert_cane( head.face(), around, LooseDotWeight { @@ -245,26 +245,26 @@ impl<'a, R: RulesTrait> Draw<'a, R> { }, cw, )?; - Ok::(SegbendHead { + Ok::(CaneHead { face: self .layout .drawing() - .primitive(segbend.bend) - .other_joint(segbend.dot), - segbend, + .primitive(cane.bend) + .other_joint(cane.dot), + cane, }) } #[debug_ensures(ret.is_some() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count() - 4))] #[debug_ensures(ret.is_none() -> self.layout.drawing().node_count() == old(self.layout.drawing().node_count()))] - pub fn undo_segbend(&mut self, head: SegbendHead) -> Option { + pub fn undo_cane(&mut self, head: CaneHead) -> Option { let prev_dot = self .layout .drawing() - .primitive(head.segbend.seg) - .other_joint(head.segbend.dot.into()); + .primitive(head.cane.seg) + .other_joint(head.cane.dot.into()); - self.layout.remove_segbend(&head.segbend, head.face); + self.layout.remove_cane(&head.cane, head.face); Some(self.guide().head(prev_dot)) } diff --git a/src/router/tracer.rs b/src/router/tracer.rs index 2e4e4c3..8d17c26 100644 --- a/src/router/tracer.rs +++ b/src/router/tracer.rs @@ -5,7 +5,7 @@ use crate::{ band::BandIndex, bend::LooseBendIndex, dot::FixedDotIndex, - guide::{BareHead, Head, SegbendHead}, + guide::{BareHead, CaneHead, Head}, rules::RulesTrait, }, layout::Layout, @@ -111,7 +111,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> { head: Head, around: NavvertexIndex, width: f64, - ) -> Result { + ) -> Result { match around { NavvertexIndex::FixedDot(dot) => self.wrap_around_fixed_dot(head, dot, width), NavvertexIndex::FixedBend(_fixed_bend) => todo!(), @@ -126,8 +126,8 @@ impl<'a, R: RulesTrait> Tracer<'a, R> { head: Head, around: FixedDotIndex, width: f64, - ) -> Result { - let head = Draw::new(self.layout).segbend_around_dot(head, around.into(), width)?; + ) -> Result { + let head = Draw::new(self.layout).cane_around_dot(head, around.into(), width)?; Ok(head) } @@ -136,16 +136,16 @@ impl<'a, R: RulesTrait> Tracer<'a, R> { head: Head, around: LooseBendIndex, width: f64, - ) -> Result { - let head = Draw::new(self.layout).segbend_around_bend(head, around.into(), width)?; + ) -> Result { + let head = Draw::new(self.layout).cane_around_bend(head, around.into(), width)?; Ok(head) } #[debug_ensures(trace.path.len() == old(trace.path.len() - 1))] pub fn undo_step(&mut self, trace: &mut Trace) { - if let Head::Segbend(head) = trace.head { - trace.head = Draw::new(self.layout).undo_segbend(head).unwrap(); + if let Head::Cane(head) = trace.head { + trace.head = Draw::new(self.layout).undo_cane(head).unwrap(); } else { panic!(); } diff --git a/src/specctra/design.rs b/src/specctra/design.rs index 1abc254..1696fad 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -9,9 +9,9 @@ use crate::{ layout::{zone::SolidZoneWeight, Layout}, math::Circle, specctra::{ - read::{self, ListTokenizer}, mesadata::SpecctraMesadata, - structure::{self, Layer, Pcb, Shape, DsnFile}, + read::{self, ListTokenizer}, + structure::{self, DsnFile, Layer, Pcb, Shape}, }, }; @@ -35,85 +35,81 @@ impl SpecctraDesign { let mut list_reader = read::ListTokenizer::new(reader); let dsn = list_reader.read_value::()?; - Ok(Self { - pcb: dsn.pcb, - }) + Ok(Self { pcb: dsn.pcb }) - //use super::structure::*; + //use super::structure::*; - // (this entire if let block does not belong here) + // (this entire if let block does not belong here) - /*let ses_name = filename.replace(".dsn", ".ses"); - let file2 = std::fs::File::create(ses_name).unwrap(); - let writer = std::io::BufWriter::new(file2); - let mut list_writer = super::write::ListWriter::new(writer); + /*let ses_name = filename.replace(".dsn", ".ses"); + let file2 = std::fs::File::create(ses_name).unwrap(); + let writer = std::io::BufWriter::new(file2); + let mut list_writer = super::write::ListWriter::new(writer); - let mut net_outs = HashMap::::new(); - for mut wire in dsn.pcb.wiring.wires { - // move wires to double check that importing the resulting file into KiCad does something - for point in &mut wire.path.coords { - point.x += 1000.0; - } - - if let Some(net) = net_outs.get_mut(&wire.net) { - net.wire.push(wire); - } else { - net_outs.insert( - wire.net.clone(), - NetOut { - name: wire.net.clone(), - wire: vec![wire], - via: Vec::new(), - }, - ); - } - } - for via in dsn.pcb.wiring.vias { - if let Some(net) = net_outs.get_mut(&via.net) { - net.via.push(via); - } else { - net_outs.insert( - via.net.clone(), - NetOut { - name: via.net.clone(), - wire: Vec::new(), - via: vec![via], - }, - ); - } + let mut net_outs = HashMap::::new(); + for mut wire in dsn.pcb.wiring.wires { + // move wires to double check that importing the resulting file into KiCad does something + for point in &mut wire.path.coords { + point.x += 1000.0; } - // build a basic .ses file from what was loaded - let ses = SesFile { - session: Session { - id: "ID".to_string(), - routes: Routes { - resolution: Resolution { - unit: "um".into(), - // TODO: why does resolution need to be adjusted from what was imported? - value: 1.0, - }, - library_out: Library { - images: Vec::new(), - padstacks: dsn.pcb.library.padstacks, - }, - network_out: NetworkOut { - net: net_outs.into_values().collect(), - }, + if let Some(net) = net_outs.get_mut(&wire.net) { + net.wire.push(wire); + } else { + net_outs.insert( + wire.net.clone(), + NetOut { + name: wire.net.clone(), + wire: vec![wire], + via: Vec::new(), + }, + ); + } + } + for via in dsn.pcb.wiring.vias { + if let Some(net) = net_outs.get_mut(&via.net) { + net.via.push(via); + } else { + net_outs.insert( + via.net.clone(), + NetOut { + name: via.net.clone(), + wire: Vec::new(), + via: vec![via], + }, + ); + } + } + + // build a basic .ses file from what was loaded + let ses = SesFile { + session: Session { + id: "ID".to_string(), + routes: Routes { + resolution: Resolution { + unit: "um".into(), + // TODO: why does resolution need to be adjusted from what was imported? + value: 1.0, + }, + library_out: Library { + images: Vec::new(), + padstacks: dsn.pcb.library.padstacks, + }, + network_out: NetworkOut { + net: net_outs.into_values().collect(), }, }, - };*/ + }, + };*/ - //println!("{:?}", list_writer.write_value(&ses)); + //println!("{:?}", list_writer.write_value(&ses)); } pub fn load_from_string(contents: String) -> Result { let mut list_reader = ListTokenizer::new(contents.as_bytes()); let dsn = list_reader.read_value::()?; - Ok(Self { - pcb: dsn.pcb, - }) + Ok(Self { pcb: dsn.pcb }) } pub fn make_board(&self) -> Board { @@ -601,14 +597,7 @@ impl SpecctraDesign { // iterate through path coords starting from the second for coord in coords.iter().skip(1) { - let pos = Self::pos( - place_pos, - place_rot, - pin_pos, - pin_rot, - coord.x, - coord.y, - ); + let pos = Self::pos(place_pos, place_rot, pin_pos, pin_rot, coord.x, coord.y); if pos == prev_pos { continue; @@ -691,15 +680,8 @@ impl SpecctraDesign { let index = board.add_zone_fixed_dot_infringably( FixedDotWeight { circle: Circle { - pos: Self::pos( - place_pos, - place_rot, - pin_pos, - pin_rot, - coord.x, - coord.y, - ) - .into(), + pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, coord.x, coord.y) + .into(), r: width / 2.0, }, layer,