mirror of https://codeberg.org/topola/topola.git
Autorouter: initial autoroute.rs docs
This commit is contained in:
parent
c9509d8336
commit
00cea36f29
|
|
@ -1,3 +1,6 @@
|
||||||
|
//! Manages autorouting of ratlines in a layout, tracking status and processed
|
||||||
|
//! routing steps. Provides access to navigation meshes, traces, ghost shapes,
|
||||||
|
//! and obstacles encountered during routing.
|
||||||
use petgraph::graph::EdgeIndex;
|
use petgraph::graph::EdgeIndex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -13,14 +16,26 @@ use super::{
|
||||||
Autorouter, AutorouterError, AutorouterOptions,
|
Autorouter, AutorouterError, AutorouterOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Represents the current status of the autoroute operation.
|
||||||
|
///
|
||||||
|
/// This enum tracks the different states of the autoroute process.
|
||||||
pub enum AutorouteStatus {
|
pub enum AutorouteStatus {
|
||||||
|
/// The autoroute is currently running and in progress.
|
||||||
Running,
|
Running,
|
||||||
|
/// A specific segment has been successfully routed.
|
||||||
Routed(BandTermsegIndex),
|
Routed(BandTermsegIndex),
|
||||||
|
/// The autoroute process has completed successfully.
|
||||||
Finished,
|
Finished,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl TryInto<()> for AutorouteStatus {
|
impl TryInto<()> for AutorouteStatus {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
/// Attempts to get the [`Result`] from the [`AutorouteStatus`].
|
||||||
|
///
|
||||||
|
/// This implementation allows transitioning from [`AutorouteStatus`] to a
|
||||||
|
/// [`Result`]. It returns success for the [`AutorouteStatus::Finished`] state
|
||||||
|
/// or an error for [`AutorouteStatus::Running`] or [`AutorouteStatus::Routed`] states.
|
||||||
fn try_into(self) -> Result<(), ()> {
|
fn try_into(self) -> Result<(), ()> {
|
||||||
match self {
|
match self {
|
||||||
AutorouteStatus::Running => Err(()),
|
AutorouteStatus::Running => Err(()),
|
||||||
|
|
@ -30,14 +45,28 @@ impl TryInto<()> for AutorouteStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Manages the autorouting process across multiple ratlines.
|
||||||
|
///
|
||||||
|
/// Consist routing logic for each
|
||||||
|
/// ratline while managing its options as well as
|
||||||
|
/// the current route state.
|
||||||
pub struct AutorouteExecutionStepper {
|
pub struct AutorouteExecutionStepper {
|
||||||
|
/// An iterator over ratlines that tracks which segments still need to be routed.
|
||||||
ratlines_iter: Box<dyn Iterator<Item = EdgeIndex<usize>>>,
|
ratlines_iter: Box<dyn Iterator<Item = EdgeIndex<usize>>>,
|
||||||
|
/// The options for the autorouting process, defining how routing should be carried out.
|
||||||
options: AutorouterOptions,
|
options: AutorouterOptions,
|
||||||
|
/// Stores the current route being processed, if any.
|
||||||
route: Option<RouteStepper>,
|
route: Option<RouteStepper>,
|
||||||
|
/// Keeps track of the current ratline being routed, if one is active.
|
||||||
curr_ratline: Option<EdgeIndex<usize>>,
|
curr_ratline: Option<EdgeIndex<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AutorouteExecutionStepper {
|
impl AutorouteExecutionStepper {
|
||||||
|
/// Initializes a new [`AutorouteExecutionStepper`] instance.
|
||||||
|
///
|
||||||
|
/// This method sets up the routing process by accepting the execution properties.
|
||||||
|
/// It prepares the first ratline to route
|
||||||
|
/// and stores the associated data for future routing steps.
|
||||||
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,
|
||||||
|
|
@ -120,24 +149,28 @@ impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus, AutorouterError, ()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetMaybeNavmesh for AutorouteExecutionStepper {
|
impl GetMaybeNavmesh for AutorouteExecutionStepper {
|
||||||
|
/// Retrieves an optional reference to the navigation mesh from the current route.
|
||||||
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 AutorouteExecutionStepper {
|
impl GetMaybeTrace for AutorouteExecutionStepper {
|
||||||
|
/// Retrieves an optional reference to the trace from the current route.
|
||||||
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 AutorouteExecutionStepper {
|
impl GetGhosts for AutorouteExecutionStepper {
|
||||||
|
/// Retrieves ghost shapes from the current route.
|
||||||
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 AutorouteExecutionStepper {
|
impl GetObstacles for AutorouteExecutionStepper {
|
||||||
|
/// Retrieves obstacles encountered during routing.
|
||||||
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())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue