padne.kicad¶
Attributes¶
Classes¶
Represents a single directive in the schematic. |
|
This class effectively serves as a mapper from Endpoint to a bunch of LayerPoints |
|
Represents a base class that specifies a _single_ lumped element |
|
Represents a base class that specifies a _single_ lumped element |
|
Represents a base class that specifies a _single_ lumped element |
|
Represents a base class that specifies a _single_ lumped element |
|
Represents a base class that specifies a _single_ lumped element |
|
Specifies pads at which a mesh vertex must be forced, without adding any |
|
Specifies custom copper conductivity for the project. |
|
Specifies a via in the PCB. |
|
Represents a KiCad project with paths to its component files. |
|
Accumulates different directive types that can be present in the schematic. |
|
Represents a schematic instance in the hierarchy. |
|
Functions¶
|
Find and return the pcbnew module using multiple strategies. |
|
|
|
|
Convert Polygon to MultiPolygon if needed, ensuring consistent interface. |
|
|
Iterate over layer IDs of copper layers in the given KiCad board. |
|
Extract the stackup from a KiCad PCB file. |
|
Extract via specifications from a KiCad PCB. |
|
Extract through-hole pad specifications from a KiCad PCB. |
|
Parse an endpoint in the format DESIGNATOR.PAD. |
|
|
|
Build the complete schematic hierarchy starting from a root schematic. |
|
Flatten a schema hierarchy into a list of all instances. |
|
Extract directives from a text string that may contain multiple lines. |
|
|
|
Extract all directives from a schematic hierarchy. |
|
Generate Gerber files from a KiCad PCB file and convert them to PlottedGerberLayer objects. |
|
Plot copper layers of a KiCad board to Gerber files. |
|
|
Loads data from a Gerber file and converts it to a Shapely geometry. |
|
|
Extract geometry from Gerber files and create PlottedGerberLayer objects. |
Extract board outline from a KiCad PCB. This uses the internal KiCad outline processing. |
|
|
|
|
|
Verify that all plotted layers are contained within the stackup. |
|
|
Construct a dictionary mapping layer names to Layer objects. |
|
Clip a plotted layer's geometry with the board outline. |
|
Load a KiCad project and create a Problem object for PDN simulation. |
Module Contents¶
- padne.kicad.find_pcbnew_module() Any[source]¶
Find and return the pcbnew module using multiple strategies.
Strategy order: 1. Try direct import of pcbnew (works when running inside KiCad or with system Python) 2. Try using kigadgets.get_pcbnew_module() (works in virtual environments)
- Returns:
The pcbnew module
- Raises:
ImportError: If pcbnew cannot be found via any method
- padne.kicad.ensure_geometry_is_multipolygon(geometry: shapely.geometry.Polygon | shapely.geometry.MultiPolygon) shapely.geometry.MultiPolygon[source]¶
Convert Polygon to MultiPolygon if needed, ensuring consistent interface.
- class padne.kicad.StackupItem[source]¶
- class Type(*args, **kwds)[source]¶
Bases:
enum.EnumCreate a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
attribute access:
>>> Color.RED <Color.RED: 1>
value lookup:
>>> Color(1) <Color.RED: 1>
name lookup:
>>> Color['RED'] <Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
- padne.kicad.copper_layers(board: pcbnew) Iterator[int][source]¶
Iterate over layer IDs of copper layers in the given KiCad board.
- padne.kicad.extract_stackup_from_kicad_pcb(board: pcbnew, copper_conductivity: float = COPPER_CONDUCTIVITY) Stackup[source]¶
Extract the stackup from a KiCad PCB file.
- Args:
board: KiCad board object copper_conductivity: Optional custom copper conductivity in S/mm.
If None, uses COPPER_CONDUCTIVITY constant.
- class padne.kicad.Directive[source]¶
Represents a single directive in the schematic.
- classmethod parse(directive: str) Directive[source]¶
Parse a directive string with key-value pairs into a Directive object.
Format: !padne DIRECTIVE_NAME key1=value1 key2=value2 …
- Args:
directive: The directive string to parse
- Returns:
A Directive object with the parsed name and parameters
- Raises:
ValueError: If the directive format is invalid
- class padne.kicad.PadIndex[source]¶
This class effectively serves as a mapper from Endpoint to a bunch of LayerPoints that can then be used to construct a problem.Connection object.
- find_by_endpoint(ep: Endpoint) list[LayerPoint][source]¶
- load_smd_pads(board: pcbnew, layer_dict: dict[str, padne.problem.Layer]) None[source]¶
Load all SMD pads from the given PCB board into the mapping. Validates that connection points fall within the final layer geometry.
- Args:
board: The PCB board to extract SMD pads from layer_dict: Dictionary of final layer geometries for validation
- insert_via_specs(via_specs: list[ViaSpec], layer_dict: dict[str, padne.problem.Layer]) None[source]¶
Insert via specifications into the mapping. Uses all boundary points of the via shape for all layers it connects.
- Args:
via_specs: List of via specifications to insert layer_dict: Dictionary of final layer geometries for validation
- class padne.kicad.BaseLumpedSpec[source]¶
Represents a base class that specifies a _single_ lumped element being wired to a bunch of pads on the PCB.
- classmethod from_directive(directive: Directive) BaseLumpedSpec[source]¶
Parse a directive into a BaseLumpedSpec object.
- Args:
directive: The directive to parse
- Returns:
A BaseLumpedSpec object with parsed endpoints and values
- construct(pad_index: PadIndex, layer_dict: dict[str, padne.problem.Layer]) padne.problem.BaseLumped[source]¶
Constructs a problem.BaseLumped element from the current specification. This method should be implemented in subclasses to create the specific type of lumped element.
- class padne.kicad.ResistorSpec[source]¶
Bases:
BaseLumpedSpecRepresents a base class that specifies a _single_ lumped element being wired to a bunch of pads on the PCB.
- class padne.kicad.VoltageSourceSpec[source]¶
Bases:
BaseLumpedSpecRepresents a base class that specifies a _single_ lumped element being wired to a bunch of pads on the PCB.
- construct(pad_index: PadIndex, layer_dict: dict[str, padne.problem.Layer]) padne.problem.Network[source]¶
Custom construct method for voltage sources that properly handles multiple endpoints without introducing coupling resistance.
Strategy: 1. Create main voltage source between first positive and first negative endpoints 2. Create 0V voltage sources to connect additional endpoints to the first ones
- class padne.kicad.CurrentSourceSpec[source]¶
Bases:
BaseLumpedSpecRepresents a base class that specifies a _single_ lumped element being wired to a bunch of pads on the PCB.
- class padne.kicad.RegulatorSpec[source]¶
Bases:
BaseLumpedSpecRepresents a base class that specifies a _single_ lumped element being wired to a bunch of pads on the PCB.
- class padne.kicad.ProbeSpec[source]¶
Specifies pads at which a mesh vertex must be forced, without adding any electrical element. Each pad becomes a single-connection Network so the mesher seeds a vertex exactly at the pad center.
- construct(pad_index: PadIndex, layer_dict: dict[str, padne.problem.Layer]) list[padne.problem.Network][source]¶
- class padne.kicad.CopperSpec[source]¶
Specifies custom copper conductivity for the project.
- classmethod from_directive(directive: Directive) CopperSpec[source]¶
Parse a COPPER directive into a CopperSpec object.
- Args:
directive: The directive to parse
- Returns:
A CopperSpec object with parsed conductivity
- Raises:
ValueError: If conductivity parameter is missing or invalid
- class padne.kicad.KiCadProject[source]¶
Represents a KiCad project with paths to its component files.
- pro_path: pathlib.Path[source]¶
- pcb_path: pathlib.Path[source]¶
- sch_path: pathlib.Path[source]¶
- classmethod from_pro_file(pro_file_path: pathlib.Path) KiCadProject[source]¶
Create a KiCadProject from a .kicad_pro file path.
- Args:
pro_file_path: Path to the KiCad project file (*.kicad_pro)
- Returns:
A KiCadProject instance with validated file paths
- Raises:
FileNotFoundError: If any required files are missing
- padne.kicad.extract_via_specs_from_pcb(board: pcbnew) list[ViaSpec][source]¶
Extract via specifications from a KiCad PCB.
- Args:
board: The KiCad board object
- Returns:
A list of ViaSpec objects containing information about vias in the PCB
- padne.kicad.extract_tht_pad_specs_from_pcb(board: pcbnew) list[ViaSpec][source]¶
Extract through-hole pad specifications from a KiCad PCB.
- Args:
board: The KiCad board object
- Returns:
A list of ViaSpec objects representing through-hole pads in the PCB
- class padne.kicad.Directives[source]¶
Accumulates different directive types that can be present in the schematic.
- lumped_specs: list[BaseLumpedSpec][source]¶
- copper_spec: CopperSpec | None = None[source]¶
- class padne.kicad.SchemaInstance[source]¶
Represents a schematic instance in the hierarchy.
- file_path: pathlib.Path[source]¶
- child_instances: list[SchemaInstance] = [][source]¶
- padne.kicad.parse_endpoint(token: str) Endpoint[source]¶
Parse an endpoint in the format DESIGNATOR.PAD. For example, “R1.1” will become Endpoint(designator=”R1”, pad=”1”).
- padne.kicad.process_directives(directives: list[Directive]) Directives[source]¶
- padne.kicad.build_schema_hierarchy(sch_file_path: pathlib.Path, sheet_name: str = 'Root') SchemaInstance[source]¶
Build the complete schematic hierarchy starting from a root schematic.
- padne.kicad.flatten_schema_hierarchy(schema_instance: SchemaInstance) list[SchemaInstance][source]¶
Flatten a schema hierarchy into a list of all instances.
- Args:
schema_instance: Root schema instance
- Returns:
List of all schema instances in the hierarchy (root first, then children)
- padne.kicad.extract_directives_from_text(text: str) list[Directive][source]¶
Extract directives from a text string that may contain multiple lines.
Each line is stripped of whitespace and checked if it starts with ‘!padne’. Lines that don’t start with ‘!padne’ are ignored.
Note: KiCad standardizes newlines to ‘
- ‘ in .kicad_sch files regardless of the
platform, so we can safely use splitlines() without worrying about mixed endings.
- Args:
text: The text string to parse for directives
- Returns:
List of Directive objects found in the text
- padne.kicad.extract_directives_from_schema(instance: SchemaInstance) list[Directive][source]¶
- padne.kicad.extract_directives_from_hierarchy(schema_instance: SchemaInstance) list[Directive][source]¶
Extract all directives from a schematic hierarchy.
- Args:
schema_instance: Root of the schematic hierarchy
- Returns:
List of all directives found in the hierarchy (deduplicated by file path)
- padne.kicad.render_gerbers_from_kicad(board: pcbnew, layer_ids: Iterable[int]) list[PlottedGerberLayer][source]¶
Generate Gerber files from a KiCad PCB file and convert them to PlottedGerberLayer objects.
- Args:
pcb_file_path: Path to the KiCad PCB file
- Returns:
List of PlottedGerberLayer objects containing layer geometries
- padne.kicad.plot_board_layer_to_gerber(board: pcbnew, layer_id: int, output_path: pathlib.Path)[source]¶
Plot copper layers of a KiCad board to Gerber files.
- Args:
board: KiCad board object output_dir: Directory where Gerber files will be saved
- Returns:
Dictionary mapping layer IDs to paths of generated Gerber files
- padne.kicad.render_with_shapely(gerber_data: pygerber.gerber.api.GerberFile) shapely.geometry.MultiPolygon[source]¶
- padne.kicad.gerber_file_to_shapely(gerber_path: pathlib.Path) shapely.geometry.MultiPolygon | None[source]¶
Loads data from a Gerber file and converts it to a Shapely geometry.
- padne.kicad.extract_layers_from_gerbers(board, gerber_layers: dict[int, pathlib.Path]) list[PlottedGerberLayer][source]¶
Extract geometry from Gerber files and create PlottedGerberLayer objects.
- Args:
board: KiCad board object (for layer names) gerber_layers: Dictionary mapping layer IDs to paths of Gerber files
- Returns:
List of PlottedGerberLayer objects
- padne.kicad.extract_board_outline(board: pcbnew) shapely.geometry.MultiPolygon | None[source]¶
Extract board outline from a KiCad PCB. This uses the internal KiCad outline processing.
- padne.kicad.process_via_spec(via_spec: ViaSpec, layer_dict: dict[str, padne.problem.Layer], stackup: Stackup) list[padne.problem.Network][source]¶
- padne.kicad.punch_via_holes(plotted_layers: list[PlottedGerberLayer], via_specs: list[ViaSpec]) list[PlottedGerberLayer][source]¶
- padne.kicad.verify_stackup_contains_all_layers(stackup: Stackup, plotted_layers: list[PlottedGerberLayer]) bool[source]¶
Verify that all plotted layers are contained within the stackup.
- Args:
stackup: Stackup object containing layers plotted_layers: List of PlottedGerberLayer objects
- Raises:
ValueError: If any plotted layer is not found in the stackup
- padne.kicad.construct_layer_dict(plotted_layers: list[PlottedGerberLayer], stackup: Stackup) dict[str, padne.problem.Layer][source]¶
Construct a dictionary mapping layer names to Layer objects.
- Args:
plotted_layers: List of PlottedGerberLayer objects
- Returns:
Dictionary mapping layer names to Layer objects
- padne.kicad.clip_layer_with_outline(plotted_layer: PlottedGerberLayer, outline: shapely.geometry.MultiPolygon) PlottedGerberLayer[source]¶
Clip a plotted layer’s geometry with the board outline.
- padne.kicad.load_kicad_project(pro_file_path: pathlib.Path) padne.problem.Problem[source]¶
Load a KiCad project and create a Problem object for PDN simulation.
- Args:
project: Either a path to the KiCad project file (*.kicad_pro) or a KiCadProject instance
- Returns:
A Problem object containing layers and lumped elements
- Raises:
FileNotFoundError: If required files are missing ValueError: If the project contains invalid data