From 0f0e739026ed6113d2f17a235b9ee79046556c41 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 27 Sep 2021 11:31:51 -0300 Subject: [PATCH] Changed the default `group_fields` list. Internal BoM: now components with different Tolerance, Voltage, Current and/or Power fields aren't grouped together. These fields are now part of the default `group_fields`. (#79) --- CHANGELOG.md | 5 +++++ README.md | 3 ++- docs/samples/generic_plot.kibot.yaml | 5 +++-- kibot/config_reader.py | 4 ++-- kibot/optionable.py | 5 +++++ kibot/out_bom.py | 7 ++++--- tests/yaml_samples/int_bom_exclude_any.kibot.yaml | 2 +- tests/yaml_samples/int_bom_simple_csv.kibot.yaml | 3 ++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c647a3df..2d4ca0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - skip_bottom: bottom components aren't rotated. - XLSX BoM: option to control the logo scale (#84) +### Changed +- Internal BoM: now components with different Tolerance, Voltage, Current + and/or Power fields aren't grouped together. + These fields are now part of the default `group_fields`. (#79) + ### Fixed - Position files now defaults to use the auxiliar origin as KiCad. Can be disabled to use absolute coordinates. (#87) diff --git a/README.md b/README.md index 6afc3ff6..52089d38 100644 --- a/README.md +++ b/README.md @@ -692,7 +692,8 @@ Next time you need this list just use an alias, like this: - `group_fields`: [list(string)] List of fields used for sorting individual components into groups. Components which match (comparing *all* fields) will be grouped together. Field names are case-insensitive. - If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib'] is used. + If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib', + 'Voltage', 'Tolerance', 'Current', 'Power'] is used. - `group_fields_fallbacks`: [list(string)] List of fields to be used when the fields in `group_fields` are empty. The first field in this list is the fallback for the first in `group_fields`, and so on. - `html`: [dict] Options for the HTML format. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 4e1694e2..1b1768b8 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -130,8 +130,9 @@ outputs: # [list(string)] List of fields used for sorting individual components into groups. # Components which match (comparing *all* fields) will be grouped together. # Field names are case-insensitive. - # If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib'] is used - group_fields: ['part', 'part lib', 'value', 'footprint', 'footprint lib'] + # If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib', + # 'Voltage', 'Tolerance', 'Current', 'Power'] is used + group_fields: ['part', 'part lib', 'value', 'footprint', 'footprint lib', 'voltage', 'tolerance', 'current', 'power'] # [list(string)] List of fields to be used when the fields in `group_fields` are empty. # The first field in this list is the fallback for the first in `group_fields`, and so on group_fields_fallbacks: diff --git a/kibot/config_reader.py b/kibot/config_reader.py index 0bdfe5ba..e9aeac01 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -405,8 +405,8 @@ def print_example_options(f, cls, name, indent, po, is_list=False): # Get the text before the space, without the ] txt = txt.split()[0][:-1] f.write(ind_str+'{}: {}\n'.format(k, txt)) - elif hasattr(val, '_default'): - f.write(ind_str+'{}: {}\n'.format(k, val._default)) + elif val.get_default(): + f.write(ind_str+'{}: {}\n'.format(k, val.get_default())) else: f.write(ind_str+'{}:\n'.format(k)) print_example_options(f, val, '', indent+2, None, help and 'list(dict' in help_lines[0]) diff --git a/kibot/optionable.py b/kibot/optionable.py index 78e47b79..46e9d012 100644 --- a/kibot/optionable.py +++ b/kibot/optionable.py @@ -25,6 +25,7 @@ class Optionable(object): Is configured from a dict and the collected values are stored in its attributes. """ _str_values_re = compile(r"string=.*\] \[([^\]]+)\]") _num_range_re = compile(r"number=.*\] \[(-?\d+),(-?\d+)\]") + _default = None def __init__(self): self._unkown_is_error = False @@ -253,6 +254,10 @@ class Optionable(object): val = [] return val + @classmethod + def get_default(cls): + return cls._default + class BaseOptions(Optionable): """ A class to validate and hold output options. diff --git a/kibot/out_bom.py b/kibot/out_bom.py index 792bf0cc..32203eb3 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -183,7 +183,7 @@ class ComponentAliases(Optionable): class GroupFields(Optionable): - _default = ColumnList.DEFAULT_GROUPING + _default = ColumnList.DEFAULT_GROUPING + ['voltage', 'tolerance', 'current', 'power'] def __init__(self): super().__init__() @@ -274,7 +274,8 @@ class BoMOptions(BaseOptions): """ [list(string)] List of fields used for sorting individual components into groups. Components which match (comparing *all* fields) will be grouped together. Field names are case-insensitive. - If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib'] is used """ + If empty: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib', + . 'Voltage', 'Tolerance', 'Current', 'Power'] is used """ self.group_fields_fallbacks = Optionable """ [list(string)] List of fields to be used when the fields in `group_fields` are empty. The first field in this list is the fallback for the first in `group_fields`, and so on """ @@ -427,7 +428,7 @@ class BoMOptions(BaseOptions): self.xlsx.config(self) # group_fields if isinstance(self.group_fields, type): - self.group_fields = ColumnList.DEFAULT_GROUPING + self.group_fields = GroupFields.get_default() else: # Make the grouping fields lowercase self.group_fields = [f.lower() for f in self.group_fields] diff --git a/tests/yaml_samples/int_bom_exclude_any.kibot.yaml b/tests/yaml_samples/int_bom_exclude_any.kibot.yaml index d5e3706d..d841f2f2 100644 --- a/tests/yaml_samples/int_bom_exclude_any.kibot.yaml +++ b/tests/yaml_samples/int_bom_exclude_any.kibot.yaml @@ -32,4 +32,4 @@ outputs: dir: BoM options: exclude_filter: 'exclude_any' - + group_fields: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib'] diff --git a/tests/yaml_samples/int_bom_simple_csv.kibot.yaml b/tests/yaml_samples/int_bom_simple_csv.kibot.yaml index 6cb5726c..f609d225 100644 --- a/tests/yaml_samples/int_bom_simple_csv.kibot.yaml +++ b/tests/yaml_samples/int_bom_simple_csv.kibot.yaml @@ -7,4 +7,5 @@ outputs: comment: "Bill of Materials in CSV format" type: bom dir: BoM - + options: + group_fields: ['Part', 'Part Lib', 'Value', 'Footprint', 'Footprint Lib']