Skip to content

Commit

Permalink
[Fixed][SubParts] iBoM and SCH print
Browse files Browse the repository at this point in the history
- Not fitted was actually ignored for components created from sub-parts

Fixes #716
  • Loading branch information
set-soft committed Nov 20, 2024
1 parent 1c966db commit c17a230
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A mechanism to paste images from outputs (#714)

### Fixed
- SubParts filter:
- iBoM and Schematic print didn't take it into account (#716)
- BoM
- The field name `Reference` was accepted, but didn't work

Expand Down
8 changes: 4 additions & 4 deletions kibot/fil_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def reset_filters(comps):
for c in comps:
c.included = True
# If the global kicad_dnp_applied variable is True try to copy the DNP flag from KiCad v7
c.fitted = not GS.global_kicad_dnp_applied or c.kicad_dnp is None or not c.kicad_dnp
c.fixed = False
c.set_fitted(not GS.global_kicad_dnp_applied or c.kicad_dnp is None or not c.kicad_dnp)
c.set_fixed(False)
c.back_up_fields()


Expand All @@ -207,7 +207,7 @@ def apply_fitted_filter(comps, filter):
logger.debug('Applying filter `{}` to fitted'.format(filter.name))
for c in comps:
if c.fitted:
c.fitted = filter.filter(c)
c.set_fitted(filter.filter(c))
if not c.fitted and GS.debug_level > 2:
logger.debug('- Not fit: '+c.ref)

Expand All @@ -217,7 +217,7 @@ def apply_fixed_filter(comps, filter):
logger.debug('Applying filter `{}` to fixed'.format(filter.name))
for c in comps:
if not c.fixed:
c.fixed = filter.filter(c)
c.set_fixed(filter.filter(c))


class BaseFilter(RegFilter):
Expand Down
1 change: 1 addition & 0 deletions kibot/fil_separate_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def filter(self, comp):
for name, v in comp.pad_properties.items():
if v.fab_property in self._attribute:
c = deepcopy(comp)
c.parent_component = comp
c.ref += self.ref_sep+name
# Adjust the suffix to be "sort friendly"
# Currently useless, but could help in the future
Expand Down
1 change: 1 addition & 0 deletions kibot/fil_subparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def do_split(self, comp, max_num_subparts, split_fields):
alt_values_len = len(alt_values)
for i in range(max_num_subparts):
new_comp = deepcopy(comp)
new_comp.parent_component = comp
if multi_part:
# Adjust the reference name
if self.use_ref_sep_for_first:
Expand Down
15 changes: 15 additions & 0 deletions kibot/kicad/v5_sch.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,8 @@ def __init__(self):
self.qty = 1
self.annotation_error = False
self.net_name = self.net_class = ''
# The following is used by transform variants that creates components derived from another
self.parent_component = None
# Position offset i.e. from the rotation filter
self.pos_offset_x = self.pos_offset_y = None
# KiCad 5 PCB flags (mutually exclusive)
Expand Down Expand Up @@ -988,6 +990,19 @@ def back_up_fields(self):
self.fields_bkp = deepcopy(self.fields)
self.dfields_bkp = {f.name.lower(): f for f in self.fields_bkp}

def set_fitted(self, status):
self.fitted = status
if self.parent_component:
self.parent_component.set_fitted(status)

def set_fixed(self, status):
self.fixed = status
if self.parent_component:
self.parent_component.set_fixed(status)

def get_parent_ref(self):
return self.ref if not self.parent_component else self.parent_component.get_parent_ref()

def _solve_ref(self, path):
""" Look for the correct reference for this path.
Returns the default reference if no paths defined.
Expand Down
11 changes: 7 additions & 4 deletions kibot/out_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,14 @@ def get_fitted_refs(self):
return []
return [c.ref for c in self._comps if c.fitted and c.included]

def get_not_fitted_refs(self):
def get_not_fitted_refs(self, parent=False):
""" List of 'not fitted' components, also includes 'not included' """
if not self._comps:
return []
return [c.ref for c in self._comps if not c.fitted or not c.included]
if not parent:
return [c.ref for c in self._comps if not c.fitted or not c.included]
# Here we want only parent components
return list({c.get_parent_ref() for c in self._comps if not c.fitted or not c.included})

def help_only_sub_pcbs(self):
self.add_to_doc('variant', 'Used for sub-PCBs')
Expand Down Expand Up @@ -1149,7 +1152,7 @@ def apply_show_components(self):
self.undo_show = set()
for c in self._comps:
if c.ref not in show_components and c.fitted:
c.fitted = False
c.set_fitted(False)
self.undo_show.add(c.ref)
logger.debugl(2, '- Removing '+c.ref)

Expand All @@ -1159,7 +1162,7 @@ def undo_show_components(self):
return
for c in self._comps:
if c.ref in self.undo_show:
c.fitted = True
c.set_fitted(True)

def sch_replace_one_image(self, sheet, box, output_name, box_index):
""" Replace one image in the schematic, see sch_replace_images """
Expand Down
2 changes: 1 addition & 1 deletion kibot/out_ibom.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def run(self, name):
# Plugin could be installed without execute flags
cmd.insert(0, 'python3')
# Apply variants/filters
to_remove = ','.join(self.get_not_fitted_refs())
to_remove = ','.join(self.get_not_fitted_refs(parent=True))
if self.blacklist and to_remove:
self.blacklist += ','
self.blacklist += to_remove
Expand Down
2 changes: 1 addition & 1 deletion kibot/var_ibom.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def filter(self, comps):
if not (c.fitted and c.included):
# Don't check if we already discarded it
continue
c.fitted = not self.skip_component(c)
c.set_fitted(not self.skip_component(c))
if not c.fitted and GS.debug_level > 2:
logger.debug(f' fitted -> False (value: {c.value})')
return comps
2 changes: 1 addition & 1 deletion kibot/var_kibom.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def filter(self, comps):
# Don't check if we already discarded it
continue
config = c.get_field_value(self.config_field)
c.fitted = self.matches_variant(config)
c.set_fitted(self.matches_variant(config))
if not c.fitted and GS.debug_level > 2:
logger.debug('ref: {} config: {} variant: {} -> False'.
format(c.ref, config, self.variant))
Expand Down
2 changes: 1 addition & 1 deletion kibot/var_kicost.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def filter(self, comps):
# Don't check if we already discarded it
continue
variants = c.get_field_value(self.variant_field)
c.fitted = self.matches_variant(variants)
c.set_fitted(self.matches_variant(variants))
if not c.fitted and GS.debug_level > 2:
logger.debug('ref: {} value: {} variants: {} -> False'.format(c.ref, c.value, variants))
return comps

0 comments on commit c17a230

Please sign in to comment.