Router
Router
A class for routing channels in a 3D component using various methods. This class provides methods for autorouting, manual routing with polychannels, and routing with fractional paths. It also manages keepouts and bounding boxes for the component and its subcomponents.
__init__
__init__(
component: "Component",
channel_size: tuple[int, int, int] = (0, 0, 0),
channel_margin: tuple[int, int, int] = (0, 0, 0),
quiet: bool = False,
)
Initializes the Router with a component and channel specifications.
Parameters:
- component: The Component instance to route channels within.
- channel_size: The size of the channels to be routed (tuple of 3 ints).
- channel_margin: The margin to apply around the channels (tuple of 3 ints).
- quiet: If True, suppresses informational output.
autoroute_channel
autoroute_channel(
input_port: "Port" | str,
output_port: "Port" | str,
label: str,
timeout: int = 120,
heuristic_weight: int = 10,
turn_weight: int = 2,
direction_preference: tuple[str] = ("X", "Y", "Z"),
)
Automatically routes a channel between two ports using A* algorithm.
Parameters:
- input_port: The Port instance where the channel starts.
- output_port: The Port instance where the channel ends.
- label: A label for the routed channel.
- timeout: The maximum time allowed for the routing operation (in seconds).
- heuristic_weight: Weighting factor for the heuristic in the A* algorithm.
- turn_weight: Weighting factor for the number of turns in the A* algorithm.
Raises:
- ValueError: If either port has not been added to the component before routing.
finalize_routes
finalize_routes()
Routes all defined channels in the component. This method checks for cached routes, loads them if valid, and reroutes if necessary. It handles both manual routing with polychannels and autorouting using the A* algorithm.
route_with_fractional_path
route_with_fractional_path(
input_port: "Port" | str,
output_port: "Port" | str,
route: list[tuple[float, float, float]],
label: str,
)
Routes a channel between two ports using a fractional path.
Parameters:
- input_port: The Port instance where the channel starts.
- output_port: The Port instance where the channel ends.
- route: A list of tuples representing the fractional path segments (each tuple contains three floats) the sum of each digit must add to 1.0.
- label: A label for the routed channel.
Raises:
- ValueError: If either port has not been added to the component before routing.
route_with_polychannel
route_with_polychannel(
input_port: "Port" | str,
output_port: "Port" | str,
polychannel_shapes: list[
Union[PolychannelShape, BezierCurveShape]
],
label: str,
)
Routes a channel between two ports using a specified polychannel path.
Parameters:
- input_port: The Port instance where the channel starts.
- output_port: The Port instance where the channel ends.
- polychannel_shapes: A list of PolychannelShape or BezierCurveShape instances defining the channel path.
- label: A label for the routed channel.
Raises:
- ValueError: If either port has not been added to the component before routing.