From 68e0ccc9b8f5b1b7a24787e60da97b9bcf525c44 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 31 Jul 2023 09:12:05 -0300 Subject: [PATCH] [iBoM][Added] `forced_name` to control the displayed name - To force the name displayed at the top left corner Closes #470 --- CHANGELOG.md | 8 ++++++++ README.md | 2 ++ docs/samples/generic_plot.kibot.yaml | 3 +++ kibot/out_base.py | 5 +++-- kibot/out_ibom.py | 11 ++++++++--- tests/yaml_samples/ibom_variant_1.kibot.yaml | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26263958..8c2a530b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.6.4] - UNRELEASED +### Added +- iBoM: + - `forced_name` option to force the name displayed at the top left corner + (#470) + ### Fixed - Rotated polygons and text used in the worksheet (#466) +- BoM: + - Problems when trying to aggregate the datasheet field (#472) + ## [1.6.3] - 2023-06-26 ### Added diff --git a/README.md b/README.md index 3bdc9f17..bbbc8a3b 100644 --- a/README.md +++ b/README.md @@ -2805,6 +2805,8 @@ Notes: IBoM option, avoid using in conjunction with KiBot variants/filters. - `extra_data_file`: [string=''] Path to netlist or xml file. You can use '%F.xml' to avoid specifying the project name. Leave it blank for most uses, data will be extracted from the PCB. + - `forced_name`: [string=''] Name to be used for the PCB/project (no file extension). + This will affect the name iBoM displays in the generated HTML. - `group_fields`: [string=''] Comma separated list of fields that components will be grouped by. Value and Footprint are used when nothing is specified. - `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 1ed502ee..cc1417e9 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -1235,6 +1235,9 @@ outputs: # [string=''] Comma separated list of extra fields to pull from netlist or xml file. # Using 'X,Y' is a shortcut for `show_fields` and `group_fields` with values 'Value,Footprint,X,Y' extra_fields: '' + # [string=''] Name to be used for the PCB/project (no file extension). + # This will affect the name iBoM displays in the generated HTML + forced_name: '' # [string=''] Comma separated list of fields that components will be grouped by. # Value and Footprint are used when nothing is specified group_fields: '' diff --git a/kibot/out_base.py b/kibot/out_base.py index 4284918c..62495ba7 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -885,12 +885,13 @@ class VariantOptions(BaseOptions): return fname @staticmethod - def save_tmp_dir_board(id, force_dir=None): + def save_tmp_dir_board(id, force_dir=None, forced_name=None): """ Save the PCB to a temporal dir. Disadvantage: all relative paths inside the file becomes useless Aadvantage: the name of the file remains the same """ pcb_dir = mkdtemp(prefix='tmp-kibot-'+id+'-') if force_dir is None else force_dir - fname = os.path.join(pcb_dir, GS.pcb_basename+'.kicad_pcb') + basename = forced_name if forced_name else GS.pcb_basename + fname = os.path.join(pcb_dir, basename+'.kicad_pcb') logger.debug('Storing modified PCB to `{}`'.format(fname)) GS.board.Save(fname) pro_name = GS.copy_project(fname) diff --git a/kibot/out_ibom.py b/kibot/out_ibom.py index a9f51652..6f11b568 100644 --- a/kibot/out_ibom.py +++ b/kibot/out_ibom.py @@ -120,6 +120,9 @@ class IBoMOptions(VariantOptions): self.hide_excluded = False """ Hide components in the Fab layer that are marked as excluded by a variant. Affected by global options """ + self.forced_name = '' + """ Name to be used for the PCB/project (no file extension). + This will affect the name iBoM displays in the generated HTML """ super().__init__() self.add_to_doc('variant', WARNING_MIX) self.add_to_doc('dnf_filter', WARNING_MIX) @@ -177,15 +180,17 @@ class IBoMOptions(VariantOptions): pcb_name = GS.pcb_file if self.will_filter_pcb_components(): # Write a custom netlist to a temporal dir + prj_name = os.path.basename(self.expand_filename('', self.forced_name, 'ibom', '')) if self.forced_name \ + else GS.pcb_basename net_dir = mkdtemp(prefix='tmp-kibot-ibom-') - netlist = os.path.join(net_dir, GS.pcb_basename+'.xml') + netlist = os.path.join(net_dir, prj_name+'.xml') self.extra_data_file = netlist logger.debug('Creating variant netlist `{}`'.format(netlist)) with open(netlist, 'wb') as f: GS.sch.save_netlist(f, self._comps) # Write a board with the filtered values applied self.filter_pcb_components() - pcb_name, _ = self.save_tmp_dir_board('ibom', force_dir=net_dir) + pcb_name, _ = self.save_tmp_dir_board('ibom', force_dir=net_dir, forced_name=prj_name) self.unfilter_pcb_components() else: # Check if the user wants extra_fields but there is no data about them (#68) @@ -208,7 +213,7 @@ class IBoMOptions(VariantOptions): self.blacklist += to_remove # Convert attributes into options for k, v in self.get_attrs_gen(): - if not v or k in ['output', 'variant', 'dnf_filter', 'pre_transform', 'hide_excluded']: + if not v or k in ['output', 'variant', 'dnf_filter', 'pre_transform', 'hide_excluded', 'forced_name']: continue if k == 'offset_back_rotation' and version < (2, 5, 0, 2): continue diff --git a/tests/yaml_samples/ibom_variant_1.kibot.yaml b/tests/yaml_samples/ibom_variant_1.kibot.yaml index 379efa9c..5abed6d6 100644 --- a/tests/yaml_samples/ibom_variant_1.kibot.yaml +++ b/tests/yaml_samples/ibom_variant_1.kibot.yaml @@ -47,6 +47,7 @@ outputs: dir: BoM options: variant: t1_v1 + forced_name: '%f, %V' - name: 'bom_internal_v2' comment: "Bill of Materials in CSV format for variant t1_v2"