From 25efbd1627820fadd2c2fc48eeac84f814c99ff4 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 19 May 2026 12:43:09 +0200 Subject: [PATCH] Rearrange and rename selections and compounds --- topola-egui/src/display.rs | 17 +++-- topola-egui/src/viewport.rs | 4 +- topola-egui/src/workspace.rs | 6 +- topola/src/board.rs | 62 ++++++++++--------- topola/src/compounds/mod.rs | 6 +- topola/src/lib.rs | 8 +-- topola/src/primitives/mod.rs | 8 +-- topola/src/selections/component.rs | 29 +++++++++ topola/src/selections/mod.rs | 11 ++++ topola/src/selections/persistable.rs | 22 +++++++ .../pin_with_layer.rs} | 14 ++--- 11 files changed, 129 insertions(+), 58 deletions(-) create mode 100644 topola/src/selections/component.rs create mode 100644 topola/src/selections/mod.rs create mode 100644 topola/src/selections/persistable.rs rename topola/src/{selection.rs => selections/pin_with_layer.rs} (59%) diff --git a/topola-egui/src/display.rs b/topola-egui/src/display.rs index 7dc4183..eda886a 100644 --- a/topola-egui/src/display.rs +++ b/topola-egui/src/display.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use crate::{viewport::Viewport, workspace::Workspace}; -use topola::{Joint, Polygon, Segment}; +use topola::primitives::{Joint, Polygon, Segment}; pub struct Display {} @@ -53,7 +53,10 @@ impl Display { workspace.appearance_panel.layer_color( ctx, board.layer_name(joint.spec.layer), - board.pin_selection_contains_joint(&workspace.pin_selection, joint_id), + board.pin_with_layer_selection_contains_joint( + &workspace.selection.pins, + joint_id, + ), ), ); } @@ -68,7 +71,10 @@ impl Display { workspace.appearance_panel.layer_color( ctx, board.layer_name(segment.layer), - board.pin_selection_contains_segment(&workspace.pin_selection, segment_id), + board.pin_with_layer_selection_contains_segment( + &workspace.selection.pins, + segment_id, + ), ), ); } @@ -85,7 +91,10 @@ impl Display { workspace.appearance_panel.layer_color( ctx, board.layer_name(polygon.layer), - board.pin_selection_contains_polygon(&workspace.pin_selection, polygon_id), + board.pin_with_layer_selection_contains_polygon( + &workspace.selection.pins, + polygon_id, + ), ), ); } diff --git a/topola-egui/src/viewport.rs b/topola-egui/src/viewport.rs index d5920b2..26febda 100644 --- a/topola-egui/src/viewport.rs +++ b/topola-egui/src/viewport.rs @@ -58,7 +58,7 @@ impl Viewport { .router() .navmesher_board() .board() - .point_pin_selector( + .point_pin_with_layer_selector( 0, Vector2::new( pointer_scene_pos.x as i64, @@ -66,7 +66,7 @@ impl Viewport { ), ) { - workspace.pin_selection.toggle(pin_selector); + workspace.selection.pins.toggle(pin_selector); } } } diff --git a/topola-egui/src/workspace.rs b/topola-egui/src/workspace.rs index 254248e..1479460 100644 --- a/topola-egui/src/workspace.rs +++ b/topola-egui/src/workspace.rs @@ -2,14 +2,14 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use topola::{Autorouter, Board, PinSelection}; +use topola::{Autorouter, Board, selections::PersistableSelection}; use crate::{appearance_panel::AppearancePanel, translator::Translator}; pub struct Workspace { pub autorouter: Autorouter, pub appearance_panel: AppearancePanel, - pub pin_selection: PinSelection, + pub selection: PersistableSelection, } impl Workspace { @@ -19,7 +19,7 @@ impl Workspace { Self { autorouter: Autorouter::new(board), appearance_panel, - pin_selection: PinSelection::new(), + selection: PersistableSelection::new(), } } diff --git a/topola/src/board.rs b/topola/src/board.rs index 1ec6929..f65431c 100644 --- a/topola/src/board.rs +++ b/topola/src/board.rs @@ -14,7 +14,7 @@ use crate::{ JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, ViaSpec, }, - selection::{PinSelection, PinSelector}, + selections::{ComponentSelector, PinWithLayerSelection, PinWithLayerSelector}, }; #[derive(Clone, Debug, Getters)] @@ -91,19 +91,19 @@ impl Board { self.layout.add_polygon(polygon) } - pub fn joint_pin_selector(&self, joint_id: JointId) -> Option { - let joint = self.layout.joint(joint_id); + pub fn joint_pin_with_layer_selector(&self, id: JointId) -> Option { + let joint = self.layout.joint(id); - Some(PinSelector { + Some(PinWithLayerSelector { pin: self.pin_name(joint.spec.pin?)?.to_string(), layer: self.layer_name(joint.spec.layer)?.to_string(), }) } - pub fn segment_pin_selector(&self, segment_id: SegmentId) -> Option { - let segment = self.layout.segment(segment_id); + pub fn segment_pin_with_layer_selector(&self, id: SegmentId) -> Option { + let segment = self.layout.segment(id); - Some(PinSelector { + Some(PinWithLayerSelector { pin: self.pin_name(segment.spec.pin?)?.to_string(), layer: self.layer_name(segment.layer)?.to_string(), }) @@ -111,69 +111,73 @@ impl Board { // TODO: Vias. - pub fn polygon_pin_selector(&self, polygon_id: PolygonId) -> Option { - let polygon = self.layout.polygon(polygon_id); + pub fn polygon_pin_with_layer_selector(&self, id: PolygonId) -> Option { + let polygon = self.layout.polygon(id); - Some(PinSelector { + Some(PinWithLayerSelector { pin: self.pin_name(polygon.pin?)?.to_string(), layer: self.layer_name(polygon.layer)?.to_string(), }) } - pub fn point_pin_selector(&self, layer: usize, point: Vector2) -> Option { + pub fn point_pin_with_layer_selector( + &self, + layer: usize, + point: Vector2, + ) -> Option { if let Some(joint_id) = self.layout.locate_joints_at_point(layer, point).next() { - return self.joint_pin_selector(joint_id); + return self.joint_pin_with_layer_selector(joint_id); } if let Some(segment_id) = self.layout.locate_segments_at_point(layer, point).next() { - return self.segment_pin_selector(segment_id); + return self.segment_pin_with_layer_selector(segment_id); } // TODO: Vias. if let Some(polygon_id) = self.layout.locate_polygons_at_point(layer, point).next() { - return self.polygon_pin_selector(polygon_id); + return self.polygon_pin_with_layer_selector(polygon_id); } None } - pub fn pin_selection_contains_joint( + pub fn pin_with_layer_selection_contains_joint( &self, - pin_selection: &PinSelection, - joint_id: JointId, + selection: &PinWithLayerSelection, + id: JointId, ) -> bool { - let Some(pin_selector) = self.joint_pin_selector(joint_id) else { + let Some(pin_selector) = self.joint_pin_with_layer_selector(id) else { return false; }; - pin_selection.0.contains(&pin_selector) + selection.0.contains(&pin_selector) } - pub fn pin_selection_contains_segment( + pub fn pin_with_layer_selection_contains_segment( &self, - pin_selection: &PinSelection, - segment_id: SegmentId, + selection: &PinWithLayerSelection, + id: SegmentId, ) -> bool { - let Some(pin_selector) = self.segment_pin_selector(segment_id) else { + let Some(pin_selector) = self.segment_pin_with_layer_selector(id) else { return false; }; - pin_selection.0.contains(&pin_selector) + selection.0.contains(&pin_selector) } // TODO: Vias. - pub fn pin_selection_contains_polygon( + pub fn pin_with_layer_selection_contains_polygon( &self, - pin_selection: &PinSelection, - polygon_id: PolygonId, + selection: &PinWithLayerSelection, + id: PolygonId, ) -> bool { - let Some(pin_selector) = self.polygon_pin_selector(polygon_id) else { + let Some(pin_selector) = self.polygon_pin_with_layer_selector(id) else { return false; }; - pin_selection.0.contains(&pin_selector) + selection.0.contains(&pin_selector) } pub fn pin_name(&self, pin: PinId) -> Option<&str> { diff --git a/topola/src/compounds/mod.rs b/topola/src/compounds/mod.rs index 4899ef6..a559ef7 100644 --- a/topola/src/compounds/mod.rs +++ b/topola/src/compounds/mod.rs @@ -6,6 +6,6 @@ mod component; mod net; mod pin; -pub use component::{Component, ComponentId}; -pub use net::NetId; -pub use pin::{Pin, PinId}; +pub use component::*; +pub use net::*; +pub use pin::*; diff --git a/topola/src/lib.rs b/topola/src/lib.rs index 46b9178..f7325df 100644 --- a/topola/src/lib.rs +++ b/topola/src/lib.rs @@ -10,10 +10,10 @@ mod layout; mod math; mod navmesher; mod pathfinder; -mod primitives; +pub mod primitives; mod ratsnest; mod router; -mod selection; +pub mod selections; mod specctra; pub use crate::autorouter::Autorouter; @@ -21,8 +21,4 @@ pub use crate::board::Board; pub use crate::compounds::{Pin, PinId}; pub use crate::layout::Layout; pub use crate::math::Vector2; -pub use crate::primitives::{ - Joint, JointId, Polygon, PolygonId, PrimitiveId, Segment, SegmentId, Via, ViaId, -}; pub use crate::ratsnest::{Ratline, Ratsnest}; -pub use crate::selection::{PinSelection, PinSelector}; diff --git a/topola/src/primitives/mod.rs b/topola/src/primitives/mod.rs index 4e02afb..f234d8d 100644 --- a/topola/src/primitives/mod.rs +++ b/topola/src/primitives/mod.rs @@ -9,10 +9,10 @@ mod polygon; mod segment; mod via; -pub use joint::{Joint, JointId, JointSpec}; -pub use polygon::{Polygon, PolygonId}; -pub use segment::{Segment, SegmentId, SegmentSpec}; -pub use via::{Via, ViaId, ViaSpec}; +pub use joint::*; +pub use polygon::*; +pub use segment::*; +pub use via::*; #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub enum PrimitiveId { diff --git a/topola/src/selections/component.rs b/topola/src/selections/component.rs new file mode 100644 index 0000000..90dd009 --- /dev/null +++ b/topola/src/selections/component.rs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use std::collections::BTreeSet; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub struct ComponentSelector { + pub component: String, +} + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct ComponentSelection(pub BTreeSet); + +impl ComponentSelection { + pub fn new() -> Self { + Self(BTreeSet::new()) + } + + pub fn toggle(&mut self, selector: ComponentSelector) { + if self.0.contains(&selector) { + self.0.remove(&selector); + } else { + self.0.insert(selector); + } + } +} diff --git a/topola/src/selections/mod.rs b/topola/src/selections/mod.rs new file mode 100644 index 0000000..5481dfe --- /dev/null +++ b/topola/src/selections/mod.rs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +mod component; +mod persistable; +mod pin_with_layer; + +pub use component::*; +pub use persistable::*; +pub use pin_with_layer::*; diff --git a/topola/src/selections/persistable.rs b/topola/src/selections/persistable.rs new file mode 100644 index 0000000..af8fea1 --- /dev/null +++ b/topola/src/selections/persistable.rs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use serde::{Deserialize, Serialize}; + +use crate::selections::{ComponentSelection, PinWithLayerSelection}; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct PersistableSelection { + pub components: ComponentSelection, + pub pins: PinWithLayerSelection, +} + +impl PersistableSelection { + pub fn new() -> Self { + Self { + components: ComponentSelection::new(), + pins: PinWithLayerSelection::new(), + } + } +} diff --git a/topola/src/selection.rs b/topola/src/selections/pin_with_layer.rs similarity index 59% rename from topola/src/selection.rs rename to topola/src/selections/pin_with_layer.rs index 596ceaf..c2990a1 100644 --- a/topola/src/selection.rs +++ b/topola/src/selections/pin_with_layer.rs @@ -7,24 +7,24 @@ use std::collections::BTreeSet; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] -pub struct PinSelector { +pub struct PinWithLayerSelector { pub pin: String, pub layer: String, } #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct PinSelection(pub BTreeSet); +pub struct PinWithLayerSelection(pub BTreeSet); -impl PinSelection { +impl PinWithLayerSelection { pub fn new() -> Self { Self(BTreeSet::new()) } - pub fn toggle(&mut self, pin_selector: PinSelector) { - if self.0.contains(&pin_selector) { - self.0.remove(&pin_selector); + pub fn toggle(&mut self, selector: PinWithLayerSelector) { + if self.0.contains(&selector) { + self.0.remove(&selector); } else { - self.0.insert(pin_selector); + self.0.insert(selector); } } }