diff --git a/src/autorouter/command.rs b/src/autorouter/command.rs deleted file mode 100644 index 25f3b2f..0000000 --- a/src/autorouter/command.rs +++ /dev/null @@ -1,96 +0,0 @@ -use enum_dispatch::enum_dispatch; -use serde::{Deserialize, Serialize}; - -use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, stepper::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( - &mut self, - invoker: &mut Invoker, - ) -> Result { - Ok(match self { - ExecutionStepper::Autoroute(autoroute) => { - match autoroute.step(&mut invoker.autorouter)? { - AutorouteStatus::Running => InvokerStatus::Running, - AutorouteStatus::Routed(..) => InvokerStatus::Running, - AutorouteStatus::Finished => { - InvokerStatus::Finished("finished autorouting".to_string()) - } - } - } - ExecutionStepper::PlaceVia(place_via) => { - place_via.doit(&mut invoker.autorouter)?; - InvokerStatus::Finished("finished placing via".to_string()) - } - ExecutionStepper::RemoveBands(remove_bands) => { - remove_bands.doit(&mut invoker.autorouter)?; - InvokerStatus::Finished("finished removing bands".to_string()) - } - ExecutionStepper::CompareDetours(compare_detours) => { - match compare_detours.step(&mut invoker.autorouter)? { - CompareDetoursStatus::Running => InvokerStatus::Running, - CompareDetoursStatus::Finished(total_length1, total_length2) => { - InvokerStatus::Finished(format!( - "total detour lengths are {} and {}", - total_length1, total_length2 - )) - } - } - } - ExecutionStepper::MeasureLength(measure_length) => { - let length = measure_length.doit(&mut invoker.autorouter)?; - InvokerStatus::Finished(format!("Total length of selected bands: {}", length)) - } - }) - } -} - -impl Step, InvokerStatus, InvokerError, ()> for ExecutionStepper { - fn step(&mut self, invoker: &mut Invoker) -> Result { - 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) - } - } - } -} diff --git a/src/autorouter/execution.rs b/src/autorouter/execution.rs index cae54de..25f3b2f 100644 --- a/src/autorouter/execution.rs +++ b/src/autorouter/execution.rs @@ -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}, @@ -39,47 +39,40 @@ impl ExecutionStepper { &mut self, invoker: &mut Invoker, ) -> Result { - match self { + Ok(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", - ))), + AutorouteStatus::Running => InvokerStatus::Running, + AutorouteStatus::Routed(..) => InvokerStatus::Running, + AutorouteStatus::Finished => { + InvokerStatus::Finished("finished autorouting".to_string()) + } } } ExecutionStepper::PlaceVia(place_via) => { place_via.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished(String::from( - "finished placing via", - ))) + InvokerStatus::Finished("finished placing via".to_string()) } ExecutionStepper::RemoveBands(remove_bands) => { remove_bands.doit(&mut invoker.autorouter)?; - Ok(InvokerStatus::Finished(String::from( - "finished removing bands", - ))) + InvokerStatus::Finished("finished removing bands".to_string()) } ExecutionStepper::CompareDetours(compare_detours) => { match compare_detours.step(&mut invoker.autorouter)? { - CompareDetoursStatus::Running => Ok(InvokerStatus::Running), + CompareDetoursStatus::Running => InvokerStatus::Running, CompareDetoursStatus::Finished(total_length1, total_length2) => { - Ok(InvokerStatus::Finished(String::from(format!( + InvokerStatus::Finished(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 - ))) + InvokerStatus::Finished(format!("Total length of selected bands: {}", length)) } - } + }) } } diff --git a/src/autorouter/history.rs b/src/autorouter/history.rs index 4db7814..bfc512e 100644 --- a/src/autorouter/history.rs +++ b/src/autorouter/history.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::autorouter::command::Command; +use crate::autorouter::execution::Command; #[derive(Error, Debug, Clone)] pub enum HistoryError { diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 2ab12c6..123daab 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -16,8 +16,8 @@ use crate::{ use super::{ autoroute::AutorouteExecutionStepper, - command::{Command, ExecutionStepper}, compare_detours::CompareDetoursExecutionStepper, + execution::{Command, ExecutionStepper}, history::{History, HistoryError}, measure_length::MeasureLengthExecutionStepper, place_via::PlaceViaExecutionStepper, diff --git a/src/autorouter/mod.rs b/src/autorouter/mod.rs index c161fe0..93093de 100644 --- a/src/autorouter/mod.rs +++ b/src/autorouter/mod.rs @@ -2,8 +2,8 @@ pub mod autoroute; mod autorouter; -pub mod command; pub mod compare_detours; +pub mod execution; pub mod history; pub mod invoker; pub mod measure_length; diff --git a/src/bin/topola-egui/activity.rs b/src/bin/topola-egui/activity.rs index 27c1c9c..00f1969 100644 --- a/src/bin/topola-egui/activity.rs +++ b/src/bin/topola-egui/activity.rs @@ -1,7 +1,7 @@ use thiserror::Error; use topola::{ autorouter::{ - command::ExecutionStepper, + execution::ExecutionStepper, invoker::{ GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker, InvokerError, InvokerStatus, diff --git a/src/bin/topola-egui/menu_bar.rs b/src/bin/topola-egui/menu_bar.rs index e0ba6ba..470cb5d 100644 --- a/src/bin/topola-egui/menu_bar.rs +++ b/src/bin/topola-egui/menu_bar.rs @@ -5,7 +5,7 @@ use std::{ use topola::{ autorouter::{ - command::Command, + execution::Command, history::History, invoker::{Invoker, InvokerError}, AutorouterOptions, diff --git a/src/bin/topola-egui/viewport.rs b/src/bin/topola-egui/viewport.rs index 1cd00fe..18de39f 100644 --- a/src/bin/topola-egui/viewport.rs +++ b/src/bin/topola-egui/viewport.rs @@ -6,7 +6,7 @@ use petgraph::{ use rstar::{Envelope, AABB}; use topola::{ autorouter::{ - command::Command, + execution::Command, invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker}, }, drawing::{ diff --git a/src/bin/topola/main.rs b/src/bin/topola/main.rs index 3e09e69..60220a2 100644 --- a/src/bin/topola/main.rs +++ b/src/bin/topola/main.rs @@ -1,7 +1,7 @@ use clap::Parser; use std::fs::File; use std::io::BufReader; -use topola::autorouter::command::Command; +use topola::autorouter::execution::Command; use topola::autorouter::history::History; use topola::autorouter::invoker::Invoker; use topola::autorouter::selection::PinSelection; diff --git a/tests/multilayer.rs b/tests/multilayer.rs index a369ebb..eb38870 100644 --- a/tests/multilayer.rs +++ b/tests/multilayer.rs @@ -1,5 +1,5 @@ use topola::{ - autorouter::{command::Command, invoker::InvokerError, AutorouterError}, + autorouter::{execution::Command, invoker::InvokerError, AutorouterError}, board::mesadata::AccessMesadata, layout::via::ViaWeight, math::Circle, diff --git a/tests/single_layer.rs b/tests/single_layer.rs index e51a24e..a093f29 100644 --- a/tests/single_layer.rs +++ b/tests/single_layer.rs @@ -1,6 +1,6 @@ use topola::{ autorouter::{ - command::Command, + execution::Command, invoker::{Invoker, InvokerError}, AutorouterError, },