mirror of https://codeberg.org/topola/topola.git
stepper: add `Abort` trait to abort steppers
This commit is contained in:
parent
5448474857
commit
e08a59cd74
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex},
|
||||
geometry::primitive::PrimitiveShape,
|
||||
router::{navmesh::Navmesh, route::RouteStepper, trace::TraceStepper, Router, RouterStatus},
|
||||
step::Step,
|
||||
stepper::Step,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, step::Step};
|
||||
use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, stepper::Step};
|
||||
|
||||
use super::{
|
||||
autoroute::{AutorouteExecutionStepper, AutorouteStatus},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
geometry::{primitive::PrimitiveShape, shape::MeasureLength},
|
||||
graph::MakeRef,
|
||||
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||
step::Step,
|
||||
stepper::Step,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
drawing::graph::PrimitiveIndex,
|
||||
geometry::primitive::PrimitiveShape,
|
||||
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||
step::Step,
|
||||
stepper::Step,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use topola::{
|
|||
geometry::primitive::PrimitiveShape,
|
||||
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||
specctra::mesadata::SpecctraMesadata,
|
||||
step::Step,
|
||||
stepper::{Abort, Step},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -57,16 +57,24 @@ impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()> for Acti
|
|||
invoker: &mut Invoker<SpecctraMesadata>,
|
||||
) -> Result<ActivityStatus, ActivityError> {
|
||||
match self {
|
||||
ActivityStepper::Execution(execute) => Ok(execute.step(invoker)?.into()),
|
||||
ActivityStepper::Execution(execution) => Ok(execution.step(invoker)?.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Abort<Invoker<SpecctraMesadata>> for ActivityStepper {
|
||||
fn abort(&mut self, invoker: &mut Invoker<SpecctraMesadata>) {
|
||||
match self {
|
||||
ActivityStepper::Execution(execution) => execution.finish(invoker), // TODO.
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for ActivityStepper {
|
||||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
match self {
|
||||
ActivityStepper::Execution(execute) => execute.maybe_navmesh(),
|
||||
ActivityStepper::Execution(execution) => execution.maybe_navmesh(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +83,7 @@ impl GetMaybeTrace for ActivityStepper {
|
|||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||
fn maybe_trace(&self) -> Option<&TraceStepper> {
|
||||
match self {
|
||||
ActivityStepper::Execution(execute) => execute.maybe_trace(),
|
||||
ActivityStepper::Execution(execution) => execution.maybe_trace(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +92,7 @@ impl GetGhosts for ActivityStepper {
|
|||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||
fn ghosts(&self) -> &[PrimitiveShape] {
|
||||
match self {
|
||||
ActivityStepper::Execution(execute) => execute.ghosts(),
|
||||
ActivityStepper::Execution(execution) => execution.ghosts(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +101,7 @@ impl GetObstacles for ActivityStepper {
|
|||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||
fn obstacles(&self) -> &[PrimitiveIndex] {
|
||||
match self {
|
||||
ActivityStepper::Execution(execute) => execute.obstacles(),
|
||||
ActivityStepper::Execution(execution) => execution.obstacles(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,9 +112,9 @@ pub struct ActivityWithStatus {
|
|||
}
|
||||
|
||||
impl ActivityWithStatus {
|
||||
pub fn new_execute(execute: ExecutionStepper) -> ActivityWithStatus {
|
||||
pub fn new_execution(execution: ExecutionStepper) -> ActivityWithStatus {
|
||||
Self {
|
||||
activity: ActivityStepper::Execution(execute),
|
||||
activity: ActivityStepper::Execution(execution),
|
||||
maybe_status: None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ impl MenuBar {
|
|||
) {
|
||||
let selection = overlay.selection().clone();
|
||||
overlay.clear_selection();
|
||||
maybe_activity.insert(ActivityWithStatus::new_execute(
|
||||
maybe_activity.insert(ActivityWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::Autoroute(
|
||||
selection.pin_selection,
|
||||
self.autorouter_options,
|
||||
|
|
@ -319,7 +319,7 @@ impl MenuBar {
|
|||
) {
|
||||
let selection = overlay.selection().clone();
|
||||
overlay.clear_selection();
|
||||
maybe_activity.insert(ActivityWithStatus::new_execute(
|
||||
maybe_activity.insert(ActivityWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::RemoveBands(
|
||||
selection.band_selection,
|
||||
))?,
|
||||
|
|
@ -336,7 +336,7 @@ impl MenuBar {
|
|||
) {
|
||||
let selection = overlay.selection().clone();
|
||||
overlay.clear_selection();
|
||||
maybe_activity.insert(ActivityWithStatus::new_execute(
|
||||
maybe_activity.insert(ActivityWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::MeasureLength(
|
||||
selection.band_selection,
|
||||
))?,
|
||||
|
|
@ -361,7 +361,7 @@ impl MenuBar {
|
|||
) {
|
||||
let selection = overlay.selection().clone();
|
||||
overlay.clear_selection();
|
||||
maybe_activity.insert(ActivityWithStatus::new_execute(
|
||||
maybe_activity.insert(ActivityWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::CompareDetours(
|
||||
selection.pin_selection,
|
||||
self.autorouter_options,
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
pub struct RouteInteractionStepper {
|
||||
route: RouteStepper,
|
||||
options: RouterOptions,
|
||||
}
|
||||
10
src/lib.rs
10
src/lib.rs
|
|
@ -1,5 +1,9 @@
|
|||
#![doc(html_favicon_url = "https://codeberg.org/topola/topola/raw/commit/e1b56875edf039aab9f41868826bcd3a92097133/assets/favicon.ico")]
|
||||
#![doc(html_logo_url = "https://codeberg.org/topola/topola/raw/commit/e1b56875edf039aab9f41868826bcd3a92097133/assets/logo.svg")]
|
||||
#![doc(
|
||||
html_favicon_url = "https://codeberg.org/topola/topola/raw/commit/e1b56875edf039aab9f41868826bcd3a92097133/assets/favicon.ico"
|
||||
)]
|
||||
#![doc(
|
||||
html_logo_url = "https://codeberg.org/topola/topola/raw/commit/e1b56875edf039aab9f41868826bcd3a92097133/assets/logo.svg"
|
||||
)]
|
||||
#![cfg_attr(not(feature = "disable_contracts"), feature(try_blocks))]
|
||||
|
||||
pub mod graph;
|
||||
|
|
@ -12,5 +16,5 @@ pub mod layout;
|
|||
pub mod math;
|
||||
pub mod router;
|
||||
pub mod specctra;
|
||||
pub mod step;
|
||||
pub mod stepper;
|
||||
pub mod triangulation;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use thiserror::Error;
|
|||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use crate::step::Step;
|
||||
use crate::stepper::Step;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct MinScored<K, T>(pub K, pub T);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
tracer::Tracer,
|
||||
Router, RouterAstarStrategy, RouterError, RouterStatus,
|
||||
},
|
||||
step::Step,
|
||||
stepper::Step,
|
||||
};
|
||||
|
||||
pub struct RouteStepper {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use crate::{
|
|||
},
|
||||
graph::{GetPetgraphIndex, MakeRef},
|
||||
layout::Layout,
|
||||
step::{Step, StepBack},
|
||||
stepper::{Step, StepBack},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
head::{BareHead, CaneHead, Head},
|
||||
rules::AccessRules,
|
||||
},
|
||||
step::{Step, StepBack},
|
||||
stepper::{Step, StepBack},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
@ -129,9 +129,7 @@ impl<'a, 'b, R: AccessRules> Step<TraceStepContext<'a, 'b, R>, TracerStatus, Tra
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, R: AccessRules> StepBack<Tracer<'a, R>, TracerStatus, TracerException, ()>
|
||||
for TraceStepper
|
||||
{
|
||||
impl<'a, R: AccessRules> StepBack<Tracer<'a, R>, TracerStatus, TracerException> for TraceStepper {
|
||||
#[debug_ensures(self.path.len() == old(self.path.len() - 1))]
|
||||
fn step_back(&mut self, tracer: &mut Tracer<'a, R>) -> Result<TracerStatus, TracerException> {
|
||||
if let Head::Cane(head) = self.head {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use thiserror::Error;
|
|||
use crate::{
|
||||
drawing::{band::BandTermsegIndex, dot::FixedDotIndex, rules::AccessRules},
|
||||
layout::Layout,
|
||||
step::{Step, StepBack},
|
||||
stepper::{Step, StepBack},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ pub trait Step<C, S: TryInto<O>, E, O> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait StepBack<C, S: TryInto<O>, E, O> {
|
||||
pub trait StepBack<C, S, E> {
|
||||
fn step_back(&mut self, context: &mut C) -> Result<S, E>;
|
||||
}
|
||||
|
||||
pub trait Abort<C> {
|
||||
fn abort(&mut self, context: &mut C);
|
||||
}
|
||||
Loading…
Reference in New Issue