mirror of https://codeberg.org/topola/topola.git
Apply `derive(Delta)` on `Board` instead of manually implementing
This commit is contained in:
parent
459c4b41ee
commit
c525af7fca
|
|
@ -12,7 +12,7 @@ derive-getters = "0.5"
|
||||||
derive_more = { version = "2.1", features = ["full"] }
|
derive_more = { version = "2.1", features = ["full"] }
|
||||||
serde = { version = "1", features = ["derive", "rc"] }
|
serde = { version = "1", features = ["derive", "rc"] }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
undoredo = { version = "0.10", features = ["derive", "stable-vec", "rstar"] }
|
undoredo = { version = "0.10", features = ["derive", "bidimap", "stable-vec", "rstar"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 2 # Fast and small WASM.
|
opt-level = 2 # Fast and small WASM.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bimap = "0.6"
|
bidimap = "0.7"
|
||||||
dearcut = { version = "0.3", features = ["serde", "undoredo"] }
|
dearcut = { version = "0.3", features = ["serde", "undoredo"] }
|
||||||
derive-getters.workspace = true
|
derive-getters.workspace = true
|
||||||
derive_more.workspace = true
|
derive_more.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ mod select;
|
||||||
pub mod selections;
|
pub mod selections;
|
||||||
mod transforms;
|
mod transforms;
|
||||||
|
|
||||||
use bimap::BiBTreeMap;
|
use bidimap::BiBTreeMap;
|
||||||
use derive_getters::{Dissolve, Getters};
|
use derive_getters::Getters;
|
||||||
use undoredo::{ApplyDelta, Delta, FlushDelta};
|
use undoredo::{Delta, Recorder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
compounds::{ComponentId, NetId, PinId},
|
compounds::{ComponentId, NetId, PinId},
|
||||||
|
|
@ -23,27 +23,27 @@ use crate::{
|
||||||
math::Vector2,
|
math::Vector2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Getters)]
|
#[derive(Clone, Debug, Getters, Delta)]
|
||||||
pub struct Board {
|
pub struct Board {
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
#[getter(skip)]
|
#[getter(skip)]
|
||||||
component_names: BiBTreeMap<ComponentId, String>,
|
component_names: Recorder<BiBTreeMap<ComponentId, String>>,
|
||||||
#[getter(skip)]
|
#[getter(skip)]
|
||||||
pin_names: BiBTreeMap<PinId, String>,
|
pin_names: Recorder<BiBTreeMap<PinId, String>>,
|
||||||
#[getter(skip)]
|
#[getter(skip)]
|
||||||
layer_names: BiBTreeMap<usize, String>,
|
layer_names: Recorder<BiBTreeMap<usize, String>>,
|
||||||
#[getter(skip)]
|
#[getter(skip)]
|
||||||
net_names: BiBTreeMap<NetId, String>,
|
net_names: Recorder<BiBTreeMap<NetId, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
pub fn new(boundary: Vec<Vector2<i64>>, layer_count: usize) -> Self {
|
pub fn new(boundary: Vec<Vector2<i64>>, layer_count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count),
|
layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count),
|
||||||
component_names: BiBTreeMap::new(),
|
component_names: Recorder::new(BiBTreeMap::new()),
|
||||||
pin_names: BiBTreeMap::new(),
|
pin_names: Recorder::new(BiBTreeMap::new()),
|
||||||
layer_names: BiBTreeMap::new(),
|
layer_names: Recorder::new(BiBTreeMap::new()),
|
||||||
net_names: BiBTreeMap::new(),
|
net_names: Recorder::new(BiBTreeMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,10 +55,10 @@ impl Board {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count),
|
layout: Layout::new(boundary.into_iter().map(Into::into).collect(), layer_count),
|
||||||
component_names: BiBTreeMap::new(),
|
component_names: Recorder::new(BiBTreeMap::new()),
|
||||||
pin_names: BiBTreeMap::new(),
|
pin_names: Recorder::new(BiBTreeMap::new()),
|
||||||
layer_names,
|
layer_names: Recorder::new(layer_names),
|
||||||
net_names,
|
net_names: Recorder::new(net_names),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +117,10 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn component_id(&self, component_name: &str) -> Option<ComponentId> {
|
pub fn component_id(&self, component_name: &str) -> Option<ComponentId> {
|
||||||
self.component_names.get_by_right(component_name).copied()
|
self.component_names
|
||||||
|
.as_ref()
|
||||||
|
.get_by_right(component_name)
|
||||||
|
.copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pin_name(&self, id: PinId) -> Option<&str> {
|
pub fn pin_name(&self, id: PinId) -> Option<&str> {
|
||||||
|
|
@ -125,7 +128,7 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pin_id(&self, pin_name: &str) -> Option<PinId> {
|
pub fn pin_id(&self, pin_name: &str) -> Option<PinId> {
|
||||||
self.pin_names.get_by_right(pin_name).copied()
|
self.pin_names.as_ref().get_by_right(pin_name).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layer_name(&self, layer: usize) -> Option<&str> {
|
pub fn layer_name(&self, layer: usize) -> Option<&str> {
|
||||||
|
|
@ -133,7 +136,7 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layer_id(&self, layer_name: &str) -> Option<usize> {
|
pub fn layer_id(&self, layer_name: &str) -> Option<usize> {
|
||||||
self.layer_names.get_by_right(layer_name).copied()
|
self.layer_names.as_ref().get_by_right(layer_name).copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn net_name(&self, id: NetId) -> Option<&str> {
|
pub fn net_name(&self, id: NetId) -> Option<&str> {
|
||||||
|
|
@ -141,35 +144,6 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn net_id(&self, net_name: &str) -> Option<NetId> {
|
pub fn net_id(&self, net_name: &str) -> Option<NetId> {
|
||||||
self.net_names.get_by_right(net_name).copied()
|
self.net_names.as_ref().get_by_right(net_name).copied()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Dissolve)]
|
|
||||||
pub struct BoardHalfDelta {
|
|
||||||
layout: LayoutHalfDelta,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ApplyDelta<BoardHalfDelta> for Board {
|
|
||||||
fn apply_delta(&mut self, delta: Delta<BoardHalfDelta>) {
|
|
||||||
let (removed, inserted) = delta.dissolve();
|
|
||||||
|
|
||||||
let layout_delta = Delta::with_removed_inserted(removed.layout, inserted.layout);
|
|
||||||
self.layout.apply_delta(layout_delta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlushDelta<BoardHalfDelta> for Board {
|
|
||||||
fn flush_delta(&mut self) -> Delta<BoardHalfDelta> {
|
|
||||||
let (removed_layout, inserted_layout) = self.layout.flush_delta().dissolve();
|
|
||||||
|
|
||||||
Delta::with_removed_inserted(
|
|
||||||
BoardHalfDelta {
|
|
||||||
layout: removed_layout,
|
|
||||||
},
|
|
||||||
BoardHalfDelta {
|
|
||||||
layout: inserted_layout,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use bimap::BiBTreeMap;
|
use bidimap::BiBTreeMap;
|
||||||
use specctra::{
|
use specctra::{
|
||||||
math::PointWithRotation,
|
math::PointWithRotation,
|
||||||
structure::{DsnFile, Layer, Point, Shape},
|
structure::{DsnFile, Layer, Point, Shape},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue