terminology: distinguish between "command" and its "execution"

This commit is contained in:
Mikolaj Wielgus 2024-10-01 16:01:11 +02:00
parent cc0bf1845a
commit 5448474857
11 changed files with 205 additions and 98 deletions

View File

@ -30,14 +30,14 @@ impl TryInto<()> for AutorouteStatus {
} }
} }
pub struct AutorouteCommandStepper { pub struct AutorouteExecutionStepper {
ratlines_iter: Box<dyn Iterator<Item = EdgeIndex<usize>>>, ratlines_iter: Box<dyn Iterator<Item = EdgeIndex<usize>>>,
options: AutorouterOptions, options: AutorouterOptions,
route: Option<RouteStepper>, route: Option<RouteStepper>,
curr_ratline: Option<EdgeIndex<usize>>, curr_ratline: Option<EdgeIndex<usize>>,
} }
impl AutorouteCommandStepper { impl AutorouteExecutionStepper {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: impl IntoIterator<Item = EdgeIndex<usize>> + 'static, ratlines: impl IntoIterator<Item = EdgeIndex<usize>> + 'static,
@ -64,7 +64,7 @@ impl AutorouteCommandStepper {
} }
impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, AutorouterError, ()> impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, AutorouterError, ()>
for AutorouteCommandStepper for AutorouteExecutionStepper
{ {
fn step(&mut self, autorouter: &mut Autorouter<M>) -> Result<AutorouteStatus, AutorouterError> { fn step(&mut self, autorouter: &mut Autorouter<M>) -> Result<AutorouteStatus, AutorouterError> {
let Some(curr_ratline) = self.curr_ratline else { let Some(curr_ratline) = self.curr_ratline else {
@ -119,25 +119,25 @@ impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, AutorouterError, ()
} }
} }
impl GetMaybeNavmesh for AutorouteCommandStepper { impl GetMaybeNavmesh for AutorouteExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
self.route.as_ref().map(|route| route.navmesh()) self.route.as_ref().map(|route| route.navmesh())
} }
} }
impl GetMaybeTrace for AutorouteCommandStepper { impl GetMaybeTrace for AutorouteExecutionStepper {
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
self.route.as_ref().map(|route| route.trace()) self.route.as_ref().map(|route| route.trace())
} }
} }
impl GetGhosts for AutorouteCommandStepper { impl GetGhosts for AutorouteExecutionStepper {
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
self.route.as_ref().map_or(&[], |route| route.ghosts()) self.route.as_ref().map_or(&[], |route| route.ghosts())
} }
} }
impl GetObstacles for AutorouteCommandStepper { impl GetObstacles for AutorouteExecutionStepper {
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
self.route.as_ref().map_or(&[], |route| route.obstacles()) self.route.as_ref().map_or(&[], |route| route.obstacles())
} }

View File

@ -16,12 +16,12 @@ use crate::{
}; };
use super::{ use super::{
autoroute::AutorouteCommandStepper, autoroute::AutorouteExecutionStepper,
compare_detours::CompareDetoursCommandStepper, compare_detours::CompareDetoursExecutionStepper,
measure_length::MeasureLengthCommandStepper, measure_length::MeasureLengthExecutionStepper,
place_via::PlaceViaCommandStepper, place_via::PlaceViaExecutionStepper,
ratsnest::{Ratsnest, RatvertexIndex}, ratsnest::{Ratsnest, RatvertexIndex},
remove_bands::RemoveBandsCommandStepper, remove_bands::RemoveBandsExecutionStepper,
selection::{BandSelection, PinSelection}, selection::{BandSelection, PinSelection},
}; };
@ -62,7 +62,7 @@ impl<M: AccessMesadata> Autorouter<M> {
&mut self, &mut self,
selection: &PinSelection, selection: &PinSelection,
options: AutorouterOptions, options: AutorouterOptions,
) -> Result<AutorouteCommandStepper, AutorouterError> { ) -> Result<AutorouteExecutionStepper, AutorouterError> {
self.autoroute_ratlines(self.selected_ratlines(selection), options) self.autoroute_ratlines(self.selected_ratlines(selection), options)
} }
@ -70,8 +70,8 @@ impl<M: AccessMesadata> Autorouter<M> {
&mut self, &mut self,
ratlines: Vec<EdgeIndex<usize>>, ratlines: Vec<EdgeIndex<usize>>,
options: AutorouterOptions, options: AutorouterOptions,
) -> Result<AutorouteCommandStepper, AutorouterError> { ) -> Result<AutorouteExecutionStepper, AutorouterError> {
AutorouteCommandStepper::new(self, ratlines, options) AutorouteExecutionStepper::new(self, ratlines, options)
} }
pub fn undo_autoroute(&mut self, selection: &PinSelection) -> Result<(), AutorouterError> { pub fn undo_autoroute(&mut self, selection: &PinSelection) -> Result<(), AutorouterError> {
@ -99,8 +99,8 @@ impl<M: AccessMesadata> Autorouter<M> {
Ok(()) Ok(())
} }
pub fn place_via(&self, weight: ViaWeight) -> Result<PlaceViaCommandStepper, AutorouterError> { pub fn place_via(&self, weight: ViaWeight) -> Result<PlaceViaExecutionStepper, AutorouterError> {
PlaceViaCommandStepper::new(weight) PlaceViaExecutionStepper::new(weight)
} }
pub fn undo_place_via(&mut self, _weight: ViaWeight) { pub fn undo_place_via(&mut self, _weight: ViaWeight) {
@ -110,8 +110,8 @@ impl<M: AccessMesadata> Autorouter<M> {
pub fn remove_bands( pub fn remove_bands(
&self, &self,
selection: &BandSelection, selection: &BandSelection,
) -> Result<RemoveBandsCommandStepper, AutorouterError> { ) -> Result<RemoveBandsExecutionStepper, AutorouterError> {
RemoveBandsCommandStepper::new(selection) RemoveBandsExecutionStepper::new(selection)
} }
pub fn undo_remove_bands(&mut self, _selection: &BandSelection) { pub fn undo_remove_bands(&mut self, _selection: &BandSelection) {
@ -122,7 +122,7 @@ impl<M: AccessMesadata> Autorouter<M> {
&mut self, &mut self,
selection: &PinSelection, selection: &PinSelection,
options: AutorouterOptions, options: AutorouterOptions,
) -> Result<CompareDetoursCommandStepper, AutorouterError> { ) -> Result<CompareDetoursExecutionStepper, AutorouterError> {
let ratlines = self.selected_ratlines(selection); let ratlines = self.selected_ratlines(selection);
let ratline1 = *ratlines let ratline1 = *ratlines
.get(0) .get(0)
@ -138,15 +138,15 @@ impl<M: AccessMesadata> Autorouter<M> {
ratline1: EdgeIndex<usize>, ratline1: EdgeIndex<usize>,
ratline2: EdgeIndex<usize>, ratline2: EdgeIndex<usize>,
options: AutorouterOptions, options: AutorouterOptions,
) -> Result<CompareDetoursCommandStepper, AutorouterError> { ) -> Result<CompareDetoursExecutionStepper, AutorouterError> {
CompareDetoursCommandStepper::new(self, ratline1, ratline2, options) CompareDetoursExecutionStepper::new(self, ratline1, ratline2, options)
} }
pub fn measure_length( pub fn measure_length(
&mut self, &mut self,
selection: &BandSelection, selection: &BandSelection,
) -> Result<MeasureLengthCommandStepper, AutorouterError> { ) -> Result<MeasureLengthExecutionStepper, AutorouterError> {
MeasureLengthCommandStepper::new(selection) MeasureLengthExecutionStepper::new(selection)
} }
pub fn ratline_endpoints( pub fn ratline_endpoints(

View File

@ -4,12 +4,12 @@ use serde::{Deserialize, Serialize};
use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, step::Step}; use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, step::Step};
use super::{ use super::{
autoroute::{AutorouteCommandStepper, AutorouteStatus}, autoroute::{AutorouteExecutionStepper, AutorouteStatus},
compare_detours::{CompareDetoursCommandStepper, CompareDetoursStatus}, compare_detours::{CompareDetoursExecutionStepper, CompareDetoursStatus},
invoker::{Invoker, InvokerError, InvokerStatus}, invoker::{Invoker, InvokerError, InvokerStatus},
measure_length::MeasureLengthCommandStepper, measure_length::MeasureLengthExecutionStepper,
place_via::PlaceViaCommandStepper, place_via::PlaceViaExecutionStepper,
remove_bands::RemoveBandsCommandStepper, remove_bands::RemoveBandsExecutionStepper,
selection::{BandSelection, PinSelection}, selection::{BandSelection, PinSelection},
AutorouterOptions, AutorouterOptions,
}; };
@ -26,21 +26,21 @@ pub enum Command {
} }
#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)] #[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)]
pub enum CommandStepper { pub enum ExecutionStepper {
Autoroute(AutorouteCommandStepper), Autoroute(AutorouteExecutionStepper),
PlaceVia(PlaceViaCommandStepper), PlaceVia(PlaceViaExecutionStepper),
RemoveBands(RemoveBandsCommandStepper), RemoveBands(RemoveBandsExecutionStepper),
CompareDetours(CompareDetoursCommandStepper), CompareDetours(CompareDetoursExecutionStepper),
MeasureLength(MeasureLengthCommandStepper), MeasureLength(MeasureLengthExecutionStepper),
} }
impl CommandStepper { impl ExecutionStepper {
fn step_catch_err<M: AccessMesadata>( fn step_catch_err<M: AccessMesadata>(
&mut self, &mut self,
invoker: &mut Invoker<M>, invoker: &mut Invoker<M>,
) -> Result<InvokerStatus, InvokerError> { ) -> Result<InvokerStatus, InvokerError> {
match self { match self {
CommandStepper::Autoroute(autoroute) => { ExecutionStepper::Autoroute(autoroute) => {
match autoroute.step(&mut invoker.autorouter)? { match autoroute.step(&mut invoker.autorouter)? {
AutorouteStatus::Running => Ok(InvokerStatus::Running), AutorouteStatus::Running => Ok(InvokerStatus::Running),
AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running), AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running),
@ -49,19 +49,19 @@ impl CommandStepper {
))), ))),
} }
} }
CommandStepper::PlaceVia(place_via) => { ExecutionStepper::PlaceVia(place_via) => {
place_via.doit(&mut invoker.autorouter)?; place_via.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(String::from( Ok(InvokerStatus::Finished(String::from(
"finished placing via", "finished placing via",
))) )))
} }
CommandStepper::RemoveBands(remove_bands) => { ExecutionStepper::RemoveBands(remove_bands) => {
remove_bands.doit(&mut invoker.autorouter)?; remove_bands.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(String::from( Ok(InvokerStatus::Finished(String::from(
"finished removing bands", "finished removing bands",
))) )))
} }
CommandStepper::CompareDetours(compare_detours) => { ExecutionStepper::CompareDetours(compare_detours) => {
match compare_detours.step(&mut invoker.autorouter)? { match compare_detours.step(&mut invoker.autorouter)? {
CompareDetoursStatus::Running => Ok(InvokerStatus::Running), CompareDetoursStatus::Running => Ok(InvokerStatus::Running),
CompareDetoursStatus::Finished(total_length1, total_length2) => { CompareDetoursStatus::Finished(total_length1, total_length2) => {
@ -72,7 +72,7 @@ impl CommandStepper {
} }
} }
} }
CommandStepper::MeasureLength(measure_length) => { ExecutionStepper::MeasureLength(measure_length) => {
let length = measure_length.doit(&mut invoker.autorouter)?; let length = measure_length.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(format!( Ok(InvokerStatus::Finished(format!(
"Total length of selected bands: {}", "Total length of selected bands: {}",
@ -83,7 +83,7 @@ impl CommandStepper {
} }
} }
impl<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, InvokerError, ()> for CommandStepper { impl<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, InvokerError, ()> for ExecutionStepper {
fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> { fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> {
match self.step_catch_err(invoker) { match self.step_catch_err(invoker) {
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running), Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),

View File

@ -10,7 +10,7 @@ use crate::{
}; };
use super::{ use super::{
autoroute::{AutorouteCommandStepper, AutorouteStatus}, autoroute::{AutorouteExecutionStepper, AutorouteStatus},
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles}, invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles},
Autorouter, AutorouterError, AutorouterOptions, Autorouter, AutorouterError, AutorouterOptions,
}; };
@ -32,9 +32,9 @@ impl TryInto<(f64, f64)> for CompareDetoursStatus {
} }
} }
pub struct CompareDetoursCommandStepper { pub struct CompareDetoursExecutionStepper {
autoroute: AutorouteCommandStepper, autoroute: AutorouteExecutionStepper,
next_autoroute: Option<AutorouteCommandStepper>, next_autoroute: Option<AutorouteExecutionStepper>,
ratline1: EdgeIndex<usize>, ratline1: EdgeIndex<usize>,
ratline2: EdgeIndex<usize>, ratline2: EdgeIndex<usize>,
total_length1: f64, total_length1: f64,
@ -42,7 +42,7 @@ pub struct CompareDetoursCommandStepper {
done: bool, done: bool,
} }
impl CompareDetoursCommandStepper { impl CompareDetoursExecutionStepper {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratline1: EdgeIndex<usize>, ratline1: EdgeIndex<usize>,
@ -64,7 +64,7 @@ impl CompareDetoursCommandStepper {
// XXX: Do we really need this to be a stepper? We don't use at the moment, as sorting functions // XXX: Do we really need this to be a stepper? We don't use at the moment, as sorting functions
// aren't steppable either. It may be useful for debugging later on tho. // aren't steppable either. It may be useful for debugging later on tho.
impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterError, (f64, f64)> impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterError, (f64, f64)>
for CompareDetoursCommandStepper for CompareDetoursExecutionStepper
{ {
fn step( fn step(
&mut self, &mut self,
@ -112,25 +112,25 @@ impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterErro
} }
} }
impl GetMaybeNavmesh for CompareDetoursCommandStepper { impl GetMaybeNavmesh for CompareDetoursExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
self.autoroute.maybe_navmesh() self.autoroute.maybe_navmesh()
} }
} }
impl GetMaybeTrace for CompareDetoursCommandStepper { impl GetMaybeTrace for CompareDetoursExecutionStepper {
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
self.autoroute.maybe_trace() self.autoroute.maybe_trace()
} }
} }
impl GetGhosts for CompareDetoursCommandStepper { impl GetGhosts for CompareDetoursExecutionStepper {
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
self.autoroute.ghosts() self.autoroute.ghosts()
} }
} }
impl GetObstacles for CompareDetoursCommandStepper { impl GetObstacles for CompareDetoursExecutionStepper {
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
self.autoroute.obstacles() self.autoroute.obstacles()
} }

103
src/autorouter/execution.rs Normal file
View File

@ -0,0 +1,103 @@
use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, step::Step};
use super::{
autoroute::{AutorouteExecutionStepper, AutorouteStatus},
compare_detours::{CompareDetoursExecutionStepper, CompareDetoursStatus},
invoker::{Invoker, InvokerError, InvokerStatus},
measure_length::MeasureLengthExecutionStepper,
place_via::PlaceViaExecutionStepper,
remove_bands::RemoveBandsExecutionStepper,
selection::{BandSelection, PinSelection},
AutorouterOptions,
};
type Type = PinSelection;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Command {
Autoroute(PinSelection, AutorouterOptions),
PlaceVia(ViaWeight),
RemoveBands(BandSelection),
CompareDetours(Type, AutorouterOptions),
MeasureLength(BandSelection),
}
#[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)]
pub enum ExecutionStepper {
Autoroute(AutorouteExecutionStepper),
PlaceVia(PlaceViaExecutionStepper),
RemoveBands(RemoveBandsExecutionStepper),
CompareDetours(CompareDetoursExecutionStepper),
MeasureLength(MeasureLengthExecutionStepper),
}
impl ExecutionStepper {
fn step_catch_err<M: AccessMesadata>(
&mut self,
invoker: &mut Invoker<M>,
) -> Result<InvokerStatus, InvokerError> {
match self {
ExecutionStepper::Autoroute(autoroute) => {
match autoroute.step(&mut invoker.autorouter)? {
AutorouteStatus::Running => Ok(InvokerStatus::Running),
AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running),
AutorouteStatus::Finished => Ok(InvokerStatus::Finished(String::from(
"finished autorouting",
))),
}
}
ExecutionStepper::PlaceVia(place_via) => {
place_via.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(String::from(
"finished placing via",
)))
}
ExecutionStepper::RemoveBands(remove_bands) => {
remove_bands.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(String::from(
"finished removing bands",
)))
}
ExecutionStepper::CompareDetours(compare_detours) => {
match compare_detours.step(&mut invoker.autorouter)? {
CompareDetoursStatus::Running => Ok(InvokerStatus::Running),
CompareDetoursStatus::Finished(total_length1, total_length2) => {
Ok(InvokerStatus::Finished(String::from(format!(
"total detour lengths are {} and {}",
total_length1, total_length2
))))
}
}
}
ExecutionStepper::MeasureLength(measure_length) => {
let length = measure_length.doit(&mut invoker.autorouter)?;
Ok(InvokerStatus::Finished(format!(
"Total length of selected bands: {}",
length
)))
}
}
}
}
impl<M: AccessMesadata> Step<Invoker<M>, InvokerStatus, InvokerError, ()> for ExecutionStepper {
fn step(&mut self, invoker: &mut Invoker<M>) -> Result<InvokerStatus, InvokerError> {
match self.step_catch_err(invoker) {
Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running),
Ok(InvokerStatus::Finished(msg)) => {
if let Some(command) = invoker.ongoing_command.take() {
invoker.history.do_(command);
}
Ok(InvokerStatus::Finished(msg))
}
Err(err) => {
invoker.ongoing_command = None;
Err(err)
}
}
}
}

View File

@ -13,13 +13,13 @@ use crate::{
}; };
use super::{ use super::{
autoroute::AutorouteCommandStepper, autoroute::AutorouteExecutionStepper,
command::{Command, CommandStepper}, command::{Command, ExecutionStepper},
compare_detours::CompareDetoursCommandStepper, compare_detours::CompareDetoursExecutionStepper,
history::{History, HistoryError}, history::{History, HistoryError},
measure_length::MeasureLengthCommandStepper, measure_length::MeasureLengthExecutionStepper,
place_via::PlaceViaCommandStepper, place_via::PlaceViaExecutionStepper,
remove_bands::RemoveBandsCommandStepper, remove_bands::RemoveBandsExecutionStepper,
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
@ -108,14 +108,14 @@ impl<M: AccessMesadata> Invoker<M> {
} }
#[debug_requires(self.ongoing_command.is_none())] #[debug_requires(self.ongoing_command.is_none())]
pub fn execute_stepper(&mut self, command: Command) -> Result<CommandStepper, InvokerError> { pub fn execute_stepper(&mut self, command: Command) -> Result<ExecutionStepper, InvokerError> {
let execute = self.dispatch_command(&command); let execute = self.dispatch_command(&command);
self.ongoing_command = Some(command); self.ongoing_command = Some(command);
execute execute
} }
#[debug_requires(self.ongoing_command.is_none())] #[debug_requires(self.ongoing_command.is_none())]
fn dispatch_command(&mut self, command: &Command) -> Result<CommandStepper, InvokerError> { fn dispatch_command(&mut self, command: &Command) -> Result<ExecutionStepper, InvokerError> {
Ok(match command { Ok(match command {
Command::Autoroute(selection, options) => { Command::Autoroute(selection, options) => {
let mut ratlines = self.autorouter.selected_ratlines(selection); let mut ratlines = self.autorouter.selected_ratlines(selection);
@ -134,19 +134,19 @@ impl<M: AccessMesadata> Invoker<M> {
}); });
} }
CommandStepper::Autoroute(self.autorouter.autoroute_ratlines(ratlines, *options)?) ExecutionStepper::Autoroute(self.autorouter.autoroute_ratlines(ratlines, *options)?)
} }
Command::PlaceVia(weight) => { Command::PlaceVia(weight) => {
CommandStepper::PlaceVia(self.autorouter.place_via(*weight)?) ExecutionStepper::PlaceVia(self.autorouter.place_via(*weight)?)
} }
Command::RemoveBands(selection) => { Command::RemoveBands(selection) => {
CommandStepper::RemoveBands(self.autorouter.remove_bands(selection)?) ExecutionStepper::RemoveBands(self.autorouter.remove_bands(selection)?)
} }
Command::CompareDetours(selection, options) => CommandStepper::CompareDetours( Command::CompareDetours(selection, options) => ExecutionStepper::CompareDetours(
self.autorouter.compare_detours(selection, *options)?, self.autorouter.compare_detours(selection, *options)?,
), ),
Command::MeasureLength(selection) => { Command::MeasureLength(selection) => {
CommandStepper::MeasureLength(self.autorouter.measure_length(selection)?) ExecutionStepper::MeasureLength(self.autorouter.measure_length(selection)?)
} }
}) })
} }

View File

@ -12,12 +12,12 @@ use super::{
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
pub struct MeasureLengthCommandStepper { pub struct MeasureLengthExecutionStepper {
selection: BandSelection, selection: BandSelection,
maybe_length: Option<f64>, maybe_length: Option<f64>,
} }
impl MeasureLengthCommandStepper { impl MeasureLengthExecutionStepper {
pub fn new(selection: &BandSelection) -> Result<Self, AutorouterError> { pub fn new(selection: &BandSelection) -> Result<Self, AutorouterError> {
Ok(Self { Ok(Self {
selection: selection.clone(), selection: selection.clone(),
@ -51,25 +51,25 @@ impl MeasureLengthCommandStepper {
} }
} }
impl GetMaybeNavmesh for MeasureLengthCommandStepper { impl GetMaybeNavmesh for MeasureLengthExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
None None
} }
} }
impl GetMaybeTrace for MeasureLengthCommandStepper { impl GetMaybeTrace for MeasureLengthExecutionStepper {
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
None None
} }
} }
impl GetGhosts for MeasureLengthCommandStepper { impl GetGhosts for MeasureLengthExecutionStepper {
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
&[] &[]
} }
} }
impl GetObstacles for MeasureLengthCommandStepper { impl GetObstacles for MeasureLengthExecutionStepper {
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
&[] &[]
} }

View File

@ -12,12 +12,12 @@ use super::{
}; };
#[derive(Debug)] #[derive(Debug)]
pub struct PlaceViaCommandStepper { pub struct PlaceViaExecutionStepper {
weight: ViaWeight, weight: ViaWeight,
done: bool, done: bool,
} }
impl PlaceViaCommandStepper { impl PlaceViaExecutionStepper {
pub fn new(weight: ViaWeight) -> Result<Self, AutorouterError> { pub fn new(weight: ViaWeight) -> Result<Self, AutorouterError> {
Ok(Self { Ok(Self {
weight, weight,
@ -39,25 +39,25 @@ impl PlaceViaCommandStepper {
} }
} }
impl GetMaybeNavmesh for PlaceViaCommandStepper { impl GetMaybeNavmesh for PlaceViaExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
None None
} }
} }
impl GetMaybeTrace for PlaceViaCommandStepper { impl GetMaybeTrace for PlaceViaExecutionStepper {
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
None None
} }
} }
impl GetGhosts for PlaceViaCommandStepper { impl GetGhosts for PlaceViaExecutionStepper {
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
&[] &[]
} }
} }
impl GetObstacles for PlaceViaCommandStepper { impl GetObstacles for PlaceViaExecutionStepper {
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
&[] &[]
} }

