From cc0bf1845ac2a7740cf1a653a4b859458fde601c Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 1 Oct 2024 14:11:02 +0200 Subject: [PATCH] terminology: suffix some single-verb object type names with "Stepper" --- src/autorouter/autoroute.rs | 22 +++++----- src/autorouter/autorouter.rs | 37 +++++++++-------- src/autorouter/{execute.rs => command.rs} | 50 ++++++++++++----------- src/autorouter/compare_detours.rs | 24 +++++------ src/autorouter/history.rs | 2 +- src/autorouter/invoker.rs | 36 ++++++++-------- src/autorouter/measure_length.rs | 16 ++++---- src/autorouter/mod.rs | 2 +- src/autorouter/place_via.rs | 16 ++++---- src/autorouter/remove_bands.rs | 16 ++++---- src/bin/topola-egui/activity.rs | 38 ++++++++--------- src/bin/topola-egui/app.rs | 2 +- src/bin/topola-egui/menu_bar.rs | 2 +- src/bin/topola-egui/viewport.rs | 2 +- src/bin/topola/main.rs | 2 +- src/router/route.rs | 12 +++--- src/router/router.rs | 12 +++--- src/router/trace.rs | 16 +++++--- src/router/tracer.rs | 14 +++---- tests/multilayer.rs | 2 +- tests/single_layer.rs | 2 +- 21 files changed, 170 insertions(+), 155 deletions(-) rename src/autorouter/{execute.rs => command.rs} (67%) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 123dc5a..cb0d258 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -4,7 +4,7 @@ use crate::{ board::mesadata::AccessMesadata, drawing::{band::BandTermsegIndex, graph::PrimitiveIndex}, geometry::primitive::PrimitiveShape, - router::{navmesh::Navmesh, route::Route, trace::Trace, Router, RouterStatus}, + router::{navmesh::Navmesh, route::RouteStepper, trace::TraceStepper, Router, RouterStatus}, step::Step, }; @@ -30,14 +30,14 @@ impl TryInto<()> for AutorouteStatus { } } -pub struct Autoroute { +pub struct AutorouteCommandStepper { ratlines_iter: Box>>, options: AutorouterOptions, - route: Option, + route: Option, curr_ratline: Option>, } -impl Autoroute { +impl AutorouteCommandStepper { pub fn new( autorouter: &mut Autorouter, ratlines: impl IntoIterator> + 'static, @@ -63,7 +63,9 @@ impl Autoroute { } } -impl Step, AutorouteStatus, AutorouterError, ()> for Autoroute { +impl Step, AutorouteStatus, AutorouterError, ()> + for AutorouteCommandStepper +{ fn step(&mut self, autorouter: &mut Autorouter) -> Result { let Some(curr_ratline) = self.curr_ratline else { return Ok(AutorouteStatus::Finished); @@ -117,25 +119,25 @@ impl Step, AutorouteStatus, AutorouterError, () } } -impl GetMaybeNavmesh for Autoroute { +impl GetMaybeNavmesh for AutorouteCommandStepper { fn maybe_navmesh(&self) -> Option<&Navmesh> { self.route.as_ref().map(|route| route.navmesh()) } } -impl GetMaybeTrace for Autoroute { - fn maybe_trace(&self) -> Option<&Trace> { +impl GetMaybeTrace for AutorouteCommandStepper { + fn maybe_trace(&self) -> Option<&TraceStepper> { self.route.as_ref().map(|route| route.trace()) } } -impl GetGhosts for Autoroute { +impl GetGhosts for AutorouteCommandStepper { fn ghosts(&self) -> &[PrimitiveShape] { self.route.as_ref().map_or(&[], |route| route.ghosts()) } } -impl GetObstacles for Autoroute { +impl GetObstacles for AutorouteCommandStepper { fn obstacles(&self) -> &[PrimitiveIndex] { self.route.as_ref().map_or(&[], |route| route.obstacles()) } diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index eee07fe..9bd7235 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -16,12 +16,12 @@ use crate::{ }; use super::{ - autoroute::Autoroute, - compare_detours::CompareDetours, - measure_length::MeasureLength, - place_via::PlaceVia, + autoroute::AutorouteCommandStepper, + compare_detours::CompareDetoursCommandStepper, + measure_length::MeasureLengthCommandStepper, + place_via::PlaceViaCommandStepper, ratsnest::{Ratsnest, RatvertexIndex}, - remove_bands::RemoveBands, + remove_bands::RemoveBandsCommandStepper, selection::{BandSelection, PinSelection}, }; @@ -62,7 +62,7 @@ impl Autorouter { &mut self, selection: &PinSelection, options: AutorouterOptions, - ) -> Result { + ) -> Result { self.autoroute_ratlines(self.selected_ratlines(selection), options) } @@ -70,8 +70,8 @@ impl Autorouter { &mut self, ratlines: Vec>, options: AutorouterOptions, - ) -> Result { - Autoroute::new(self, ratlines, options) + ) -> Result { + AutorouteCommandStepper::new(self, ratlines, options) } pub fn undo_autoroute(&mut self, selection: &PinSelection) -> Result<(), AutorouterError> { @@ -99,16 +99,19 @@ impl Autorouter { Ok(()) } - pub fn place_via(&self, weight: ViaWeight) -> Result { - PlaceVia::new(weight) + pub fn place_via(&self, weight: ViaWeight) -> Result { + PlaceViaCommandStepper::new(weight) } pub fn undo_place_via(&mut self, _weight: ViaWeight) { todo!(); } - pub fn remove_bands(&self, selection: &BandSelection) -> Result { - RemoveBands::new(selection) + pub fn remove_bands( + &self, + selection: &BandSelection, + ) -> Result { + RemoveBandsCommandStepper::new(selection) } pub fn undo_remove_bands(&mut self, _selection: &BandSelection) { @@ -119,7 +122,7 @@ impl Autorouter { &mut self, selection: &PinSelection, options: AutorouterOptions, - ) -> Result { + ) -> Result { let ratlines = self.selected_ratlines(selection); let ratline1 = *ratlines .get(0) @@ -135,15 +138,15 @@ impl Autorouter { ratline1: EdgeIndex, ratline2: EdgeIndex, options: AutorouterOptions, - ) -> Result { - CompareDetours::new(self, ratline1, ratline2, options) + ) -> Result { + CompareDetoursCommandStepper::new(self, ratline1, ratline2, options) } pub fn measure_length( &mut self, selection: &BandSelection, - ) -> Result { - MeasureLength::new(selection) + ) -> Result { + MeasureLengthCommandStepper::new(selection) } pub fn ratline_endpoints( diff --git a/src/autorouter/execute.rs b/src/autorouter/command.rs similarity index 67% rename from src/autorouter/execute.rs rename to src/autorouter/command.rs index 2d4e34a..8077f1d 100644 --- a/src/autorouter/execute.rs +++ b/src/autorouter/command.rs @@ -4,12 +4,12 @@ use serde::{Deserialize, Serialize}; use crate::{board::mesadata::AccessMesadata, layout::via::ViaWeight, step::Step}; use super::{ - autoroute::{Autoroute, AutorouteStatus}, - compare_detours::{CompareDetours, CompareDetoursStatus}, + autoroute::{AutorouteCommandStepper, AutorouteStatus}, + compare_detours::{CompareDetoursCommandStepper, CompareDetoursStatus}, invoker::{Invoker, InvokerError, InvokerStatus}, - measure_length::MeasureLength, - place_via::PlaceVia, - remove_bands::RemoveBands, + measure_length::MeasureLengthCommandStepper, + place_via::PlaceViaCommandStepper, + remove_bands::RemoveBandsCommandStepper, selection::{BandSelection, PinSelection}, AutorouterOptions, }; @@ -26,40 +26,42 @@ pub enum Command { } #[enum_dispatch(GetMaybeNavmesh, GetMaybeTrace, GetGhosts, GetObstacles)] -pub enum Execute { - Autoroute(Autoroute), - PlaceVia(PlaceVia), - RemoveBands(RemoveBands), - CompareDetours(CompareDetours), - MeasureLength(MeasureLength), +pub enum CommandStepper { + Autoroute(AutorouteCommandStepper), + PlaceVia(PlaceViaCommandStepper), + RemoveBands(RemoveBandsCommandStepper), + CompareDetours(CompareDetoursCommandStepper), + MeasureLength(MeasureLengthCommandStepper), } -impl Execute { +impl CommandStepper { fn step_catch_err( &mut self, invoker: &mut Invoker, ) -> Result { match self { - Execute::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", - ))), - }, - Execute::PlaceVia(place_via) => { + CommandStepper::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", + ))), + } + } + CommandStepper::PlaceVia(place_via) => { place_via.doit(&mut invoker.autorouter)?; Ok(InvokerStatus::Finished(String::from( "finished placing via", ))) } - Execute::RemoveBands(remove_bands) => { + CommandStepper::RemoveBands(remove_bands) => { remove_bands.doit(&mut invoker.autorouter)?; Ok(InvokerStatus::Finished(String::from( "finished removing bands", ))) } - Execute::CompareDetours(compare_detours) => { + CommandStepper::CompareDetours(compare_detours) => { match compare_detours.step(&mut invoker.autorouter)? { CompareDetoursStatus::Running => Ok(InvokerStatus::Running), CompareDetoursStatus::Finished(total_length1, total_length2) => { @@ -70,7 +72,7 @@ impl Execute { } } } - Execute::MeasureLength(measure_length) => { + CommandStepper::MeasureLength(measure_length) => { let length = measure_length.doit(&mut invoker.autorouter)?; Ok(InvokerStatus::Finished(format!( "Total length of selected bands: {}", @@ -81,7 +83,7 @@ impl Execute { } } -impl Step, InvokerStatus, InvokerError, ()> for Execute { +impl Step, InvokerStatus, InvokerError, ()> for CommandStepper { fn step(&mut self, invoker: &mut Invoker) -> Result { match self.step_catch_err(invoker) { Ok(InvokerStatus::Running) => Ok(InvokerStatus::Running), diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index c2ea328..6da6ced 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -5,12 +5,12 @@ use crate::{ drawing::graph::PrimitiveIndex, geometry::{primitive::PrimitiveShape, shape::MeasureLength}, graph::MakeRef, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, step::Step, }; use super::{ - autoroute::{Autoroute, AutorouteStatus}, + autoroute::{AutorouteCommandStepper, AutorouteStatus}, invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles}, Autorouter, AutorouterError, AutorouterOptions, }; @@ -32,9 +32,9 @@ impl TryInto<(f64, f64)> for CompareDetoursStatus { } } -pub struct CompareDetours { - autoroute: Autoroute, - next_autoroute: Option, +pub struct CompareDetoursCommandStepper { + autoroute: AutorouteCommandStepper, + next_autoroute: Option, ratline1: EdgeIndex, ratline2: EdgeIndex, total_length1: f64, @@ -42,7 +42,7 @@ pub struct CompareDetours { done: bool, } -impl CompareDetours { +impl CompareDetoursCommandStepper { pub fn new( autorouter: &mut Autorouter, ratline1: EdgeIndex, @@ -64,7 +64,7 @@ impl CompareDetours { // 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. impl Step, CompareDetoursStatus, AutorouterError, (f64, f64)> - for CompareDetours + for CompareDetoursCommandStepper { fn step( &mut self, @@ -112,25 +112,25 @@ impl Step, CompareDetoursStatus, AutorouterErro } } -impl GetMaybeNavmesh for CompareDetours { +impl GetMaybeNavmesh for CompareDetoursCommandStepper { fn maybe_navmesh(&self) -> Option<&Navmesh> { self.autoroute.maybe_navmesh() } } -impl GetMaybeTrace for CompareDetours { - fn maybe_trace(&self) -> Option<&Trace> { +impl GetMaybeTrace for CompareDetoursCommandStepper { + fn maybe_trace(&self) -> Option<&TraceStepper> { self.autoroute.maybe_trace() } } -impl GetGhosts for CompareDetours { +impl GetGhosts for CompareDetoursCommandStepper { fn ghosts(&self) -> &[PrimitiveShape] { self.autoroute.ghosts() } } -impl GetObstacles for CompareDetours { +impl GetObstacles for CompareDetoursCommandStepper { fn obstacles(&self) -> &[PrimitiveIndex] { self.autoroute.obstacles() } diff --git a/src/autorouter/history.rs b/src/autorouter/history.rs index 90a3426..3730480 100644 --- a/src/autorouter/history.rs +++ b/src/autorouter/history.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::autorouter::execute::Command; +use crate::autorouter::command::Command; #[derive(Error, Debug, Clone)] pub enum HistoryError { diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 0245d5d..3568fb5 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -8,18 +8,18 @@ use crate::{ board::mesadata::AccessMesadata, drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, step::Step, }; use super::{ - autoroute::Autoroute, - compare_detours::CompareDetours, - execute::{Command, Execute}, + autoroute::AutorouteCommandStepper, + command::{Command, CommandStepper}, + compare_detours::CompareDetoursCommandStepper, history::{History, HistoryError}, - measure_length::MeasureLength, - place_via::PlaceVia, - remove_bands::RemoveBands, + measure_length::MeasureLengthCommandStepper, + place_via::PlaceViaCommandStepper, + remove_bands::RemoveBandsCommandStepper, Autorouter, AutorouterError, }; @@ -30,7 +30,7 @@ pub trait GetMaybeNavmesh { #[enum_dispatch] pub trait GetMaybeTrace { - fn maybe_trace(&self) -> Option<&Trace>; + fn maybe_trace(&self) -> Option<&TraceStepper>; } #[enum_dispatch] @@ -108,14 +108,14 @@ impl Invoker { } #[debug_requires(self.ongoing_command.is_none())] - pub fn execute_stepper(&mut self, command: Command) -> Result { + pub fn execute_stepper(&mut self, command: Command) -> Result { let execute = self.dispatch_command(&command); self.ongoing_command = Some(command); execute } #[debug_requires(self.ongoing_command.is_none())] - fn dispatch_command(&mut self, command: &Command) -> Result { + fn dispatch_command(&mut self, command: &Command) -> Result { Ok(match command { Command::Autoroute(selection, options) => { let mut ratlines = self.autorouter.selected_ratlines(selection); @@ -134,17 +134,19 @@ impl Invoker { }); } - Execute::Autoroute(self.autorouter.autoroute_ratlines(ratlines, *options)?) + CommandStepper::Autoroute(self.autorouter.autoroute_ratlines(ratlines, *options)?) + } + Command::PlaceVia(weight) => { + CommandStepper::PlaceVia(self.autorouter.place_via(*weight)?) } - Command::PlaceVia(weight) => Execute::PlaceVia(self.autorouter.place_via(*weight)?), Command::RemoveBands(selection) => { - Execute::RemoveBands(self.autorouter.remove_bands(selection)?) - } - Command::CompareDetours(selection, options) => { - Execute::CompareDetours(self.autorouter.compare_detours(selection, *options)?) + CommandStepper::RemoveBands(self.autorouter.remove_bands(selection)?) } + Command::CompareDetours(selection, options) => CommandStepper::CompareDetours( + self.autorouter.compare_detours(selection, *options)?, + ), Command::MeasureLength(selection) => { - Execute::MeasureLength(self.autorouter.measure_length(selection)?) + CommandStepper::MeasureLength(self.autorouter.measure_length(selection)?) } }) } diff --git a/src/autorouter/measure_length.rs b/src/autorouter/measure_length.rs index ed76ff5..11b0991 100644 --- a/src/autorouter/measure_length.rs +++ b/src/autorouter/measure_length.rs @@ -3,7 +3,7 @@ use crate::{ drawing::graph::PrimitiveIndex, geometry::{primitive::PrimitiveShape, shape::MeasureLength as MeasureLengthTrait}, graph::MakeRef, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, }; use super::{ @@ -12,12 +12,12 @@ use super::{ Autorouter, AutorouterError, }; -pub struct MeasureLength { +pub struct MeasureLengthCommandStepper { selection: BandSelection, maybe_length: Option, } -impl MeasureLength { +impl MeasureLengthCommandStepper { pub fn new(selection: &BandSelection) -> Result { Ok(Self { selection: selection.clone(), @@ -51,25 +51,25 @@ impl MeasureLength { } } -impl GetMaybeNavmesh for MeasureLength { +impl GetMaybeNavmesh for MeasureLengthCommandStepper { fn maybe_navmesh(&self) -> Option<&Navmesh> { None } } -impl GetMaybeTrace for MeasureLength { - fn maybe_trace(&self) -> Option<&Trace> { +impl GetMaybeTrace for MeasureLengthCommandStepper { + fn maybe_trace(&self) -> Option<&TraceStepper> { None } } -impl GetGhosts for MeasureLength { +impl GetGhosts for MeasureLengthCommandStepper { fn ghosts(&self) -> &[PrimitiveShape] { &[] } } -impl GetObstacles for MeasureLength { +impl GetObstacles for MeasureLengthCommandStepper { fn obstacles(&self) -> &[PrimitiveIndex] { &[] } diff --git a/src/autorouter/mod.rs b/src/autorouter/mod.rs index 7ce1a4e..1c638b3 100644 --- a/src/autorouter/mod.rs +++ b/src/autorouter/mod.rs @@ -1,7 +1,7 @@ pub mod autoroute; mod autorouter; +pub mod command; pub mod compare_detours; -pub mod execute; pub mod history; pub mod invoker; pub mod measure_length; diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index 93c5810..bacb254 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -3,7 +3,7 @@ use crate::{ drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, layout::via::ViaWeight, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, }; use super::{ @@ -12,12 +12,12 @@ use super::{ }; #[derive(Debug)] -pub struct PlaceVia { +pub struct PlaceViaCommandStepper { weight: ViaWeight, done: bool, } -impl PlaceVia { +impl PlaceViaCommandStepper { pub fn new(weight: ViaWeight) -> Result { Ok(Self { weight, @@ -39,25 +39,25 @@ impl PlaceVia { } } -impl GetMaybeNavmesh for PlaceVia { +impl GetMaybeNavmesh for PlaceViaCommandStepper { fn maybe_navmesh(&self) -> Option<&Navmesh> { None } } -impl GetMaybeTrace for PlaceVia { - fn maybe_trace(&self) -> Option<&Trace> { +impl GetMaybeTrace for PlaceViaCommandStepper { + fn maybe_trace(&self) -> Option<&TraceStepper> { None } } -impl GetGhosts for PlaceVia { +impl GetGhosts for PlaceViaCommandStepper { fn ghosts(&self) -> &[PrimitiveShape] { &[] } } -impl GetObstacles for PlaceVia { +impl GetObstacles for PlaceViaCommandStepper { fn obstacles(&self) -> &[PrimitiveIndex] { &[] } diff --git a/src/autorouter/remove_bands.rs b/src/autorouter/remove_bands.rs index 494f9c1..cea80a9 100644 --- a/src/autorouter/remove_bands.rs +++ b/src/autorouter/remove_bands.rs @@ -2,7 +2,7 @@ use crate::{ board::mesadata::AccessMesadata, drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, }; use super::{ @@ -12,12 +12,12 @@ use super::{ }; #[derive(Debug)] -pub struct RemoveBands { +pub struct RemoveBandsCommandStepper { selection: BandSelection, done: bool, } -impl RemoveBands { +impl RemoveBandsCommandStepper { pub fn new(selection: &BandSelection) -> Result { Ok(Self { selection: selection.clone(), @@ -47,25 +47,25 @@ impl RemoveBands { } } -impl GetMaybeNavmesh for RemoveBands { +impl GetMaybeNavmesh for RemoveBandsCommandStepper { fn maybe_navmesh(&self) -> Option<&Navmesh> { None } } -impl GetMaybeTrace for RemoveBands { - fn maybe_trace(&self) -> Option<&Trace> { +impl GetMaybeTrace for RemoveBandsCommandStepper { + fn maybe_trace(&self) -> Option<&TraceStepper> { None } } -impl GetGhosts for RemoveBands { +impl GetGhosts for RemoveBandsCommandStepper { fn ghosts(&self) -> &[PrimitiveShape] { &[] } } -impl GetObstacles for RemoveBands { +impl GetObstacles for RemoveBandsCommandStepper { fn obstacles(&self) -> &[PrimitiveIndex] { &[] } diff --git a/src/bin/topola-egui/activity.rs b/src/bin/topola-egui/activity.rs index d454599..10d4a4a 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::{ - execute::Execute, + command::CommandStepper, invoker::{ GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker, InvokerError, InvokerStatus, @@ -10,7 +10,7 @@ use topola::{ board::mesadata::AccessMesadata, drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, - router::{navmesh::Navmesh, trace::Trace}, + router::{navmesh::Navmesh, trace::TraceStepper}, specctra::mesadata::SpecctraMesadata, step::Step, }; @@ -46,67 +46,67 @@ impl TryInto<()> for ActivityStatus { } } -pub enum Activity { +pub enum ActivityStepper { // There will be another variant for interactive activities here soon. (TODO) - Execute(Execute), + Command(CommandStepper), } -impl Step, ActivityStatus, ActivityError, ()> for Activity { +impl Step, ActivityStatus, ActivityError, ()> for ActivityStepper { fn step( &mut self, invoker: &mut Invoker, ) -> Result { match self { - Activity::Execute(execute) => Ok(execute.step(invoker)?.into()), + ActivityStepper::Command(execute) => Ok(execute.step(invoker)?.into()), } } } -impl GetMaybeNavmesh for Activity { +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 { - Activity::Execute(execute) => execute.maybe_navmesh(), + ActivityStepper::Command(execute) => execute.maybe_navmesh(), } } } -impl GetMaybeTrace for Activity { +impl GetMaybeTrace for ActivityStepper { /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. - fn maybe_trace(&self) -> Option<&Trace> { + fn maybe_trace(&self) -> Option<&TraceStepper> { match self { - Activity::Execute(execute) => execute.maybe_trace(), + ActivityStepper::Command(execute) => execute.maybe_trace(), } } } -impl GetGhosts for Activity { +impl GetGhosts for ActivityStepper { /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. fn ghosts(&self) -> &[PrimitiveShape] { match self { - Activity::Execute(execute) => execute.ghosts(), + ActivityStepper::Command(execute) => execute.ghosts(), } } } -impl GetObstacles for Activity { +impl GetObstacles for ActivityStepper { /// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates. fn obstacles(&self) -> &[PrimitiveIndex] { match self { - Activity::Execute(execute) => execute.obstacles(), + ActivityStepper::Command(execute) => execute.obstacles(), } } } pub struct ActivityWithStatus { - activity: Activity, + activity: ActivityStepper, maybe_status: Option, } impl ActivityWithStatus { - pub fn new_execute(execute: Execute) -> ActivityWithStatus { + pub fn new_execute(execute: CommandStepper) -> ActivityWithStatus { Self { - activity: Activity::Execute(execute), + activity: ActivityStepper::Command(execute), maybe_status: None, } } @@ -132,7 +132,7 @@ impl GetMaybeNavmesh for ActivityWithStatus { } impl GetMaybeTrace for ActivityWithStatus { - fn maybe_trace(&self) -> Option<&Trace> { + fn maybe_trace(&self) -> Option<&TraceStepper> { self.activity.maybe_trace() } } diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 8d4ca2f..42d306a 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -31,7 +31,7 @@ use topola::{ router::{ draw::DrawException, navmesh::{BinavvertexNodeIndex, Navmesh}, - trace::Trace, + trace::TraceStepper, tracer::Tracer, }, specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, diff --git a/src/bin/topola-egui/menu_bar.rs b/src/bin/topola-egui/menu_bar.rs index ff3219a..18fcd07 100644 --- a/src/bin/topola-egui/menu_bar.rs +++ b/src/bin/topola-egui/menu_bar.rs @@ -6,7 +6,7 @@ use std::{ use topola::{ autorouter::{ - execute::Command, + command::Command, invoker::{Invoker, InvokerError, InvokerStatus}, AutorouterOptions, }, diff --git a/src/bin/topola-egui/viewport.rs b/src/bin/topola-egui/viewport.rs index 4ab3810..aadceb7 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::{ - execute::Command, + command::Command, invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles, Invoker}, }, board::mesadata::AccessMesadata, diff --git a/src/bin/topola/main.rs b/src/bin/topola/main.rs index f0edde7..1f072e1 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::execute::Command; +use topola::autorouter::command::Command; use topola::autorouter::history::History; use topola::autorouter::invoker::Invoker; use topola::autorouter::selection::PinSelection; diff --git a/src/router/route.rs b/src/router/route.rs index 917cf2f..91ba68c 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -6,21 +6,21 @@ use crate::{ router::{ astar::{Astar, AstarStatus}, navmesh::Navmesh, - trace::Trace, + trace::TraceStepper, tracer::Tracer, Router, RouterAstarStrategy, RouterError, RouterStatus, }, step::Step, }; -pub struct Route { +pub struct RouteStepper { astar: Astar, - trace: Trace, + trace: TraceStepper, ghosts: Vec, obstacles: Vec, } -impl Route { +impl RouteStepper { pub fn new( router: &mut Router, from: FixedDotIndex, @@ -60,7 +60,7 @@ impl Route { &self.astar.graph } - pub fn trace(&self) -> &Trace { + pub fn trace(&self) -> &TraceStepper { &self.trace } @@ -74,7 +74,7 @@ impl Route { } impl<'a, R: AccessRules> Step, RouterStatus, RouterError, BandTermsegIndex> - for Route + for RouteStepper { fn step(&mut self, router: &mut Router) -> Result { let tracer = Tracer::new(router.layout_mut()); diff --git a/src/router/router.rs b/src/router/router.rs index c232f76..bed16ab 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -26,8 +26,8 @@ use super::{ astar::{AstarError, AstarStrategy, PathTracker}, draw::DrawException, navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavvertexIndex}, - route::Route, - trace::{Trace, TraceStepContext}, + route::RouteStepper, + trace::{TraceStepContext, TraceStepper}, tracer::{Tracer, TracerException}, }; @@ -63,14 +63,14 @@ impl TryInto for RouterStatus { #[derive(Debug)] pub struct RouterAstarStrategy<'a, R: AccessRules> { pub tracer: Tracer<'a, R>, - pub trace: &'a mut Trace, + pub trace: &'a mut TraceStepper, pub target: FixedDotIndex, pub probe_ghosts: Vec, pub probe_obstacles: Vec, } impl<'a, R: AccessRules> RouterAstarStrategy<'a, R> { - pub fn new(tracer: Tracer<'a, R>, trace: &'a mut Trace, target: FixedDotIndex) -> Self { + pub fn new(tracer: Tracer<'a, R>, trace: &'a mut TraceStepper, target: FixedDotIndex) -> Self { Self { tracer, trace, @@ -200,8 +200,8 @@ impl<'a, R: AccessRules> Router<'a, R> { from: FixedDotIndex, to: FixedDotIndex, width: f64, - ) -> Result { - Route::new(self, from, to, width) + ) -> Result { + RouteStepper::new(self, from, to, width) } pub fn layout_mut(&mut self) -> &mut Layout { diff --git a/src/router/trace.rs b/src/router/trace.rs index bc06407..bcb38a4 100644 --- a/src/router/trace.rs +++ b/src/router/trace.rs @@ -20,14 +20,18 @@ use super::{ }; #[derive(Debug)] -pub struct Trace { +pub struct TraceStepper { pub path: Vec, pub head: Head, pub width: f64, } -impl Trace { - pub fn new(source: FixedDotIndex, source_navvertex: NavvertexIndex, width: f64) -> Trace { +impl TraceStepper { + pub fn new( + source: FixedDotIndex, + source_navvertex: NavvertexIndex, + width: f64, + ) -> TraceStepper { Self { path: vec![source_navvertex], head: BareHead { face: source }.into(), @@ -101,7 +105,7 @@ pub struct TraceStepContext<'a: 'b, 'b, R: AccessRules> { } impl<'a, 'b, R: AccessRules> Step, TracerStatus, TracerException, ()> - for Trace + for TraceStepper { #[debug_ensures(ret.is_ok() -> matches!(self.head, Head::Cane(..)))] #[debug_ensures(ret.is_ok() -> self.path.len() == old(self.path.len() + 1))] @@ -125,7 +129,9 @@ impl<'a, 'b, R: AccessRules> Step, TracerStatus, Tra } } -impl<'a, R: AccessRules> StepBack, TracerStatus, TracerException, ()> for Trace { +impl<'a, R: AccessRules> StepBack, 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 { if let Head::Cane(head) = self.head { diff --git a/src/router/tracer.rs b/src/router/tracer.rs index 4cb1dbb..7ed24b3 100644 --- a/src/router/tracer.rs +++ b/src/router/tracer.rs @@ -10,7 +10,7 @@ use crate::{ use super::{ draw::{Draw, DrawException}, navmesh::{Navmesh, NavvertexIndex}, - trace::{Trace, TraceStepContext}, + trace::{TraceStepContext, TraceStepper}, }; #[derive(Error, Debug, Clone, Copy)] @@ -51,14 +51,14 @@ impl<'a, R: AccessRules> Tracer<'a, R> { source: FixedDotIndex, source_navvertex: NavvertexIndex, width: f64, - ) -> Trace { - Trace::new(source, source_navvertex, width) + ) -> TraceStepper { + TraceStepper::new(source, source_navvertex, width) } pub fn finish( &mut self, _navmesh: &Navmesh, - trace: &mut Trace, + trace: &mut TraceStepper, target: FixedDotIndex, width: f64, ) -> Result { @@ -70,7 +70,7 @@ impl<'a, R: AccessRules> Tracer<'a, R> { pub fn rework_path( &mut self, navmesh: &Navmesh, - trace: &mut Trace, + trace: &mut TraceStepper, path: &[NavvertexIndex], width: f64, ) -> Result<(), TracerException> { @@ -90,7 +90,7 @@ impl<'a, R: AccessRules> Tracer<'a, R> { pub fn path( &mut self, navmesh: &Navmesh, - trace: &mut Trace, + trace: &mut TraceStepper, path: &[NavvertexIndex], width: f64, ) -> Result<(), TracerException> { @@ -110,7 +110,7 @@ impl<'a, R: AccessRules> Tracer<'a, R> { } #[debug_ensures(trace.path.len() == old(trace.path.len() - step_count))] - pub fn undo_path(&mut self, trace: &mut Trace, step_count: usize) { + pub fn undo_path(&mut self, trace: &mut TraceStepper, step_count: usize) { for _ in 0..step_count { let _ = trace.step_back(self); } diff --git a/tests/multilayer.rs b/tests/multilayer.rs index cbbb09f..a369ebb 100644 --- a/tests/multilayer.rs +++ b/tests/multilayer.rs @@ -1,5 +1,5 @@ use topola::{ - autorouter::{execute::Command, invoker::InvokerError, AutorouterError}, + autorouter::{command::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 f6c837a..a0ea5ad 100644 --- a/tests/single_layer.rs +++ b/tests/single_layer.rs @@ -1,6 +1,6 @@ use topola::{ autorouter::{ - execute::Command, + command::Command, invoker::{Invoker, InvokerError}, AutorouterError, },