mirror of https://codeberg.org/topola/topola.git
Add interfaces to move components
This commit is contained in:
parent
24af694c6b
commit
459c4b41ee
|
|
@ -2,8 +2,10 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
mod resolve;
|
||||||
mod select;
|
mod select;
|
||||||
pub mod selections;
|
pub mod selections;
|
||||||
|
mod transforms;
|
||||||
|
|
||||||
use bimap::BiBTreeMap;
|
use bimap::BiBTreeMap;
|
||||||
use derive_getters::{Dissolve, Getters};
|
use derive_getters::{Dissolve, Getters};
|
||||||
|
|
|
||||||
|
|
@ -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<ComponentId> {
|
||||||
|
selection
|
||||||
|
.0
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|selector| self.component_id(&selector.component))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Topola contributors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
mod move_by;
|
||||||
|
|
@ -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<i64>,
|
||||||
|
) {
|
||||||
|
self.move_resolved_components_by(&self.resolve_components(selection.clone()), translation);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn move_resolved_components_by(
|
||||||
|
&mut self,
|
||||||
|
selection: &[ComponentId],
|
||||||
|
translation: Vector2<i64>,
|
||||||
|
) {
|
||||||
|
self.layout.move_components_by(selection, translation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
pub mod primitives;
|
pub mod primitives;
|
||||||
|
mod transforms;
|
||||||
|
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use rstar::{
|
use rstar::{
|
||||||
|
|
@ -122,12 +123,12 @@ impl Layout {
|
||||||
self.modify_joint_raw(id, |joint| f(&mut joint.spec));
|
self.modify_joint_raw(id, |joint| f(&mut joint.spec));
|
||||||
let new_joint = self.joints[id.index()].clone();
|
let new_joint = self.joints[id.index()].clone();
|
||||||
|
|
||||||
for &segment in &new_joint.segments {
|
for &segment_id in &new_joint.segments {
|
||||||
self.update_segment(segment);
|
self.update_segment(segment_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for &via in &new_joint.vias {
|
for &via_id in &new_joint.vias {
|
||||||
self.update_via(via);
|
self.update_via(via_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Topola contributors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
|
mod move_by;
|
||||||
|
|
@ -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<i64>) {
|
||||||
|
self.move_components_by(&[id], translation);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn move_components_by(&mut self, ids: &[ComponentId], translation: Vector2<i64>) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue