autorouter: fix redo operation

Redone operation was only dispatched, not truly executed.
This commit is contained in:
Mikolaj Wielgus 2024-06-25 11:16:10 +02:00
parent 514eab683a
commit 3ce8cfcabc
4 changed files with 13 additions and 18 deletions

View File

@ -46,11 +46,11 @@ impl Execute {
match self.step_catch_err(invoker) { match self.step_catch_err(invoker) {
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running), Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),
Ok(InvokerStatus::Finished) => { Ok(InvokerStatus::Finished) => {
invoker.history.do_(invoker.ongoing.take().unwrap()); invoker.history.do_(invoker.ongoing_command.take().unwrap());
Ok(InvokerStatus::Finished) Ok(InvokerStatus::Finished)
} }
Err(err) => { Err(err) => {
invoker.ongoing = None; invoker.ongoing_command = None;
Err(err) Err(err)
} }
} }
@ -76,7 +76,7 @@ impl Execute {
pub struct Invoker<M: MesadataTrait> { pub struct Invoker<M: MesadataTrait> {
autorouter: Autorouter<M>, autorouter: Autorouter<M>,
history: History, history: History,
ongoing: Option<Command>, ongoing_command: Option<Command>,
} }
impl<M: MesadataTrait> Invoker<M> { impl<M: MesadataTrait> Invoker<M> {
@ -88,15 +88,15 @@ impl<M: MesadataTrait> Invoker<M> {
Self { Self {
autorouter, autorouter,
history, history,
ongoing: None, ongoing_command: None,
} }
} }
pub fn destruct(self) -> (Autorouter<M>, History, Option<Command>) { pub fn destruct(self) -> (Autorouter<M>, History, Option<Command>) {
(self.autorouter, self.history, self.ongoing) (self.autorouter, self.history, self.ongoing_command)
} }
#[debug_requires(self.ongoing.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn execute(&mut self, command: Command) -> Result<(), InvokerError> { pub fn execute(&mut self, command: Command) -> Result<(), InvokerError> {
let mut execute = self.execute_walk(command); let mut execute = self.execute_walk(command);
@ -113,14 +113,14 @@ impl<M: MesadataTrait> Invoker<M> {
} }
} }
#[debug_requires(self.ongoing.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn execute_walk(&mut self, command: Command) -> Execute { pub fn execute_walk(&mut self, command: Command) -> Execute {
let execute = self.dispatch_command(&command); let execute = self.dispatch_command(&command);
self.ongoing = Some(command); self.ongoing_command = Some(command);
execute execute
} }
#[debug_requires(self.ongoing.is_none())] #[debug_requires(self.ongoing_command.is_none())]
fn dispatch_command(&mut self, command: &Command) -> Execute { fn dispatch_command(&mut self, command: &Command) -> Execute {
match command { match command {
Command::Autoroute(selection) => { Command::Autoroute(selection) => {
@ -132,7 +132,7 @@ impl<M: MesadataTrait> Invoker<M> {
} }
} }
#[debug_requires(self.ongoing.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn undo(&mut self) -> Result<(), InvokerError> { pub fn undo(&mut self) -> Result<(), InvokerError> {
let command = self.history.last_done()?; let command = self.history.last_done()?;
@ -147,7 +147,7 @@ impl<M: MesadataTrait> Invoker<M> {
//#[debug_requires(self.ongoing.is_none())] //#[debug_requires(self.ongoing.is_none())]
pub fn redo(&mut self) -> Result<(), InvokerError> { pub fn redo(&mut self) -> Result<(), InvokerError> {
let command = self.history.last_undone()?.clone(); let command = self.history.last_undone()?.clone();
let mut execute = self.dispatch_command(&command); let mut execute = self.execute_walk(command);
loop { loop {
let status = match execute.step(self) { let status = match execute.step(self) {
@ -161,7 +161,7 @@ impl<M: MesadataTrait> Invoker<M> {
} }
} }
#[debug_requires(self.ongoing.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn replay(&mut self, history: History) { pub fn replay(&mut self, history: History) {
let (done, undone) = history.destructure(); let (done, undone) = history.destructure();

View File

@ -172,7 +172,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
#[debug_ensures(trace.path.len() == old(trace.path.len() - 1))] #[debug_ensures(trace.path.len() == old(trace.path.len() - 1))]
pub fn undo_step(&mut self, graph: &UnGraph<NavvertexWeight, (), usize>, trace: &mut Trace) { pub fn undo_step(&mut self, graph: &UnGraph<NavvertexWeight, (), usize>, trace: &mut Trace) {
if let Head::Cane(head) = dbg!(trace.head) { if let Head::Cane(head) = trace.head {
trace.head = Draw::new(self.layout).undo_cane(head).unwrap(); trace.head = Draw::new(self.layout).undo_cane(head).unwrap();
} else { } else {
panic!(); panic!();

View File

@ -89,7 +89,6 @@ pub fn assert_single_layer_groundless_autoroute(
.rules() .rules()
.layer_layername(target_layer), .layer_layername(target_layer),
) { ) {
dbg!(source_layername, target_layername);
assert_eq!(source_layername, target_layername); assert_eq!(source_layername, target_layername);
if source_layername != layername { if source_layername != layername {
@ -111,7 +110,6 @@ pub fn assert_single_layer_groundless_autoroute(
.drawing() .drawing()
.primitive(target_dot) .primitive(target_dot)
.maybe_net(); .maybe_net();
dbg!(source_net, target_net);
assert_eq!(source_net, target_net); assert_eq!(source_net, target_net);
let net = source_net.unwrap(); let net = source_net.unwrap();
@ -119,7 +117,6 @@ pub fn assert_single_layer_groundless_autoroute(
if let Some(netname) = autorouter.board().layout().rules().net_netname(net) { if let Some(netname) = autorouter.board().layout().rules().net_netname(net) {
// We don't route ground. // We don't route ground.
if netname != "GND" { if netname != "GND" {
dbg!(source_dot, target_dot);
assert_eq!( assert_eq!(
unionfind.find(source_dot.petgraph_index()), unionfind.find(source_dot.petgraph_index()),
unionfind.find(target_dot.petgraph_index()) unionfind.find(target_dot.petgraph_index())
@ -150,7 +147,6 @@ pub fn assert_band_length(
) { ) {
let band = board.band_between_pins(source, target).unwrap(); let band = board.band_between_pins(source, target).unwrap();
let band_length = board.layout().band_length(band); let band_length = board.layout().band_length(band);
dbg!(band_length);
assert!((band_length - length).abs() < epsilon); assert!((band_length - length).abs() < epsilon);
} }

View File

@ -25,7 +25,6 @@ fn test_unrouted_lm317_breakout() {
}, },
maybe_net: Some(1234), maybe_net: Some(1234),
})); }));
let result = dbg!(result);
assert!(matches!( assert!(matches!(
result, result,
Err(InvokerError::Autorouter(AutorouterError::CouldNotPlaceVia( Err(InvokerError::Autorouter(AutorouterError::CouldNotPlaceVia(