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 spade::InsertionError;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex},
|
autorouter::{
|
||||||
|
ratsnest::{Ratsnest, RatsnestVertexIndex},
|
||||||
|
selection::Selection,
|
||||||
|
},
|
||||||
drawing::{
|
drawing::{
|
||||||
dot::FixedDotIndex,
|
dot::FixedDotIndex,
|
||||||
graph::{GetLayer, GetMaybeNet},
|
graph::{GetLayer, GetMaybeNet},
|
||||||
|
|
@ -122,11 +125,7 @@ impl<R: RulesTrait> Autorouter<R> {
|
||||||
Ok(Self { layout, ratsnest })
|
Ok(Self { layout, ratsnest })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn autoroute(
|
pub fn autoroute(&mut self, selection: &Selection, observer: &mut impl RouterObserverTrait<R>) {
|
||||||
&mut self,
|
|
||||||
selection: &HashSet<NodeIndex>,
|
|
||||||
observer: &mut impl RouterObserverTrait<R>,
|
|
||||||
) {
|
|
||||||
if let Some(mut autoroute) = self.autoroute_walk(selection) {
|
if let Some(mut autoroute) = self.autoroute_walk(selection) {
|
||||||
while autoroute.next(self, observer) {
|
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(
|
Autoroute::new(
|
||||||
self.ratsnest
|
self.ratsnest
|
||||||
.graph()
|
.graph()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
mod autorouter;
|
mod autorouter;
|
||||||
pub mod ratsnest;
|
pub mod ratsnest;
|
||||||
|
pub mod selection;
|
||||||
|
|
||||||
pub use autorouter::*;
|
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 spade::InsertionError;
|
||||||
|
|
||||||
use topola::{
|
use topola::{
|
||||||
autorouter::ratsnest::Ratsnest,
|
autorouter::{ratsnest::Ratsnest, selection::Selection},
|
||||||
drawing::{
|
drawing::{
|
||||||
graph::{GetLayer, MakePrimitive},
|
graph::{GetLayer, MakePrimitive},
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
|
|
@ -20,7 +20,7 @@ use topola::{
|
||||||
|
|
||||||
pub struct Overlay {
|
pub struct Overlay {
|
||||||
ratsnest: Ratsnest,
|
ratsnest: Ratsnest,
|
||||||
selection: HashSet<NodeIndex>,
|
selection: Selection,
|
||||||
active_layer: u64,
|
active_layer: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ impl Overlay {
|
||||||
pub fn new(layout: &Layout<impl RulesTrait>) -> Result<Self, InsertionError> {
|
pub fn new(layout: &Layout<impl RulesTrait>) -> Result<Self, InsertionError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
ratsnest: Ratsnest::new(layout)?,
|
ratsnest: Ratsnest::new(layout)?,
|
||||||
selection: HashSet::new(),
|
selection: Selection::new(),
|
||||||
active_layer: 0,
|
active_layer: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -73,23 +73,17 @@ impl Overlay {
|
||||||
};
|
};
|
||||||
|
|
||||||
if shape.contains_point(p) {
|
if shape.contains_point(p) {
|
||||||
self.toggle_selection(node);
|
self.selection.toggle_at_node(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_selection(&mut self, node: NodeIndex) {
|
|
||||||
if !self.selection.insert(node) {
|
|
||||||
self.selection.remove(&node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ratsnest(&self) -> &Ratsnest {
|
pub fn ratsnest(&self) -> &Ratsnest {
|
||||||
&self.ratsnest
|
&self.ratsnest
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selection(&self) -> &HashSet<NodeIndex> {
|
pub fn selection(&self) -> &Selection {
|
||||||
&self.selection
|
&self.selection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue