diff --git a/topola/src/board/interactors/drag_move.rs b/topola/src/board/interactors/drag_move.rs index 0467508..0358909 100644 --- a/topola/src/board/interactors/drag_move.rs +++ b/topola/src/board/interactors/drag_move.rs @@ -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) { 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) { self.hold(board, pointer); } diff --git a/topola/src/board/interactors/drag_select.rs b/topola/src/board/interactors/drag_select.rs index 9c9382d..47d1a45 100644 --- a/topola/src/board/interactors/drag_select.rs +++ b/topola/src/board/interactors/drag_select.rs @@ -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) { 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(); + } } diff --git a/topola/src/board/mod.rs b/topola/src/board/mod.rs index 5d2d077..1531802 100644 --- a/topola/src/board/mod.rs +++ b/topola/src/board/mod.rs @@ -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) -> 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 diff --git a/topola/src/layout/compounds/net.rs b/topola/src/layout/compounds/net.rs index 61d7778..ca8d410 100644 --- a/topola/src/layout/compounds/net.rs +++ b/topola/src/layout/compounds/net.rs @@ -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, +} + +impl Net { + pub fn new() -> Self { + Default::default() + } +} diff --git a/topola/src/layout/compounds/pin.rs b/topola/src/layout/compounds/pin.rs index 6ae1e8e..f6d5872 100644 --- a/topola/src/layout/compounds/pin.rs +++ b/topola/src/layout/compounds/pin.rs @@ -30,7 +30,7 @@ impl PinId { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Pin { pub joints: Vec, pub segments: Vec, @@ -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() } } diff --git a/topola/src/layout/insert.rs b/topola/src/layout/insert.rs index 0167ae2..9e65ebe 100644 --- a/topola/src/layout/insert.rs +++ b/topola/src/layout/insert.rs @@ -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) -> 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 { diff --git a/topola/src/layout/mod.rs b/topola/src/layout/mod.rs index c9a6235..5b6a8df 100644 --- a/topola/src/layout/mod.rs +++ b/topola/src/layout/mod.rs @@ -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>, + nets: Recorder>, pins: Recorder>, joints: Recorder>, @@ -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()), diff --git a/topola/src/specctra.rs b/topola/src/specctra.rs index 2a003a0..da7de80 100644 --- a/topola/src/specctra.rs +++ b/topola/src/specctra.rs @@ -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,