feat(autorouter/autoroute): Make it possible to abort autoroute stepper

Aborting the autoroute stepper was unimplemented and it would make the
autorouting job finish instead. This is fixed now.
This commit is contained in:
Mikolaj Wielgus 2025-07-13 00:55:27 +02:00
parent 2f4dac223c
commit 1cc75a79e8
3 changed files with 23 additions and 13 deletions

View File

@ -10,13 +10,13 @@ use std::ops::ControlFlow;
use crate::{
board::AccessMesadata,
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex, Collect},
geometry::primitive::PrimitiveShape,
geometry::{edit::ApplyGeometryEdit, primitive::PrimitiveShape},
graph::MakeRef,
layout::LayoutEdit,
router::{
navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router,
},
stepper::{EstimateProgress, Step},
stepper::{Abort, EstimateProgress, Step},
};
use super::{
@ -165,6 +165,15 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<LayoutEdit>, AutorouteContinu
}
}
impl<M: AccessMesadata> Abort<Autorouter<M>> for AutorouteExecutionStepper {
fn abort(&mut self, autorouter: &mut Autorouter<M>) {
if let Some(ref route) = self.route {
autorouter.board.apply(&route.navcord().recorder.reverse());
self.curr_ratline_index = self.ratlines.len();
}
}
}
impl EstimateProgress for AutorouteExecutionStepper {
type Value = f64;

View File

@ -158,10 +158,11 @@ impl<M: AccessMesadata + Clone> Abort<Invoker<M>> for ExecutionStepper<M> {
// TODO: maintain topo-navmesh just like layout
*invoker.autorouter.board.layout_mut() = autoroute.last_layout.clone();
}
execution => {
// TODO
execution.finish(invoker);
}
ExecutionStepper::Autoroute(autoroute) => autoroute.abort(&mut invoker.autorouter),
ExecutionStepper::PlaceVia(_place_via) => (), //place_via.abort(),
ExecutionStepper::RemoveBands(_remove_bands) => (), //remove_bands.abort(),
ExecutionStepper::CompareDetours(_compare_detours) => (), //compare_detours.abort(),
ExecutionStepper::MeasureLength(_measure_length) => (), //measure_length.abort(),
}
}
}

View File

@ -39,21 +39,21 @@ pub trait Step<Ctx, B, C = ()> {
}
/// Steppers that may be stepped backwards implement this trait.
pub trait StepBack<C, S, E> {
pub trait StepBack<Ctx, S, E> {
/// Retreat the stepper's state by one step.
fn step_back(&mut self, context: &mut C) -> Result<S, E>;
fn step_back(&mut self, context: &mut Ctx) -> Result<S, E>;
}
/// Steppers that may be aborted implement this trait.
///
/// Aborting a stepper puts it in a state where stepping or stepping back always
/// fails.
pub trait Abort<C> {
/// Aborting a stepper puts it and its context back in its initial state, except
/// that from then on trying to step or step back always fails.
pub trait Abort<Ctx> {
/// Abort the stepper.
fn abort(&mut self, context: &mut C);
fn abort(&mut self, context: &mut Ctx);
}
/// Steppers that can receive discrete events and act on them, implement this
/// Steppers that can receive discrete events and act on them implement this
/// trait.
// XXX: Doesn't this violate the rule that stepper's future states are
// determined by its initial state?