mirror of https://codeberg.org/topola/topola.git
fix(board/edit): Proper undo/redo of band creation
This commit is contained in:
parent
1bbb068af9
commit
d0417926f5
|
|
@ -4,11 +4,15 @@
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::{board::BandName, drawing::band::BandUid, geometry::edit::Edit, layout::LayoutEdit};
|
use crate::{
|
||||||
|
board::BandName, drawing::band::BandUid, geometry::edit::Edit, layout::LayoutEdit,
|
||||||
|
router::ng::EtchedPath,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct BoardDataEdit {
|
pub struct BoardDataEdit {
|
||||||
pub(super) bands: BTreeMap<BandName, (Option<BandUid>, Option<BandUid>)>,
|
pub(super) bands_by_id: BTreeMap<EtchedPath, (Option<BandUid>, Option<BandUid>)>,
|
||||||
|
pub(super) bands_by_name: BTreeMap<BandName, (Option<BandUid>, Option<BandUid>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BoardDataEdit {
|
impl BoardDataEdit {
|
||||||
|
|
@ -19,11 +23,13 @@ impl BoardDataEdit {
|
||||||
|
|
||||||
impl Edit for BoardDataEdit {
|
impl Edit for BoardDataEdit {
|
||||||
fn reverse_inplace(&mut self) {
|
fn reverse_inplace(&mut self) {
|
||||||
self.bands.reverse_inplace();
|
self.bands_by_id.reverse_inplace();
|
||||||
|
self.bands_by_name.reverse_inplace();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge(&mut self, edit: Self) {
|
fn merge(&mut self, edit: Self) {
|
||||||
self.bands.merge(edit.bands);
|
self.bands_by_id.merge(edit.bands_by_id);
|
||||||
|
self.bands_by_name.merge(edit.bands_by_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,10 +262,13 @@ impl<M: AccessMesadata> Board<M> {
|
||||||
let ep = EtchedPath {
|
let ep = EtchedPath {
|
||||||
end_points: (source, target).into(),
|
end_points: (source, target).into(),
|
||||||
};
|
};
|
||||||
self.bands_by_id.insert(ep, band);
|
|
||||||
self.band_bandname.insert(band, bandname.clone());
|
|
||||||
|
|
||||||
recorder.bands.insert(bandname, (None, Some(band)));
|
self.bands_by_id.insert(ep, band);
|
||||||
|
recorder.bands_by_id.insert(ep, (None, Some(band)));
|
||||||
|
|
||||||
|
self.band_bandname.insert(band, bandname.clone());
|
||||||
|
recorder.bands_by_name.insert(bandname, (None, Some(band)));
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -310,12 +313,19 @@ impl<M: AccessMesadata> Board<M> {
|
||||||
if let Some((_, uid)) = self.bands_by_id.remove_by_left(&ep) {
|
if let Some((_, uid)) = self.bands_by_id.remove_by_left(&ep) {
|
||||||
let (from, _) = uid.into();
|
let (from, _) = uid.into();
|
||||||
self.layout.remove_band(&mut recorder.layout_edit, from)?;
|
self.layout.remove_band(&mut recorder.layout_edit, from)?;
|
||||||
|
|
||||||
|
recorder
|
||||||
|
.board_data_edit
|
||||||
|
.bands_by_id
|
||||||
|
.insert(ep, (Some(uid), None));
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder
|
if let Some(uid) = maybe_band {
|
||||||
.board_data_edit
|
recorder
|
||||||
.bands
|
.board_data_edit
|
||||||
.insert(bandname, (maybe_band, None));
|
.bands_by_name
|
||||||
|
.insert(bandname, (Some(uid), None));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -346,19 +356,31 @@ impl<M: AccessMesadata> Board<M> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_edit(&mut self, edit: &BoardEdit) {
|
pub fn apply_edit(&mut self, edit: &BoardEdit) {
|
||||||
for (bandname, (maybe_old_band_uid, ..)) in &edit.board_data_edit.bands {
|
for (bandname, (maybe_old_band_uid, _)) in &edit.board_data_edit.bands_by_name {
|
||||||
if maybe_old_band_uid.is_some() {
|
if maybe_old_band_uid.is_some() {
|
||||||
self.band_bandname.remove_by_right(bandname);
|
self.band_bandname.remove_by_right(bandname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ep, (maybe_old_band_uid, _)) in &edit.board_data_edit.bands_by_id {
|
||||||
|
if maybe_old_band_uid.is_some() {
|
||||||
|
self.bands_by_id.remove_by_left(ep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.layout_mut().apply(&edit.layout_edit);
|
self.layout_mut().apply(&edit.layout_edit);
|
||||||
|
|
||||||
for (bandname, (.., maybe_new_band_uid)) in &edit.board_data_edit.bands {
|
for (bandname, (_, maybe_new_band_uid)) in &edit.board_data_edit.bands_by_name {
|
||||||
if let Some(band_uid) = maybe_new_band_uid {
|
if let Some(band_uid) = maybe_new_band_uid {
|
||||||
self.band_bandname.insert(*band_uid, bandname.clone());
|
self.band_bandname.insert(*band_uid, bandname.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ep, (_, maybe_new_band_uid)) in &edit.board_data_edit.bands_by_id {
|
||||||
|
if let Some(band_uid) = maybe_new_band_uid {
|
||||||
|
self.bands_by_id.insert(*ep, *band_uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the mesadata associated with the layout's drawing rules.
|
/// Returns the mesadata associated with the layout's drawing rules.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue