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 {
pub fn abort(&mut self, board: &mut Board) {
board.discard_delta();
}
pub fn hold(&mut self, board: &mut Board, pointer: Vector2<i64>) {
board.discard_delta();
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>) {
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>) {
self.selection = PersistableSelection::new();
@ -184,4 +180,8 @@ impl DragSelectInteractor {
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
}
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) {
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);
pin_id

View File

@ -5,6 +5,8 @@
use derive_more::{Constructor, From};
use serde::{Deserialize, Serialize};
use crate::PinId;
#[derive(
Clone,
Constructor,
@ -27,3 +29,14 @@ impl NetId {
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 joints: Vec<JointId>,
pub segments: Vec<SegmentId>,
@ -40,11 +40,6 @@ pub struct Pin {
impl Pin {
pub fn new() -> Self {
Self {
joints: Vec::new(),
segments: Vec::new(),
vias: Vec::new(),
polygons: Vec::new(),
}
Default::default()
}
}

View File

@ -8,7 +8,7 @@ use crate::{
Pin, PinId,
layout::{
Layout,
compounds::{Component, ComponentId},
compounds::{Component, ComponentId, NetId},
},
primitives::{
Joint, JointId, JointSpec, Polygon, PolygonId, Segment, SegmentId, SegmentSpec, Via, ViaId,
@ -21,8 +21,15 @@ impl Layout {
ComponentId::new(self.components.push(Component::new()))
}
pub fn insert_pin(&mut self) -> PinId {
PinId::new(self.pins.push(Pin::new()))
pub fn insert_pin(&mut self, net_id: Option<NetId>) -> PinId {
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 {

View File

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

View File

@ -159,9 +159,9 @@ impl Board {
for pin in &image.pins {
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();
for shape in padstack.shapes.iter() {
@ -174,7 +174,7 @@ impl Board {
pin.point_with_rotation(),
circle.diameter / 2.0,
layer,
net,
net_id,
Some(component_id),
Some(pin_id),
!place_side_is_front,
@ -192,7 +192,7 @@ impl Board {
rect.x2,
rect.y2,
layer,
net,
net_id,
Some(component_id),
Some(pin_id),
!place_side_is_front,
@ -208,7 +208,7 @@ impl Board {
&path.coords,
path.width,
layer,
net,
net_id,
Some(component_id),
Some(pin_id),
!place_side_is_front,
@ -224,7 +224,7 @@ impl Board {
&polygon.coords,
polygon.width,
layer,
net,
net_id,
Some(component_id),
Some(pin_id),
!place_side_is_front,