Make nets keep track of pins they contain

This commit is contained in:
Mikolaj Wielgus 2026-06-02 23:38:39 +02:00
parent dde3720e04
commit b3dc4089a4
8 changed files with 44 additions and 27 deletions

View File

@ -16,16 +16,16 @@ pub struct DragMoveInteractor {
} }
impl DragMoveInteractor { impl DragMoveInteractor {
pub fn abort(&mut self, board: &mut Board) {
board.discard_delta();
}
pub fn hold(&mut self, board: &mut Board, pointer: Vector2<i64>) { pub fn hold(&mut self, board: &mut Board, pointer: Vector2<i64>) {
board.discard_delta(); board.discard_delta();
board.move_components_by(self.selection.clone(), pointer - self.origin); board.move_components_by(self.selection.clone(), pointer - self.origin);
} }
pub fn abort(&mut self, board: &mut Board) {
board.discard_delta();
}
pub fn release(&mut self, board: &mut Board, pointer: Vector2<i64>) { pub fn release(&mut self, board: &mut Board, pointer: Vector2<i64>) {
self.hold(board, pointer); self.hold(board, pointer);
} }

View File

@ -47,10 +47,6 @@ impl DragSelectInteractor {
} }
} }
pub fn abort(&mut self) {
self.selection = self.original_selection.clone();
}
pub fn hold(&mut self, board: &Board, pointer: Vector2<i64>) { pub fn hold(&mut self, board: &Board, pointer: Vector2<i64>) {
self.selection = PersistableSelection::new(); self.selection = PersistableSelection::new();
@ -184,4 +180,8 @@ impl DragSelectInteractor {
self.selection = combined_selection; self.selection = combined_selection;
} }
pub fn abort(&mut self) {
self.selection = self.original_selection.clone();
}
} }

View File

@ -79,12 +79,12 @@ impl Board {
component_id component_id
} }
pub fn ensure_named_pin(&mut self, pin_name: String) -> PinId { pub fn ensure_named_pin(&mut self, pin_name: String, net_id: Option<NetId>) -> PinId {
if let Some(pin) = self.pin_names.get_by_right(&pin_name) { if let Some(pin) = self.pin_names.get_by_right(&pin_name) {
return *pin; return *pin;
}; };
let pin_id = self.layout.insert_pin(); let pin_id = self.layout.insert_pin(net_id);
self.pin_names.insert(pin_id, pin_name); self.pin_names.insert(pin_id, pin_name);
pin_id pin_id

View File

@ -5,6 +5,8 @@
use derive_more::{Constructor, From}; use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::PinId;
#[derive( #[derive(
Clone, Clone,
Constructor, Constructor,
@ -27,3 +29,14 @@ impl NetId {
self.0 self.0
} }
} }
#[derive(Clone, Debug, Default)]
pub struct Net {
pub pins: Vec<PinId>,
}
impl Net {
pub fn new() -> Self {
Default::default()
}
}

View File

