Skip to content

Commit

Permalink
[BoM][Added] Range separator configuration
Browse files Browse the repository at this point in the history
- `ref_range_separator`
- Also `use_ref_ranges` alias for `use_alt`
  • Loading branch information
set-soft committed Oct 31, 2024
1 parent 8310536 commit ab7f55f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New option `sort_ascending` to sort in reverse order
- New sort style: *kicad_bom*, uses the field an ascending used by KiCad's
BoM
- `ref_range_separator` option to configure the character used for reference
ranges
- `use_ref_ranges` alias for `use_alt`
- PCB Print: a mechanism to filter components for a particular layer (#706)

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ outputs:
variant: ''
# BoM (Bill of Materials):
# This output can generate XYRS files (pick and place files).
# You can import the options used in the KiCad internal BoM, consult :ref:`bom_kicad_options`.
# Is compatible with KiBoM, but doesn't need to update the XML netlist because the components
# are loaded from the schematic.
# Important differences with KiBoM output:
# - All options are in the main `options` section, not in `conf` subsection.
# - The `Component` column is named `Row` and works just like any other column.
# This output is what you get from the 'Tools/Generate Bill of Materials' menu in eeschema.
- name: 'bom_example'
comment: 'Used to generate the BoM in CSV, HTML, TSV, TXT, XML or XLSX format using the internal BoM.'
type: 'bom'
Expand Down Expand Up @@ -691,6 +691,8 @@ outputs:
pre_transform: '_null'
# [string=''] A prefix to add to all the references from this project. Used for multiple projects
ref_id: ''
# [string='-'] Separator used for ranges in the list of references. Used when `use_alt` is enabled
ref_range_separator: '-'
# [string=' '] Separator used for the list of references
ref_separator: ' '
# [boolean=true] Sort in ascending order
Expand All @@ -710,6 +712,7 @@ outputs:
use_alt: false
# [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default) (for XYRS)
use_aux_axis_as_origin: true
# `use_ref_ranges` is an alias for `use_alt`
# [string='_kibom_simple'] Board variant, used to determine which components are output to the BoM.
# The `_kibom_simple` variant is a KiBoM variant without any filters and it provides some basic
# compatibility with KiBoM. Note that this output has default filters that behaves like KiBoM.
Expand Down
3 changes: 3 additions & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Added
- New option ``sort_ascending`` to sort in reverse order
- New sort style: *kicad_bom*, uses the field an ascending used by
KiCad’s BoM
- ``ref_range_separator`` option to configure the character used for
reference ranges
- ``use_ref_ranges`` alias for ``use_alt``

- PCB Print: a mechanism to filter components for a particular layer
(#706)
Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuration/outputs/BoMOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ BoMOptions parameters
This option is for simple cases, consider using a full variant for complex cases.

- ``ref_id`` :index:`: <pair: output - bom - options; ref_id>` [:ref:`string <string>`] (default: ``''``) A prefix to add to all the references from this project. Used for multiple projects.
- ``ref_range_separator`` :index:`: <pair: output - bom - options; ref_range_separator>` [:ref:`string <string>`] (default: ``'-'``) Separator used for ranges in the list of references. Used when `use_alt` is enabled.
- ``ref_separator`` :index:`: <pair: output - bom - options; ref_separator>` [:ref:`string <string>`] (default: ``' '``) Separator used for the list of references.
- ``sort_ascending`` :index:`: <pair: output - bom - options; sort_ascending>` [:ref:`boolean <boolean>`] (default: ``true``) Sort in ascending order.
- ``source_by_id`` :index:`: <pair: output - bom - options; source_by_id>` [:ref:`boolean <boolean>`] (default: ``false``) Generate the `Source BoM` column using the reference ID instead of the project name.
- ``use_alt`` :index:`: <pair: output - bom - options; use_alt>` [:ref:`boolean <boolean>`] (default: ``false``) Print grouped references in the alternate compressed style eg: R1-R7,R18.
- ``use_aux_axis_as_origin`` :index:`: <pair: output - bom - options; use_aux_axis_as_origin>` [:ref:`boolean <boolean>`] (default: ``true``) Use the auxiliary axis as origin for coordinates (KiCad default) (for XYRS).
- *use_ref_ranges* :index:`: <pair: output - bom - options; use_ref_ranges>` Alias for use_alt.
- ``variant`` :index:`: <pair: output - bom - options; variant>` [:ref:`string <string>`] (default: ``'_kibom_simple'``) Board variant, used to determine which components are output to the BoM.
The `_kibom_simple` variant is a KiBoM variant without any filters and it provides some basic
compatibility with KiBoM. Note that this output has default filters that behaves like KiBoM. |br|
Expand Down
3 changes: 1 addition & 2 deletions docs/source/configuration/outputs/bom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ BoM (Bill of Materials)

Used to generate the BoM in CSV, HTML, TSV, TXT, XML or XLSX format using the internal BoM.
This output can generate XYRS files (pick and place files). |br|
You can import the options used in the KiCad internal BoM, consult :ref:`bom_kicad_options`. |br|
Is compatible with KiBoM, but doesn't need to update the XML netlist because the components
are loaded from the schematic. |br|
Important differences with KiBoM output:

- All options are in the main `options` section, not in `conf` subsection.
- The `Component` column is named `Row` and works just like any other column.

This output is what you get from the 'Tools/Generate Bill of Materials' menu in eeschema. |br|

Type: ``bom``

Category: **Schematic/BoM**
Expand Down
2 changes: 1 addition & 1 deletion kibot/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def get_alt_refs(self):
for n in self.components:
if n.project == sch.name:
S.add(n.ref_id+n.ref_prefix, _suffix_to_num(n.ref_suffix))
result = S.flush(self.cfg.ref_separator)
result = S.flush(self.cfg.ref_separator, self.cfg.ref_range_separator)
if result:
if refs:
refs += self.cfg.ref_separator
Expand Down
10 changes: 10 additions & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class GS(object):
pro_ext = '.pro'
pro_variables = None # KiCad 6 text variables defined in the project
pro_bom_settings = None # KiCad BoM settings from the project
pro_bom_fmt_settings = None # KiCad BoM file format options
pro_bom_export_filename = '' # KiCad BoM file name, for the extension
vars_regex = re.compile(r'\$\{([^\}]+)\}')
# Main output dir
out_dir = None
Expand Down Expand Up @@ -281,9 +283,17 @@ def load_pro_bom_settings():
GS.exit_with_error('Corrupted project {}'.format(GS.pro_file), CORRUPTED_PRO)
schematic = data.get('schematic', {})
GS.pro_bom_settings = schematic.get('bom_settings', {})
GS.pro_bom_fmt_settings = schematic.get('bom_fmt_settings', {})
GS.pro_bom_export_filename = schematic.get('bom_export_filename', '')
logger.debug("Current bom_settings: {}".format(GS.pro_bom_settings))
return GS.pro_bom_settings

@staticmethod
def load_pro_bom_fmt_settings():
if GS.pro_bom_fmt_settings is None:
GS.load_pro_bom_settings()
return GS.pro_bom_fmt_settings

@staticmethod
def read_pro():
if not GS.pro_file:
Expand Down
12 changes: 8 additions & 4 deletions kibot/out_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ def __init__(self):
""" {no_case} Field name used for internal filters (not for variants) """
self.use_alt = False
""" Print grouped references in the alternate compressed style eg: R1-R7,R18 """
self.use_ref_ranges = None
""" {use_alt} """
self.ref_separator = ' '
""" Separator used for the list of references """
self.ref_range_separator = '-'
""" Separator used for ranges in the list of references. Used when `use_alt` is enabled """
self.columns = BoMColumns
""" *[list(dict)|list(string)=?] List of columns to display.
One entry can be just the name of the field (a string).
Expand All @@ -493,8 +499,6 @@ def __init__(self):
""" *Try to normalize the R, L and C values, producing uniform units and prefixes """
self.normalize_locale = False
""" When normalizing values use the locale decimal point """
self.ref_separator = ' '
""" Separator used for the list of references """
self.html = BoMHTML
""" *[dict={}] Options for the HTML format """
self.xlsx = BoMXLSX
Expand Down Expand Up @@ -1043,12 +1047,12 @@ class BoM(BaseOutput): # noqa: F821
""" BoM (Bill of Materials)
Used to generate the BoM in CSV, HTML, TSV, TXT, XML or XLSX format using the internal BoM.
This output can generate XYRS files (pick and place files).
You can import the options used in the KiCad internal BoM, consult :ref:`bom_kicad_options`.
Is compatible with KiBoM, but doesn't need to update the XML netlist because the components
are loaded from the schematic.
Important differences with KiBoM output:
- All options are in the main `options` section, not in `conf` subsection.
- The `Component` column is named `Row` and works just like any other column.
This output is what you get from the 'Tools/Generate Bill of Materials' menu in eeschema. """
- The `Component` column is named `Row` and works just like any other column. """
def __init__(self):
super().__init__()
with document:
Expand Down

0 comments on commit ab7f55f

Please sign in to comment.