diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 90a906a..94a2af0 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -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 Step, Option, AutorouteContinu } } +impl Abort> for AutorouteExecutionStepper { + fn abort(&mut self, autorouter: &mut Autorouter) { + 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; diff --git a/src/autorouter/execution.rs b/src/autorouter/execution.rs index 61ae470..fa4a3dd 100644 --- a/src/autorouter/execution.rs +++ b/src/autorouter/execution.rs @@ -158,10 +158,11 @@ impl Abort> for ExecutionStepper { // 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(), } } } diff --git a/src/stepper.rs b/src/stepper.rs index ac4b44c..6f9dba7 100644 --- a/src/stepper.rs +++ b/src/stepper.rs @@ -39,21 +39,21 @@ pub trait Step { } /// Steppers that may be stepped backwards implement this trait. -pub trait StepBack { +pub trait StepBack { /// Retreat the stepper's state by one step. - fn step_back(&mut self, context: &mut C) -> Result; + fn step_back(&mut self, context: &mut Ctx) -> Result; } /// 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 { +/// 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 { /// 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?