@ -30,7 +30,7 @@ impl PinId {
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct Pin { pub struct Pin {
pub joints: Vec<JointId>, pub joints: Vec<JointId>,
pub segments: Vec<SegmentId>, pub segments: Vec<SegmentId>,
@ -40,11 +40,6 @@ pub struct Pin {
impl Pin { impl Pin {
pub fn new() -> Self { pub fn new() -> Self {
Self { Default::default()
joints: Vec::new(),
segments: Vec::new(),
vias: Vec::new(),
polygons: Vec::new(),
}
} }
} }

View File

@ -8,7 +8,7 @@ use crate::{
Pin, PinId, Pin, PinId,
layout::{ layout::{
Layout, Layout,
compounds::{Component, ComponentId}, compounds::{Component, ComponentId, NetId},
}, },
primitives::{ primitives::{
Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId, Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId,
@ -21,8 +21,15 @@ impl Layout {
ComponentId::new(self.components.push(Component::new())) ComponentId::new(self.components.push(Component::new()))
} }
pub fn insert_pin(&mut self) -> PinId { pub fn insert_pin(&mut self, net_id: Option<NetId>) -> PinId {
PinId::new(self.pins.push(Pin::new())) let pin_id = PinId::new(self.pins.push(Pin::new()));
if let Some(net_id) = net_id {
self.nets
.modify(net_id.index(), |net| net.pins.push(pin_id));
}
pin_id
} }
pub fn insert_joint(&mut self, spec: JointSpec) -> JointId { pub fn insert_joint(&mut self, spec: JointSpec) -> JointId {

View File

@ -26,7 +26,7 @@ use undoredo::aliases::RTreeHalfDelta;
use undoredo::{Delta, Recorder}; use undoredo::{Delta, Recorder};
use crate::layout::{ use crate::layout::{
compounds::{Component, ComponentId, Pin, PinId}, compounds::{Component, ComponentId, Net, Pin, PinId},
primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId}, primitives::{Joint, JointId, Polygon, PolygonId, Segment, SegmentId, Via, ViaId},
}; };
@ -63,6 +63,7 @@ pub struct Layout {
layer_count: usize, layer_count: usize,
components: Recorder<StableVec<Component>>, components: Recorder<StableVec<Component>>,
nets: Recorder<StableVec<Net>>,
pins: Recorder<StableVec<Pin>>, pins: Recorder<StableVec<Pin>>,
joints: Recorder<StableVec<Joint>>, joints: Recorder<StableVec<Joint>>,
@ -96,6 +97,7 @@ impl Layout {
layer_count, layer_count,
components: Recorder::new(StableVec::new()), components: Recorder::new(StableVec::new()),
nets: Recorder::new(StableVec::new()),
pins: Recorder::new(StableVec::new()), pins: Recorder::new(StableVec::new()),
joints: Recorder::new(StableVec::new()), joints: Recorder::new(StableVec::new()),

View File

@ -159,9 +159,9 @@ impl Board {
for pin in &image.pins { for pin in &image.pins {
let pin_name = format!("{}-{}", place.name, pin.id); let pin_name = format!("{}-{}", place.name, pin.id);
let net = pin_nets.get(&pin_name).copied(); let net_id = pin_nets.get(&pin_name).copied();
let pin_id = board.ensure_named_pin(pin_name.clone()); let pin_id = board.ensure_named_pin(pin_name.clone(), net_id);
let padstack = dsn.pcb.library.find_padstack_by_name(&pin.name).unwrap(); let padstack = dsn.pcb.library.find_padstack_by_name(&pin.name).unwrap();
for shape in padstack.shapes.iter() { for shape in padstack.shapes.iter() {
@ -174,7 +174,7 @@ impl Board {
pin.point_with_rotation(), pin.point_with_rotation(),
circle.diameter / 2.0, circle.diameter / 2.0,
layer, layer,
net, net_id,
Some(component_id), Some(component_id),
Some(pin_id), Some(pin_id),
!place_side_is_front, !place_side_is_front,
@ -192,7 +192,7 @@ impl Board {
rect.x2, rect.x2,
rect.y2, rect.y2,
layer, layer,
net, net_id,
Some(component_id), Some(component_id),
Some(pin_id), Some(pin_id),
!place_side_is_front, !place_side_is_front,
@ -208,7 +208,7 @@ impl Board {
&path.coords, &path.coords,
path.width, path.width,
layer, layer,
net, net_id,
Some(component_id), Some(component_id),
Some(pin_id), Some(pin_id),
!place_side_is_front, !place_side_is_front,
@ -224,7 +224,7 @@ impl Board {
&polygon.coords, &polygon.coords,
polygon.width, polygon.width,
layer, layer,
net, net_id,
Some(component_id), Some(component_id),
Some(pin_id), Some(pin_id),
!place_side_is_front, !place_side_is_front,