From e20c9aa3d6a4e6f879bd9002b7f78c189113ca58 Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Mon, 31 Mar 2025 01:18:16 +0200 Subject: [PATCH] feat(specctra-core/mesadata, layout): make `Layout` clonable This change also propagates to `SpecctraMesadata`, which is a bit unfortunate, because the code that needs this will never mutate the mesadata, wrapping it in an `Arc` would be a possible alternative. --- crates/specctra-core/src/mesadata.rs | 4 ++-- src/drawing/drawing.rs | 2 +- src/geometry/geometry.rs | 11 +++++++++++ src/geometry/recording_with_rtree.rs | 10 ++++++++++ src/geometry/with_rtree.rs | 12 ++++++++++++ src/layout/layout.rs | 2 +- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/specctra-core/src/mesadata.rs b/crates/specctra-core/src/mesadata.rs index 1eda25f..a7b3087 100644 --- a/crates/specctra-core/src/mesadata.rs +++ b/crates/specctra-core/src/mesadata.rs @@ -37,7 +37,7 @@ pub trait AccessMesadata: AccessRules { fn netname_net(&self, netname: &str) -> Option; } -#[derive(Debug)] +#[derive(Clone, Debug)] /// [`SpecctraRule`] represents the basic routing constraints used by an auto-router, such as /// the Topola auto-router, in a PCB design process. This struct defines two key design /// rules: the width of the trace and the minimum clearance between electrical features. @@ -62,7 +62,7 @@ impl SpecctraRule { } } -#[derive(Debug)] +#[derive(Clone, Debug)] /// [`SpecctraMesadata`] holds the metadata required by the Specctra auto-router to /// understand and enforce design rules across various net classes and layers in a PCB layout. /// This struct encapsulates information about rules for individual nets, net classes, diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index d1eeb53..0b2896d 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -102,7 +102,7 @@ pub type DrawingEdit = GeometryEdit< BendIndex, >; -#[derive(Debug, Getters)] +#[derive(Clone, Debug, Getters)] pub struct Drawing { recording_geometry_with_rtree: RecordingGeometryWithRtree< PrimitiveWeight, diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index 72a97dc..a2013a6 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -97,6 +97,17 @@ pub struct Geometry { bend_index_marker: PhantomData, } +impl Clone + for Geometry +{ + fn clone(&self) -> Self { + Self { + graph: self.graph.clone(), + ..Self::new() + } + } +} + impl Default for Geometry { fn default() -> Self { Self::new() diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index abff11f..4e74220 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -23,6 +23,16 @@ pub struct RecordingGeometryWithRtree { geometry_with_rtree: GeometryWithRtree, } +impl Clone + for RecordingGeometryWithRtree +{ + fn clone(&self) -> Self { + Self { + geometry_with_rtree: self.geometry_with_rtree.clone(), + } + } +} + impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, diff --git a/src/geometry/with_rtree.rs b/src/geometry/with_rtree.rs index 338f7f9..80c9338 100644 --- a/src/geometry/with_rtree.rs +++ b/src/geometry/with_rtree.rs @@ -45,6 +45,18 @@ pub struct GeometryWithRtree { layer_count: usize, } +impl Clone + for GeometryWithRtree +{ + fn clone(&self) -> Self { + Self { + geometry: self.geometry.clone(), + rtree: self.rtree.clone(), + layer_count: self.layer_count, + } + } +} + #[debug_invariant(self.test_envelopes())] #[debug_invariant(self.geometry.graph().node_count() == self.rtree.size())] impl< diff --git a/src/layout/layout.rs b/src/layout/layout.rs index c91dcfa..346a427 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -56,7 +56,7 @@ pub enum CompoundWeight { pub type NodeIndex = GenericNode>; pub type LayoutEdit = DrawingEdit; -#[derive(Debug, Getters)] +#[derive(Clone, Debug, Getters)] /// Structure for managing the Layout design pub struct Layout { drawing: Drawing,