mirror of https://codeberg.org/topola/topola.git
Add selectors for routes to persistable selection
This commit is contained in:
parent
39fb51d401
commit
31107559c8
|
|
@ -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<ComponentSelector>);
|
||||
|
||||
impl ComponentSelection {
|
||||
pub fn new() -> Self {
|
||||
Self(BTreeSet::new())
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn toggle(&mut self, selector: ComponentSelector) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
mod component;
|
||||
mod persistable;
|
||||
mod pin;
|
||||
mod route;
|
||||
|
||||
pub use component::{ComponentSelection, ComponentSelector};
|
||||
pub use persistable::PersistableSelection;
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<PinSelector>);
|
||||
|
||||
impl PinSelection {
|
||||
pub fn new() -> Self {
|
||||
Self(BTreeSet::new())
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn toggle(&mut self, selector: PinSelector) {
|
||||
|
|
|
|||
|
|
@ -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<RouteSelector>);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue