This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c4af44
commit c993d9d
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# This file is part of the faebryk project | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
This file contains BOM generation utilities. | ||
""" | ||
|
||
import logging | ||
|
||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
import faebryk.library._F as F | ||
from faebryk.core.module import Module | ||
from faebryk.libs.picker.picker import DescriptiveProperties | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def print_bom(root_module: Module) -> None: | ||
""" | ||
Print a Bill of Materials table for the given root module. | ||
Args: | ||
root_module: The root module containing the components to list in the BOM | ||
""" | ||
console = Console() | ||
table = Table(title="BOM") | ||
|
||
# Add columns | ||
table.add_column("Name", style="white") | ||
table.add_column("Designator", style="cyan") | ||
table.add_column("Footprint", style="green") | ||
table.add_column("LCSC", style="yellow") | ||
table.add_column("Manufacturer PN", style="magenta") | ||
|
||
components = root_module.get_children_modules(types=(Module,)) | ||
|
||
for comp in components: | ||
# Only process components that have required traits | ||
if not all([ | ||
comp.has_trait(F.has_designator), | ||
comp.has_trait(F.has_footprint), | ||
comp.has_trait(F.has_descriptive_properties) | ||
]): | ||
continue | ||
|
||
# Get component name | ||
comp_name = comp.get_name() | ||
|
||
# Get designator | ||
designator = comp.get_trait(F.has_designator).get_designator() | ||
|
||
# Get footprint | ||
footprint = comp.get_trait(F.has_footprint).get_footprint() | ||
footprint_name = ( | ||
footprint.get_trait(F.has_kicad_footprint).get_kicad_footprint_name() | ||
if footprint.has_trait(F.has_kicad_footprint) | ||
else str(footprint) | ||
) | ||
|
||
# Get part numbers | ||
properties = comp.get_trait(F.has_descriptive_properties).get_properties() | ||
mfr_pn = properties.get(DescriptiveProperties.partno, "N/A") | ||
lcsc_pn = properties.get("LCSC", "N/A") | ||
|
||
# Add row to table | ||
table.add_row( | ||
comp_name, | ||
designator, | ||
footprint_name, | ||
lcsc_pn, | ||
mfr_pn | ||
) | ||
|
||
console.print(table) |