[iBoM][Fixed] Variant changes to the *.Fab weren't exported

- Now all 2D variant stuff is applied before calling iBoM

Closes #350
This commit is contained in:
Salvador E. Tropea 2022-12-19 11:26:24 -03:00
parent ccaefd7e90
commit 5594fa0b7c
3 changed files with 20 additions and 13 deletions

View File

@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- PCB_Print: - PCB_Print:
- Images not showing in custom frames. (#352) - Images not showing in custom frames. (#352)
- iBoM:
- Variant changes to the *.Fab weren't exported.
Now all 2D variant stuff is applied before calling iBoM (#350)
## [1.5.1] - 2022-12-16 ## [1.5.1] - 2022-12-16
### Fixed ### Fixed

View File

@ -409,8 +409,8 @@ class VariantOptions(BaseOptions):
self.old_layers = old_layers self.old_layers = old_layers
self.old_fadhes = old_fadhes self.old_fadhes = old_fadhes
self.old_badhes = old_badhes self.old_badhes = old_badhes
self.fadhes = fadhes self._fadhes = fadhes
self.badhes = badhes self._badhes = badhes
return exclude return exclude
def restore_paste_and_glue(self, board, comps_hash): def restore_paste_and_glue(self, board, comps_hash):
@ -429,9 +429,9 @@ class VariantOptions(BaseOptions):
p.SetLayerSet(pad_layers) p.SetLayerSet(pad_layers)
if GS.global_remove_adhesive_for_dnp: if GS.global_remove_adhesive_for_dnp:
for gi in self.old_fadhes: for gi in self.old_fadhes:
gi.SetLayer(self.fadhes) gi.SetLayer(self._fadhes)
for gi in self.old_badhes: for gi in self.old_badhes:
gi.SetLayer(self.badhes) gi.SetLayer(self._badhes)
def remove_fab(self, board, comps_hash): def remove_fab(self, board, comps_hash):
""" Remove from Fab the excluded components. """ """ Remove from Fab the excluded components. """
@ -458,16 +458,16 @@ class VariantOptions(BaseOptions):
# Store the data to undo the above actions # Store the data to undo the above actions
self.old_ffab = old_ffab self.old_ffab = old_ffab
self.old_bfab = old_bfab self.old_bfab = old_bfab
self.ffab = ffab self._ffab = ffab
self.bfab = bfab self._bfab = bfab
def restore_fab(self, board, comps_hash): def restore_fab(self, board, comps_hash):
if comps_hash is None: if comps_hash is None:
return return
for gi in self.old_ffab: for gi in self.old_ffab:
gi.SetLayer(self.ffab) gi.SetLayer(self._ffab)
for gi in self.old_bfab: for gi in self.old_bfab:
gi.SetLayer(self.bfab) gi.SetLayer(self._bfab)
def replace_3D_models(self, models, new_model, c): def replace_3D_models(self, models, new_model, c):
""" Changes the 3D model using a provided model. """ Changes the 3D model using a provided model.
@ -726,6 +726,10 @@ class VariantOptions(BaseOptions):
self.remove_paste_and_glue(board, self.comps_hash) self.remove_paste_and_glue(board, self.comps_hash)
if hasattr(self, 'hide_excluded') and self.hide_excluded: if hasattr(self, 'hide_excluded') and self.hide_excluded:
self.remove_fab(board, self.comps_hash) self.remove_fab(board, self.comps_hash)
# Copy any change in the schematic fields to the PCB properties
# I.e. the value of a component so it gets updated in the *.Fab layer
# Also useful for iBoM that can read the sch fields from the PCB
self.sch_fields_to_pcb(board, self.comps_hash)
if do_3D: if do_3D:
# Disable the models that aren't for this variant # Disable the models that aren't for this variant
self.apply_3D_variant_aspect(board) self.apply_3D_variant_aspect(board)
@ -751,6 +755,8 @@ class VariantOptions(BaseOptions):
self.restore_paste_and_glue(board, self.comps_hash) self.restore_paste_and_glue(board, self.comps_hash)
if hasattr(self, 'hide_excluded') and self.hide_excluded: if hasattr(self, 'hide_excluded') and self.hide_excluded:
self.restore_fab(board, self.comps_hash) self.restore_fab(board, self.comps_hash)
# Restore the PCB properties and values
self.restore_sch_fields_to_pcb(board)
if do_3D: if do_3D:
# Undo the removing (also rename) # Undo the removing (also rename)
self.restore_3D_models(board, self.comps_hash) self.restore_3D_models(board, self.comps_hash)
@ -789,10 +795,9 @@ class VariantOptions(BaseOptions):
GS.board.GetTitleBlock().SetTitle(self.old_title) GS.board.GetTitleBlock().SetTitle(self.old_title)
self.old_title = None self.old_title = None
def sch_fields_to_pcb(self, comps, board): def sch_fields_to_pcb(self, board, comps_hash):
""" Change the module/footprint data according to the filtered fields. """ Change the module/footprint data according to the filtered fields.
iBoM can parse it. """ iBoM can parse it. """
comps_hash = self.get_refs_hash()
self.sch_fields_to_pcb_bkp = {} self.sch_fields_to_pcb_bkp = {}
first = True first = True
for m in GS.get_modules_board(board): for m in GS.get_modules_board(board):

View File

@ -184,8 +184,9 @@ class IBoMOptions(VariantOptions):
with open(netlist, 'wb') as f: with open(netlist, 'wb') as f:
GS.sch.save_netlist(f, self._comps) GS.sch.save_netlist(f, self._comps)
# Write a board with the filtered values applied # Write a board with the filtered values applied
self.sch_fields_to_pcb(self._comps, GS.board) self.filter_pcb_components(GS.board)
pcb_name, _ = self.save_tmp_dir_board('ibom', force_dir=net_dir) pcb_name, _ = self.save_tmp_dir_board('ibom', force_dir=net_dir)
self.unfilter_pcb_components(GS.board)
else: else:
# Check if the user wants extra_fields but there is no data about them (#68) # Check if the user wants extra_fields but there is no data about them (#68)
if self.need_extra_fields() and not os.path.isfile(self.extra_data_file): if self.need_extra_fields() and not os.path.isfile(self.extra_data_file):
@ -233,8 +234,6 @@ class IBoMOptions(VariantOptions):
if net_dir: if net_dir:
logger.debug('Removing temporal variant dir `{}`'.format(net_dir)) logger.debug('Removing temporal variant dir `{}`'.format(net_dir))
rmtree(net_dir) rmtree(net_dir)
# Restore the PCB properties and values
self.restore_sch_fields_to_pcb(GS.board)
# Restore the real name selected # Restore the real name selected
self.extra_data_file = ori_extra_data_file self.extra_data_file = ori_extra_data_file
logger.debug('Output from command:\n'+cmd_output_dec+'\n') logger.debug('Output from command:\n'+cmd_output_dec+'\n')