From 459c4b41eea7223e2df17e92f2dbc60f7c2fcf7f Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 20 May 2026 14:07:05 +0200 Subject: [PATCH] Add interfaces to move components --- topola/src/board/mod.rs | 2 ++ topola/src/board/resolve.rs | 19 ++++++++++++++++ topola/src/board/transforms/mod.rs | 5 +++++ topola/src/board/transforms/move_by.rs | 23 ++++++++++++++++++++ topola/src/layout/mod.rs | 9 ++++---- topola/src/layout/transforms/mod.rs | 5 +++++ topola/src/layout/transforms/move_by.rs | 29 +++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 topola/src/board/resolve.rs create mode 100644 topola/src/board/transforms/mod.rs create mode 100644 topola/src/board/transforms/move_by.rs create mode 100644 topola/src/layout/transforms/mod.rs create mode 100644 topola/src/layout/transforms/move_by.rs diff --git a/topola/src/board/mod.rs b/topola/src/board/mod.rs index 402563a..89995e1 100644 --- a/topola/src/board/mod.rs +++ b/topola/src/board/mod.rs @@ -2,8 +2,10 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 +mod resolve; mod select; pub mod selections; +mod transforms; use bimap::BiBTreeMap; use derive_getters::{Dissolve, Getters}; diff --git a/topola/src/board/resolve.rs b/topola/src/board/resolve.rs new file mode 100644 index 0000000..417c199 --- /dev/null +++ b/topola/src/board/resolve.rs @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{ + board::{Board, selections::ComponentSelection}, + compounds::ComponentId, +}; + +impl Board { + pub fn resolve_components(&self, selection: ComponentSelection) -> Vec { + selection + .0 + .clone() + .into_iter() + .filter_map(|selector| self.component_id(&selector.component)) + .collect() + } +} diff --git a/topola/src/board/transforms/mod.rs b/topola/src/board/transforms/mod.rs new file mode 100644 index 0000000..3253d71 --- /dev/null +++ b/topola/src/board/transforms/mod.rs @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +mod move_by; diff --git a/topola/src/board/transforms/move_by.rs b/topola/src/board/transforms/move_by.rs new file mode 100644 index 0000000..4f10a72 --- /dev/null +++ b/topola/src/board/transforms/move_by.rs @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{Board, Vector2, compounds::ComponentId, selections::ComponentSelection}; + +impl Board { + pub fn move_components_by( + &mut self, + selection: &ComponentSelection, + translation: Vector2, + ) { + self.move_resolved_components_by(&self.resolve_components(selection.clone()), translation); + } + + pub fn move_resolved_components_by( + &mut self, + selection: &[ComponentId], + translation: Vector2, + ) { + self.layout.move_components_by(selection, translation); + } +} diff --git a/topola/src/layout/mod.rs b/topola/src/layout/mod.rs index ae0398a..90bd3c7 100644 --- a/topola/src/layout/mod.rs +++ b/topola/src/layout/mod.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 pub mod primitives; +mod transforms; use derive_getters::Getters; use rstar::{ @@ -122,12 +123,12 @@ impl Layout { self.modify_joint_raw(id, |joint| f(&mut joint.spec)); let new_joint = self.joints[id.index()].clone(); - for &segment in &new_joint.segments { - self.update_segment(segment); + for &segment_id in &new_joint.segments { + self.update_segment(segment_id); } - for &via in &new_joint.vias { - self.update_via(via); + for &via_id in &new_joint.vias { + self.update_via(via_id); } } diff --git a/topola/src/layout/transforms/mod.rs b/topola/src/layout/transforms/mod.rs new file mode 100644 index 0000000..3253d71 --- /dev/null +++ b/topola/src/layout/transforms/mod.rs @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +mod move_by; diff --git a/topola/src/layout/transforms/move_by.rs b/topola/src/layout/transforms/move_by.rs new file mode 100644 index 0000000..fe68549 --- /dev/null +++ b/topola/src/layout/transforms/move_by.rs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2026 Topola contributors +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use crate::{Layout, compounds::ComponentId, math::Vector2}; + +impl Layout { + pub fn move_component_by(&mut self, id: ComponentId, translation: Vector2) { + self.move_components_by(&[id], translation); + } + + pub fn move_components_by(&mut self, ids: &[ComponentId], translation: Vector2) { + for id in ids { + let component = self.components[id.index()].clone(); + + for &joint_id in &component.joints { + self.modify_joint_raw(joint_id, |joint| joint.spec.position += translation); + } + + for &segment_id in &component.segments { + self.update_segment(segment_id); + } + + for &via_id in &component.vias { + self.update_via(via_id); + } + } + } +}