mirror of https://codeberg.org/topola/topola.git
autorouter: don't cache nodes in `Selection`
This solves the problem of having to use stateful deserialization.
This commit is contained in:
parent
53fa89d02c
commit
06150f5167
|
|
@ -183,7 +183,9 @@ impl<R: RulesTrait> Autorouter<R> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.vertex_index();
|
.vertex_index();
|
||||||
|
|
||||||
selection.contains(source_vertex.into()) && selection.contains(to_vertex.into())
|
let layout = self.layout.lock().unwrap();
|
||||||
|
selection.contains_node(&layout, source_vertex.into())
|
||||||
|
&& selection.contains_node(&layout, to_vertex.into())
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,12 @@ use crate::{
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Selection {
|
pub struct Selection {
|
||||||
pins: HashSet<String>,
|
pins: HashSet<String>,
|
||||||
#[serde(skip)]
|
|
||||||
primitives: HashSet<PrimitiveIndex>,
|
|
||||||
#[serde(skip)]
|
|
||||||
zones: HashSet<GenericIndex<ZoneWeight>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selection {
|
impl Selection {
|
||||||
pub fn new() -> Selection {
|
pub fn new() -> Selection {
|
||||||
Self {
|
Self {
|
||||||
pins: HashSet::new(),
|
pins: HashSet::new(),
|
||||||
primitives: HashSet::new(),
|
|
||||||
zones: HashSet::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +23,7 @@ impl Selection {
|
||||||
let maybe_pin = layout.node_pin(node);
|
let maybe_pin = layout.node_pin(node);
|
||||||
|
|
||||||
if let Some(ref pin) = maybe_pin {
|
if let Some(ref pin) = maybe_pin {
|
||||||
if self.contains(node) {
|
if self.contains_node(layout, node) {
|
||||||
self.remove_pin(layout, pin);
|
self.remove_pin(layout, pin);
|
||||||
} else {
|
} else {
|
||||||
self.add_pin(layout, pin);
|
self.add_pin(layout, pin);
|
||||||
|
|
@ -38,49 +32,18 @@ impl Selection {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_pin(&mut self, layout: &Layout<impl RulesTrait>, pin: &String) {
|
fn add_pin(&mut self, layout: &Layout<impl RulesTrait>, pin: &String) {
|
||||||
for primitive in layout.drawing().primitive_nodes().filter(|primitive| {
|
|
||||||
layout
|
|
||||||
.node_pin(NodeIndex::Primitive(*primitive))
|
|
||||||
.is_some_and(|p| p == pin)
|
|
||||||
}) {
|
|
||||||
self.primitives.insert(primitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
for zone in layout.zone_nodes().filter(|zone| {
|
|
||||||
layout
|
|
||||||
.node_pin(NodeIndex::Compound(*zone))
|
|
||||||
.is_some_and(|p| p == pin)
|
|
||||||
}) {
|
|
||||||
self.zones.insert(zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.pins.insert(pin.clone());
|
self.pins.insert(pin.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_pin(&mut self, layout: &Layout<impl RulesTrait>, pin: &String) {
|
fn remove_pin(&mut self, layout: &Layout<impl RulesTrait>, pin: &String) {
|
||||||
for primitive in layout.drawing().primitive_nodes().filter(|primitive| {
|
|
||||||
layout
|
|
||||||
.node_pin(NodeIndex::Primitive(*primitive))
|
|
||||||
.is_some_and(|p| p == pin)
|
|
||||||
}) {
|
|
||||||
self.primitives.remove(&primitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
for zone in layout.zone_nodes().filter(|zone| {
|
|
||||||
layout
|
|
||||||
.node_pin(NodeIndex::Compound(*zone))
|
|
||||||
.is_some_and(|p| p == pin)
|
|
||||||
}) {
|
|
||||||
self.zones.remove(&zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.pins.remove(pin);
|
self.pins.remove(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains(&self, node: NodeIndex) -> bool {
|
pub fn contains_node(&self, layout: &Layout<impl RulesTrait>, node: NodeIndex) -> bool {
|
||||||
match node {
|
if let Some(pin) = layout.node_pin(node) {
|
||||||
NodeIndex::Primitive(primitive) => self.primitives.contains(&primitive),
|
self.pins.contains(pin)
|
||||||
NodeIndex::Compound(zone) => self.zones.contains(&zone),
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,7 +363,7 @@ impl eframe::App for App {
|
||||||
let color = if shared_data.highlighteds.contains(&primitive)
|
let color = if shared_data.highlighteds.contains(&primitive)
|
||||||
|| overlay
|
|| overlay
|
||||||
.selection()
|
.selection()
|
||||||
.contains(GenericNode::Primitive(primitive))
|
.contains_node(&layout, GenericNode::Primitive(primitive))
|
||||||
{
|
{
|
||||||
egui::Color32::from_rgb(100, 100, 255)
|
egui::Color32::from_rgb(100, 100, 255)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -373,7 +373,9 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
for zone in layout.layer_zone_nodes(1) {
|
for zone in layout.layer_zone_nodes(1) {
|
||||||
let color = if overlay.selection().contains(GenericNode::Compound(zone))
|
let color = if overlay
|
||||||
|
.selection()
|
||||||
|
.contains_node(&layout, GenericNode::Compound(zone))
|
||||||
{
|
{
|
||||||
egui::Color32::from_rgb(100, 100, 255)
|
egui::Color32::from_rgb(100, 100, 255)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -388,7 +390,7 @@ impl eframe::App for App {
|
||||||
let color = if shared_data.highlighteds.contains(&primitive)
|
let color = if shared_data.highlighteds.contains(&primitive)
|
||||||
|| overlay
|
|| overlay
|
||||||
.selection()
|
.selection()
|
||||||
.contains(GenericNode::Primitive(primitive))
|
.contains_node(&layout, GenericNode::Primitive(primitive))
|
||||||
{
|
{
|
||||||
egui::Color32::from_rgb(255, 100, 100)
|
egui::Color32::from_rgb(255, 100, 100)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -398,7 +400,9 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
for zone in layout.layer_zone_nodes(0) {
|
for zone in layout.layer_zone_nodes(0) {
|
||||||
let color = if overlay.selection().contains(GenericNode::Compound(zone))
|
let color = if overlay
|
||||||
|
.selection()
|
||||||
|
.contains_node(&layout, GenericNode::Compound(zone))
|
||||||
{
|
{
|
||||||
egui::Color32::from_rgb(255, 100, 100)
|
egui::Color32::from_rgb(255, 100, 100)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue