From ca517f62bdda99f0b431b84cde310fd1c1c972df Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 24 May 2026 00:04:14 +0200 Subject: [PATCH] Create layer groups, assign each layer to one of it --- topola/src/board/mod.rs | 43 +++++++++++++++++++++++++++++++++++------ topola/src/specctra.rs | 2 +- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/topola/src/board/mod.rs b/topola/src/board/mod.rs index 893f44e..25e6489 100644 --- a/topola/src/board/mod.rs +++ b/topola/src/board/mod.rs @@ -9,12 +9,13 @@ mod transforms; use bidimap::BiBTreeMap; use derive_getters::Getters; +use derive_more::{Constructor, From}; +use serde::{Deserialize, Serialize}; use undoredo::{Delta, Recorder}; use crate::{ - layout::LayerId, layout::{ - Layout, LayoutHalfDelta, + LayerId, Layout, LayoutHalfDelta, compounds::{ComponentId, NetId, PinId}, primitives::{ JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, @@ -24,10 +25,35 @@ use crate::{ math::Vector2, }; +#[derive( + Clone, + Constructor, + Copy, + Debug, + Default, + Deserialize, + Eq, + From, + Ord, + PartialEq, + PartialOrd, + Serialize, +)] +pub struct LayerGroupId(usize); + +impl LayerGroupId { + #[inline] + pub fn index(self) -> usize { + self.0 + } +} + #[derive(Clone, Debug, Getters, Delta)] pub struct Board { layout: Layout, #[getter(skip)] + layer_groups: Recorder>, + #[getter(skip)] component_names: Recorder>, #[getter(skip)] pin_names: Recorder>, @@ -38,7 +64,7 @@ pub struct Board { } impl Board { - pub fn new(boundary: Vec>, layer_count: usize) -> Self { + /*pub fn new(boundary: Vec>, layer_count: usize) -> Self { Self { layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count), component_names: Recorder::new(BiBTreeMap::new()), @@ -46,16 +72,21 @@ impl Board { layer_names: Recorder::new(BiBTreeMap::new()), net_names: Recorder::new(BiBTreeMap::new()), } - } + }*/ pub fn with_names( boundary: Vec>, - layer_count: usize, + layer_groups: impl Into>, layer_names: BiBTreeMap, net_names: BiBTreeMap, ) -> Self { + let layer_groups = layer_groups.into(); Self { - layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count), + layout: Layout::new( + boundary.into_iter().map(Into::into).collect(), + layer_groups.len(), + ), + layer_groups: Recorder::new(layer_groups), component_names: Recorder::new(BiBTreeMap::new()), pin_names: Recorder::new(BiBTreeMap::new()), layer_names: Recorder::new(layer_names), diff --git a/topola/src/specctra.rs b/topola/src/specctra.rs index 247d035..24791d2 100644 --- a/topola/src/specctra.rs +++ b/topola/src/specctra.rs @@ -62,7 +62,7 @@ impl Board { .rev() .map(|p| Vector2::new(p.x as i64, p.y as i64)) .collect(), - dsn.pcb.structure.layers.len(), + vec![crate::board::LayerGroupId::new(0); dsn.pcb.structure.layers.len()], layer_names, net_names, );