Skip to content

Commit

Permalink
[iBoM][Added] forced_name to control the displayed name
Browse files Browse the repository at this point in the history
- To force the name displayed at the top left corner

Closes #470
  • Loading branch information
set-soft committed Jul 31, 2023
1 parent f9e774a commit 68e0ccc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
5 changes: 3 additions & 2 deletions kibot/out_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,13 @@ def save_tmp_board_if_variant(self, new_title='', dir=None, do_3D=False):
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)
Expand Down
11 changes: 8 additions & 3 deletions kibot/out_ibom.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def __init__(self):
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)
Expand Down Expand Up @@ -177,15 +180,17 @@ def run(self, name):
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)
Expand All @@ -208,7 +213,7 @@ def run(self, name):
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
Expand Down
1 change: 1 addition & 0 deletions tests/yaml_samples/ibom_variant_1.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 68e0ccc

Please sign in to comment.