View File

@ -12,12 +12,12 @@ use super::{
}; };
#[derive(Debug)] #[derive(Debug)]
pub struct RemoveBandsCommandStepper { pub struct RemoveBandsExecutionStepper {
selection: BandSelection, selection: BandSelection,
done: bool, done: bool,
} }
impl RemoveBandsCommandStepper { impl RemoveBandsExecutionStepper {
pub fn new(selection: &BandSelection) -> Result<Self, AutorouterError> { pub fn new(selection: &BandSelection) -> Result<Self, AutorouterError> {
Ok(Self { Ok(Self {
selection: selection.clone(), selection: selection.clone(),
@ -47,25 +47,25 @@ impl RemoveBandsCommandStepper {
} }
} }
impl GetMaybeNavmesh for RemoveBandsCommandStepper { impl GetMaybeNavmesh for RemoveBandsExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
None None
} }
} }
impl GetMaybeTrace for RemoveBandsCommandStepper { impl GetMaybeTrace for RemoveBandsExecutionStepper {
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
None None
} }
} }
impl GetGhosts for RemoveBandsCommandStepper { impl GetGhosts for RemoveBandsExecutionStepper {
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
&[] &[]
} }
} }
impl GetObstacles for RemoveBandsCommandStepper { impl GetObstacles for RemoveBandsExecutionStepper {
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
&[] &[]
} }

View File

@ -1,7 +1,7 @@
use thiserror::Error; use thiserror::Error;
use topola::{ use topola::{
autorouter::{ autorouter::{
command::CommandStepper, command::ExecutionStepper,
invoker::{ invoker::{
GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker, InvokerError, GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker, InvokerError,
InvokerStatus, InvokerStatus,
@ -15,18 +15,18 @@ use topola::{
step::Step, step::Step,
}; };
#[derive(Error, Debug, Clone)]
pub enum ActivityError {
#[error(transparent)]
Invoker(#[from] InvokerError),
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ActivityStatus { pub enum ActivityStatus {
Running, Running,
Finished(String), Finished(String),
} }
#[derive(Error, Debug, Clone)]
pub enum ActivityError {
#[error(transparent)]
Invoker(#[from] InvokerError),
}
impl From<InvokerStatus> for ActivityStatus { impl From<InvokerStatus> for ActivityStatus {
fn from(status: InvokerStatus) -> Self { fn from(status: InvokerStatus) -> Self {
match status { match status {
@ -48,7 +48,7 @@ impl TryInto<()> for ActivityStatus {
pub enum ActivityStepper { pub enum ActivityStepper {
// There will be another variant for interactive activities here soon. (TODO) // There will be another variant for interactive activities here soon. (TODO)
Command(CommandStepper), Execution(ExecutionStepper),
} }
impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()> for ActivityStepper { impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()> for ActivityStepper {
@ -57,7 +57,7 @@ impl Step<Invoker<SpecctraMesadata>, ActivityStatus, ActivityError, ()> for Acti
invoker: &mut Invoker<SpecctraMesadata>, invoker: &mut Invoker<SpecctraMesadata>,
) -> Result<ActivityStatus, ActivityError> { ) -> Result<ActivityStatus, ActivityError> {
match self { match self {
ActivityStepper::Command(execute) => Ok(execute.step(invoker)?.into()), ActivityStepper::Execution(execute) => Ok(execute.step(invoker)?.into()),
} }
} }
} }
@ -66,7 +66,7 @@ impl GetMaybeNavmesh for ActivityStepper {
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_navmesh(&self) -> Option<&Navmesh> {
match self { match self {
ActivityStepper::Command(execute) => execute.maybe_navmesh(), ActivityStepper::Execution(execute) => execute.maybe_navmesh(),
} }
} }
} }
@ -75,7 +75,7 @@ impl GetMaybeTrace for ActivityStepper {
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
fn maybe_trace(&self) -> Option<&TraceStepper> { fn maybe_trace(&self) -> Option<&TraceStepper> {
match self { match self {
ActivityStepper::Command(execute) => execute.maybe_trace(), ActivityStepper::Execution(execute) => execute.maybe_trace(),
} }
} }
} }
@ -84,7 +84,7 @@ impl GetGhosts for ActivityStepper {
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
fn ghosts(&self) -> &[PrimitiveShape] { fn ghosts(&self) -> &[PrimitiveShape] {
match self { match self {
ActivityStepper::Command(execute) => execute.ghosts(), ActivityStepper::Execution(execute) => execute.ghosts(),
} }
} }
} }
@ -93,7 +93,7 @@ impl GetObstacles for ActivityStepper {
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
fn obstacles(&self) -> &[PrimitiveIndex] { fn obstacles(&self) -> &[PrimitiveIndex] {
match self { match self {
ActivityStepper::Command(execute) => execute.obstacles(), ActivityStepper::Execution(execute) => execute.obstacles(),
} }
} }
} }
@ -104,9 +104,9 @@ pub struct ActivityWithStatus {
} }
impl ActivityWithStatus { impl ActivityWithStatus {
pub fn new_execute(execute: CommandStepper) -> ActivityWithStatus { pub fn new_execute(execute: ExecutionStepper) -> ActivityWithStatus {
Self { Self {
activity: ActivityStepper::Command(execute), activity: ActivityStepper::Execution(execute),
maybe_status: None, maybe_status: None,
} }
} }

View File

@ -0,0 +1,4 @@
pub struct RouteInteractionStepper {
route: RouteStepper,
options: RouterOptions,
}