From 31107559c812fa7ae30829c7d4aa4275a4b05402 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 25 May 2026 13:44:31 +0200 Subject: [PATCH] Add selectors for routes to persistable selection --- topola/src/board/selections/component.rs | 7 ++-- topola/src/board/selections/mod.rs | 1 + topola/src/board/selections/persistable.rs | 9 +++-- topola/src/board/selections/pin.rs | 9 +++-- topola/src/board/selections/route.rs | 41 ++++++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 topola/src/board/selections/route.rs diff --git a/topola/src/board/selections/component.rs b/topola/src/board/selections/component.rs index 90dd009..1a59b21 100644 --- a/topola/src/board/selections/component.rs +++ b/topola/src/board/selections/component.rs @@ -4,19 +4,20 @@ use std::collections::BTreeSet; +use derive_more::Constructor; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +#[derive(Clone, Constructor, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub struct ComponentSelector { pub component: String, } -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub struct ComponentSelection(pub BTreeSet); impl ComponentSelection { pub fn new() -> Self { - Self(BTreeSet::new()) + Default::default() } pub fn toggle(&mut self, selector: ComponentSelector) { diff --git a/topola/src/board/selections/mod.rs b/topola/src/board/selections/mod.rs index 49deb88..b249160 100644 --- a/topola/src/board/selections/mod.rs +++ b/topola/src/board/selections/mod.rs @@ -5,6 +5,7 @@ mod component; mod persistable; mod pin; +mod route; pub use component::{ComponentSelection, ComponentSelector}; pub use persistable::PersistableSelection; diff --git a/topola/src/board/selections/persistable.rs b/topola/src/board/selections/persistable.rs index ac137a3..a8da51e 100644 --- a/topola/src/board/selections/persistable.rs +++ b/topola/src/board/selections/persistable.rs @@ -4,11 +4,15 @@ use serde::{Deserialize, Serialize}; -use crate::board::selections::{ComponentSelection, PinSelection}; +use crate::{ + board::selections::{ComponentSelection, PinSelection}, + selections::route::RouteSelection, +}; -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub struct PersistableSelection { pub components: ComponentSelection, + pub routes: RouteSelection, pub pins: PinSelection, } @@ -16,6 +20,7 @@ impl PersistableSelection { pub fn new() -> Self { Self { components: ComponentSelection::new(), + routes: RouteSelection::new(), pins: PinSelection::new(), } } diff --git a/topola/src/board/selections/pin.rs b/topola/src/board/selections/pin.rs index 2226ed3..944d08e 100644 --- a/topola/src/board/selections/pin.rs +++ b/topola/src/board/selections/pin.rs @@ -4,20 +4,23 @@ use std::collections::BTreeSet; +use derive_more::Constructor; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +#[derive( + Clone, Constructor, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, +)] pub struct PinSelector { pub pin: String, pub layer: String, } -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] pub struct PinSelection(pub BTreeSet); impl PinSelection { pub fn new() -> Self { - Self(BTreeSet::new()) + Default::default() } pub fn toggle(&mut self, selector: PinSelector) { diff --git a/topola/src/board/selections/route.rs b/topola/src/board/selections/route.rs new file mode 100644 index 0000000..b75dfa4 --- /dev/null +++ b/topola/src/board/selections/route.rs @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use std::collections::BTreeSet; + +use serde::{Deserialize, Serialize}; + +use crate::selections::PinSelector; + +#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub struct RouteSelector { + lesser_pin: PinSelector, + greater_pin: PinSelector, +} + +impl RouteSelector { + pub fn new(pin1: PinSelector, pin2: PinSelector) -> Self { + Self { + lesser_pin: std::cmp::min(pin1.clone(), pin2.clone()), + greater_pin: std::cmp::max(pin1, pin2), + } + } +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] +pub struct RouteSelection(pub BTreeSet); + +impl RouteSelection { + pub fn new() -> Self { + Default::default() + } + + pub fn toggle(&mut self, selector: RouteSelector) { + if self.0.contains(&selector) { + self.0.remove(&selector); + } else { + self.0.insert(selector); + } + } +}