Layout¶
Diagram layout engine for positioning devices and routing wires.
layout ¶
Layout engine for positioning components and routing wires.
LayoutConfig
dataclass
¶
LayoutConfig(
board_margin_left: float = 40.0,
board_margin_top: float = 40.0,
device_area_left: float = 450.0,
device_spacing_vertical: float = 20.0,
device_margin_top: float = 60.0,
rail_offset: float = 40.0,
wire_spacing: float = 8.0,
bundle_spacing: float = 4.0,
corner_radius: float = 5.0,
legend_margin: float = 20.0,
legend_width: float = 150.0,
legend_height: float = 120.0,
pin_number_y_offset: float = 12.0,
gpio_diagram_width: float = 125.0,
gpio_diagram_margin: float = 40.0,
)
Configuration parameters for diagram layout.
Controls spacing, margins, and visual parameters for the diagram layout engine. All measurements are in SVG units (typically pixels).
| ATTRIBUTE | DESCRIPTION |
|---|---|
board_margin_left |
Left margin before board (default: 40.0)
TYPE:
|
board_margin_top |
Top margin before board (default: 40.0)
TYPE:
|
device_area_left |
X position where devices start (default: 450.0)
TYPE:
|
device_spacing_vertical |
Vertical space between stacked devices (default: 20.0)
TYPE:
|
device_margin_top |
Top margin for first device (default: 60.0)
TYPE:
|
rail_offset |
Horizontal distance from board to wire routing rail (default: 40.0)
TYPE:
|
wire_spacing |
Minimum vertical spacing between parallel wires (default: 8.0)
TYPE:
|
bundle_spacing |
Spacing between wire bundles (default: 4.0)
TYPE:
|
corner_radius |
Radius for wire corner rounding (default: 5.0)
TYPE:
|
legend_margin |
Margin around legend box (default: 20.0)
TYPE:
|
legend_width |
Width of legend box (default: 150.0)
TYPE:
|
legend_height |
Height of legend box (default: 120.0)
TYPE:
|
pin_number_y_offset |
Vertical offset for pin number circles (default: 12.0)
TYPE:
|
gpio_diagram_width |
Width of GPIO reference diagram (default: 125.0)
TYPE:
|
gpio_diagram_margin |
Margin around GPIO reference diagram (default: 40.0)
TYPE:
|
LayoutEngine ¶
Calculate positions and wire routing for diagram components.
The layout engine handles the algorithmic placement of devices and routing of wires between board pins and device pins. It uses a "rail" system where wires route horizontally to a vertical rail, then along the rail, then horizontally to the device.
Wire routing features
- Automatic offset for parallel wires from the same pin
- Rounded corners for professional appearance
- Multiple routing styles (orthogonal, curved, mixed)
- Optimized path calculation to minimize overlaps
Initialize layout engine with optional configuration.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Layout configuration parameters. If None, uses default LayoutConfig.
TYPE:
|
Source code in src/pinviz/layout.py
layout_diagram ¶
Calculate layout for a complete diagram.
| PARAMETER | DESCRIPTION |
|---|---|
diagram
|
The diagram to layout
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float, list[RoutedWire]]
|
Tuple of (canvas_width, canvas_height, routed_wires) |
Source code in src/pinviz/layout.py
RoutedWire
dataclass
¶
RoutedWire(
connection: Connection,
path_points: list[Point],
color: str,
from_pin_pos: Point,
to_pin_pos: Point,
)
A wire connection with calculated routing path.
Contains the complete routing information for a wire, including all waypoints along its path. This is the result of the layout engine's wire routing algorithm.
| ATTRIBUTE | DESCRIPTION |
|---|---|
connection |
The original connection specification
TYPE:
|
path_points |
List of points defining the wire path (min 2 points)
TYPE:
|
color |
Wire color as hex code (from connection or auto-assigned)
TYPE:
|
from_pin_pos |
Absolute position of source pin on board
TYPE:
|
to_pin_pos |
Absolute position of destination pin on device
TYPE:
|
create_bezier_path ¶
Create an SVG path string with rounded corners.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
List of points defining the path
TYPE:
|
corner_radius
|
Radius for rounded corners
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
SVG path d attribute string |