mirror of https://codeberg.org/topola/topola.git
autorouter: encapsulate selection in `Selection` object
Just a thin wrapper over `HashSet` for now, but will contain more complicated logic later.
This commit is contained in:
parent
f893f73cd8
commit
d9ff08477c
|
|
@ -12,7 +12,10 @@ use petgraph::{
|
|||
use spade::InsertionError;
|
||||
|
||||
use crate::{
|
||||
autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex},
|
||||
autorouter::{
|
||||
ratsnest::{Ratsnest, RatsnestVertexIndex},
|
||||
selection::Selection,
|
||||
},
|
||||
drawing::{
|
||||
dot::FixedDotIndex,
|
||||
graph::{GetLayer, GetMaybeNet},
|
||||
|
|
@ -122,11 +125,7 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
Ok(Self { layout, ratsnest })
|
||||
}
|
||||
|
||||
pub fn autoroute(
|
||||
&mut self,
|
||||
selection: &HashSet<NodeIndex>,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
) {
|
||||
pub fn autoroute(&mut self, selection: &Selection, observer: &mut impl RouterObserverTrait<R>) {
|
||||
if let Some(mut autoroute) = self.autoroute_walk(selection) {
|
||||
while autoroute.next(self, observer) {
|
||||
//
|
||||
|
|
@ -134,7 +133,7 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn autoroute_walk(&mut self, selection: &HashSet<NodeIndex>) -> Option<Autoroute> {
|
||||
pub fn autoroute_walk(&mut self, selection: &Selection) -> Option<Autoroute> {
|
||||
Autoroute::new(
|
||||
self.ratsnest
|
||||
.graph()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
mod autorouter;
|
||||
pub mod ratsnest;
|
||||
pub mod selection;
|
||||
|
||||
pub use autorouter::*;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use crate::layout::NodeIndex;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Selection {
|
||||
set: HashSet<NodeIndex>,
|
||||
}
|
||||
|
||||
impl Selection {
|
||||
pub fn new() -> Selection {
|
||||
Self {
|
||||
set: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_at_node(&mut self, node: NodeIndex) {
|
||||
if !self.set.insert(node) {
|
||||
self.set.remove(&node);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, node: &NodeIndex) -> bool {
|
||||
self.set.contains(node)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ use rstar::AABB;
|
|||
use spade::InsertionError;
|
||||
|
||||
use topola::{
|
||||
autorouter::ratsnest::Ratsnest,
|
||||
autorouter::{ratsnest::Ratsnest, selection::Selection},
|
||||
drawing::{
|
||||
graph::{GetLayer, MakePrimitive},
|
||||
primitive::MakePrimitiveShape,
|
||||
|
|
@ -20,7 +20,7 @@ use topola::{
|
|||
|
||||
pub struct Overlay {
|
||||
ratsnest: Ratsnest,
|
||||
selection: HashSet<NodeIndex>,
|
||||
selection: Selection,
|
||||
active_layer: u64,
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ impl Overlay {
|
|||
pub fn new(layout: &Layout<impl RulesTrait>) -> Result<Self, InsertionError> {
|
||||
Ok(Self {
|
||||
ratsnest: Ratsnest::new(layout)?,
|
||||
selection: HashSet::new(),
|
||||
selection: Selection::new(),
|
||||
active_layer: 0,
|
||||
})
|
||||
}
|
||||
|
|
@ -73,23 +73,17 @@ impl Overlay {
|
|||
};
|
||||
|
||||
if shape.contains_point(p) {
|
||||
self.toggle_selection(node);
|
||||
self.selection.toggle_at_node(node);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn toggle_selection(&mut self, node: NodeIndex) {
|
||||
if !self.selection.insert(node) {
|
||||
self.selection.remove(&node);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ratsnest(&self) -> &Ratsnest {
|
||||
&self.ratsnest
|
||||
}
|
||||
|
||||
pub fn selection(&self) -> &HashSet<NodeIndex> {
|
||||
pub fn selection(&self) -> &Selection {
|
||||
&self.selection
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue