Skip to content

Commit

Permalink
[BoM][Added] KiCad internal BoM special fields
Browse files Browse the repository at this point in the history
At least all the ones I found, trying to make them to behave like in KiCad
  • Loading branch information
set-soft committed Oct 30, 2024
1 parent 3404895 commit 6cd4811
Show file tree
Hide file tree
Showing 9 changed files with 1,436 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.8.3] - UNRELEASED
### Added
- BoM:
- Field aliases ${QUANTITY} and ${ITEM_NUMBER} for compatibility with
KiCad's internal BoM.
- Fields ${DNP}, ${EXCLUDE_FROM_BOARD} and ${EXCLUDE_FROM_SIM}, like
the ones used by KiCad's internal BoM.
- PCB Print: a mechanism to filter components for a particular layer (#706)


Expand Down
7 changes: 7 additions & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Versioning <https://semver.org/spec/v2.0.0.html>`__.
Added
~~~~~

- BoM:

- Field aliases ${QUANTITY} and ${ITEM_NUMBER} for compatibility
with KiCad’s internal BoM.
- Fields ${DNP}, ${EXCLUDE_FROM_BOARD} and ${EXCLUDE_FROM_SIM}, like
the ones used by KiCad’s internal BoM.

- PCB Print: a mechanism to filter components for a particular layer
(#706)

Expand Down
29 changes: 18 additions & 11 deletions docs/source/configuration/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -671,34 +671,41 @@ Columns available for the BoM

In addition to all the user defined fields you also have the following columns:

- **References**: The component references.
- **Build Quantity**: How many components we use for this row for all the PCBs.
- **Datasheet**: The datasheet from the standard field.
- **Description**: The description from the component library (DCM file).
Note that a user field with the same name has more precedence.
- **Value**: The value for the component. Affected by the **normalize_values** option.
- **${DNP}**: Is **DNP** when the schematic DNP attribute is enabled, for compatibility with KiCad BoM.
- **${EXCLUDE_FROM_BOARD}**: Is **Excluded from board** when the schematic *exclude from board*
attribute is enabled, for compatibility with KiCad BoM.
- **${EXCLUDE_FROM_SIM}**: Is **Excluded from simulation** when the schematic *exclude from simulation*
attribute is enabled, for compatibility with KiCad BoM.
- **Footprint**: The name of the footprint, without the library name.
- **Footprint Lib**: The name of the library for the footprint.
- **Footprint X**: The X coordinate for the footprint.
- **Footprint Y**: The Y coordinate for the footprint.
- **Footprint Populate**: If the footprint is populated (soldered) or not, can be: *yes* or *no*.
Affected by the **footprint_populate_values** option.
- **Footprint Rot**: The rotation angle for the footprint.
- **Footprint Side**: The side of the footprint, *bottom* or *top*.
- **Footprint Type**: The type of the footprint, can be: *SMD*, *THT* or *VIRTUAL*.
- **Footprint Type NV**: The type of the footprint, can be: *SMD* or *THT*. Empty if not defined.
Affected by the **footprint_type_values** option.
- **Footprint Populate**: If the footprint is populated (soldered) or not, can be: *yes* or *no*.
Affected by the **footprint_populate_values** option.
- **Footprint X**: The X coordinate for the footprint.
- **Footprint Y**: The Y coordinate for the footprint.
- **Footprint X-Size**: The footprint width, no rotation computed.
- **Footprint Y-Size**: The footprint height, no rotation computed.
- **${ITEM_NUMBER}**: Same as **Row**, for compatibility with KiCad BoM.
- **Net Name**: Name of the nets associated with the footprint. Useful for testpoints.
- **Net Class**: Name of the net classes associated with the footprint. Useful for testpoints.
- **Part**: The name of the symbol for the component, without the library name.
- **Part Lib**: The name of the library for the symbol.
- **Datasheet**: The datasheet from the standard field.
- **Sheetpath**: The path in the schematic hierarchy for the component.
- **Row**: The row number in the BoM for this entry.
- **Status**: The DNF (Do Not Fit) and/or DNC (Do Not Change) status for the component.
- **${QUANTITY}**: Same as **Quantity Per PCB**, for compatibility with KiCad BoM.
- **Quantity Per PCB**: How many components we use for this row for each PCB.
- **Build Quantity**: How many components we use for this row for all the PCBs.
- **References**: The component references.
- **Row**: The row number in the BoM for this entry.
- **Sheetpath**: The path in the schematic hierarchy for the component.
- **Source BoM**: From which BoM/s comes this component/s. This is used when consolidating more than one BoM.
- **Status**: The DNF (Do Not Fit) and/or DNC (Do Not Change) status for the component.
- **Value**: The value for the component. Affected by the **normalize_values** option.

Most of the footprint columns are oriented to the creation of position files using the BoM output,
for more information consult :ref:`xyrs_files`.
Expand Down
14 changes: 11 additions & 3 deletions kibot/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def update_fields(self, conv, bottom_negative_x, x_origin, y_origin, angle_posit
else:
self.fields[ColumnList.COL_REFERENCE_L] = self.get_refs()
# Quantity
self.fields[ColumnList.COL_GRP_QUANTITY_L] = str(self.get_count())
self.fields[ColumnList.COL_QUANTITY_L] = self.fields[ColumnList.COL_GRP_QUANTITY_L] = str(self.get_count())
self.total = self.get_build_count()
self.fields[ColumnList.COL_GRP_BUILD_QUANTITY_L] = str(self.total)
self.fields[ColumnList.COL_SOURCE_BOM_L] = self.get_sources()
Expand Down Expand Up @@ -366,6 +366,12 @@ def update_fields(self, conv, bottom_negative_x, x_origin, y_origin, angle_posit
self.fields[ColumnList.COL_DESCRIPTION_L] = comp.desc
self.fields[ColumnList.COL_NET_NAME_L] = comp.net_name
self.fields[ColumnList.COL_NET_CLASS_L] = comp.net_class
# KiCad attributes
self.fields[ColumnList.COL_DNP_L] = ("DNP" if comp.kicad_dnp else "") if hasattr(comp, 'kicad_dnp') else 'Unknown'
self.fields[ColumnList.COL_EXCLUDE_FROM_BOARD_L] = (("Excluded from board" if not comp.on_board else "")
if hasattr(comp, 'on_board') else 'Unknown')
self.fields[ColumnList.COL_EXCLUDE_FROM_SIM_L] = (("Excluded from simulation" if comp.exclude_from_sim else "")
if hasattr(comp, 'exclude_from_sim') else 'Unknown')

def get_row(self, columns):
""" Return a dict of the KiCad data based on the supplied columns """
Expand Down Expand Up @@ -500,10 +506,12 @@ def group_components(cfg, components):
for g in groups:
is_fitted = g.is_fitted()
if cfg.ignore_dnf and not is_fitted:
g.update_field('Row', str(dnf))
g.update_field(ColumnList.COL_ROW_NUMBER, str(dnf))
g.update_field(ColumnList.COL_ITEM_NUMBER, str(dnf))
dnf += 1
else:
g.update_field('Row', str(c))
g.update_field(ColumnList.COL_ROW_NUMBER, str(c))
g.update_field(ColumnList.COL_ITEM_NUMBER, str(c))
c += 1
# Stats
g_l = g.get_count()
Expand Down
38 changes: 30 additions & 8 deletions kibot/bom/columnlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,42 @@ class ColumnList:
COL_SHEETPATH_L = COL_SHEETPATH.lower()
COL_ROW_NUMBER = 'Row'
COL_ROW_NUMBER_L = COL_ROW_NUMBER.lower()
# KiCad version of Row
COL_ITEM_NUMBER = '${ITEM_NUMBER}'
COL_ITEM_NUMBER_L = COL_ROW_NUMBER.lower()
COL_STATUS = 'Status'
COL_STATUS_L = COL_STATUS.lower()
COL_NET_NAME = 'Net Name'
COL_NET_NAME_L = COL_NET_NAME.lower()
COL_NET_CLASS = 'Net Class'
COL_NET_CLASS_L = COL_NET_CLASS.lower()
# KiCad attributes
COL_DNP = '${DNP}'
COL_DNP_L = COL_DNP.lower()
COL_EXCLUDE_FROM_BOARD = '${EXCLUDE_FROM_BOARD}'
COL_EXCLUDE_FROM_BOARD_L = COL_EXCLUDE_FROM_BOARD.lower()
COL_EXCLUDE_FROM_SIM = '${EXCLUDE_FROM_SIM}'
COL_EXCLUDE_FROM_SIM_L = COL_EXCLUDE_FROM_SIM.lower()

# Default columns for groups
COL_GRP_QUANTITY = 'Quantity Per PCB'
COL_GRP_QUANTITY_L = COL_GRP_QUANTITY.lower()
# KiCad version of 'Quantity Per PCB'
COL_QUANTITY = '${QUANTITY}'
COL_QUANTITY_L = COL_QUANTITY.lower()
COL_GRP_BUILD_QUANTITY = 'Build Quantity'
COL_GRP_BUILD_QUANTITY_L = COL_GRP_BUILD_QUANTITY.lower()
COL_SOURCE_BOM = 'Source BoM'
COL_SOURCE_BOM_L = COL_SOURCE_BOM.lower()

# Generated columns
COLUMNS_GEN_L = {
COL_GRP_QUANTITY_L: 1,
COL_GRP_BUILD_QUANTITY_L: 1,
COL_ROW_NUMBER_L: 1,
COL_STATUS_L: 1,
COL_SOURCE_BOM_L: 1,
COL_GRP_QUANTITY_L,
COL_GRP_BUILD_QUANTITY_L,
COL_ROW_NUMBER_L,
COL_ITEM_NUMBER_L,
COL_STATUS_L,
COL_SOURCE_BOM_L,
}

# Default columns
Expand Down Expand Up @@ -115,6 +129,9 @@ class ColumnList:

# Not included by default
COLUMNS_EXTRA = [
COL_DNP,
COL_EXCLUDE_FROM_BOARD,
COL_EXCLUDE_FROM_SIM,
COL_FP_X,
COL_FP_Y,
COL_FP_ROT,
Expand All @@ -124,20 +141,22 @@ class ColumnList:
COL_FP_FIT,
COL_FP_XS,
COL_FP_YS,
COL_ITEM_NUMBER,
COL_NET_NAME,
COL_NET_CLASS,
COL_QUANTITY,
]

# Default columns
# These columns are 'immutable'
COLUMNS_PROTECTED_L = {
COL_REFERENCE_L[:-1], # The column is References and the field Reference
COL_REFERENCE_L, # The column is References and the field Reference
COL_GRP_QUANTITY_L,
COL_QUANTITY_L,
COL_VALUE_L,
COL_PART_L,
COL_PART_LIB_L,
# COL_DESCRIPTION_L: 1,
# COL_DESCRIPTION_L,
COL_DATASHEET_L,
COL_SHEETPATH_L,
COL_FP_L,
Expand All @@ -149,7 +168,10 @@ class ColumnList:
COL_FP_FIT_L,
COL_FP_XS_L,
COL_FP_YS_L,
COL_FP_LIB_L
COL_FP_LIB_L,
COL_DNP_L,
COL_EXCLUDE_FROM_BOARD_L,
COL_EXCLUDE_FROM_SIM_L,
}

# Default fields used to group components
Expand Down
Loading

0 comments on commit 6cd4811

Please sign in to comment.