Skip to content

Commit b2eaed2

Browse files
committed
[KiCad Variants][Added] Default action
- Applies in_bom, dnp and fields
1 parent bb2362b commit b2eaed2

6 files changed

Lines changed: 39 additions & 19 deletions

File tree

kibot/fil_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ def reset_filters(comps, kicad_dnp_applied='global'):
207207
c.set_fitted(fitted)
208208
c.set_fixed(False)
209209
c.back_up_fields()
210+
c.in_bom = c.in_bom_sch
211+
c.kicad_dnp = c.kicad_dnp_sch
210212

211213

212214
def apply_fitted_filter(comps, filter):

kibot/kicad/v5_sch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,13 +906,15 @@ def __init__(self):
906906
self.tht = False
907907
# KiCad 6 SCH flags
908908
self.in_bom = True # not Exclude from bill of materials
909+
self.in_bom_sch = True # back-up copy
909910
self.on_board = True # not Exclude from BoM
910911
# KiCad 6 PCB flags
911912
self.in_bom_pcb = True # not Exclude from bill of materials
912913
self.in_pos = True # not Exclude from position files
913914
self.in_pcb_only = False # Not in schematic
914915
# KiCad 7 PCB flags
915916
self.kicad_dnp = None # Do Not Populate
917+
self.kicad_dnp_sch = None # back-up copy
916918
# KiCad 10
917919
self.in_pos_files = None
918920
self.duplicate_pin_numbers_are_jumpers = None

kibot/kicad/v6_sch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,15 +1397,15 @@ def load(c, project, parent):
13971397
elif i_type == 'exclude_from_sim':
13981398
comp.exclude_from_sim = _get_yes_no(i, 1, i_type)
13991399
elif i_type == 'in_bom':
1400-
comp.in_bom = _get_yes_no(i, 1, i_type)
1400+
comp.in_bom_sch = comp.in_bom = _get_yes_no(i, 1, i_type)
14011401
elif i_type == 'on_board':
14021402
comp.on_board = _get_yes_no(i, 1, i_type)
14031403
elif i_type == 'in_pos_files':
14041404
comp.in_pos_files = _get_yes_no(i, 1, i_type)
14051405
elif i_type == 'duplicate_pin_numbers_are_jumpers':
14061406
comp.duplicate_pin_numbers_are_jumpers = _get_yes_no(i, 1, i_type)
14071407
elif i_type == 'dnp':
1408-
comp.kicad_dnp = _get_yes_no(i, 1, i_type)
1408+
comp.kicad_dnp_sch = comp.kicad_dnp = _get_yes_no(i, 1, i_type)
14091409
elif i_type == 'fields_autoplaced':
14101410
# Not documented
14111411
comp.fields_autoplaced = True

kibot/optionable.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,33 @@ def solve_field_name(field, empty_when_none=False):
729729
return GS.global_field_distributor[0] if GS.global_field_distributor else field_or_empty
730730
return field
731731

732+
def get_kicad_variant(self, c):
733+
""" Look for the currently selected variant in the component """
734+
vname = 'Default'
735+
v = None
736+
if self.variant:
737+
v = c.variants.get(self.variant.name)
738+
if v:
739+
logger.debugl(4, f"- Found variant {self.variant.name} for {c.ref}")
740+
vname = self.variant.name
741+
return v, vname
742+
743+
def kicad_var_cb(self, c):
744+
""" Generic KiCad variants implementation """
745+
v, vname = self.get_kicad_variant(c)
746+
if v is None:
747+
return v, vname
748+
# Flags
749+
if v.in_bom is not None:
750+
c.in_bom = v.in_bom
751+
if v.dnp is not None:
752+
c.kicad_dnp = v.dnp
753+
# Fields
754+
for name, value in v.fields.items():
755+
c.set_field(name, value)
756+
logger.debugl(3, f'- {c.ref} field `{name}` set to `{value}` by `{vname}`')
757+
return v, vname
758+
732759

733760
class BaseOptions(Optionable):
734761
""" A class to validate and hold output options.

kibot/out_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ def load_list_components(self, forced=False):
11611161
# Apply the variant
11621162
if self.variant:
11631163
# Apply the variant
1164-
comps = self.variant.filter(comps)
1164+
comps = self.variant.filter(comps, self.kicad_var_cb)
11651165
self._sub_pcb = self.variant._sub_pcb
11661166
self._comps = comps
11671167

kibot/out_bom.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,18 +1009,11 @@ def kicad_var_cb(self, c):
10091009
""" KiCad variants implementation specific for BoM.
10101010
`no in BoM` -> not included
10111011
`DNP` -> not fitted """
1012-
vname = 'Default'
1013-
v = None
1014-
if self.variant:
1015-
v = c.variants.get(self.variant.name)
1016-
if v:
1017-
logger.debugl(4, f"- Found variant {self.variant.name} for {c.ref}")
1018-
vname = self.variant.name
1012+
v, vname = super().kicad_var_cb(c)
10191013
# Included
10201014
if self.exclude_marked_in_sch:
1021-
in_bom = v.in_bom if v is not None and v.in_bom is not None else c.in_bom
1022-
if c.included and not in_bom:
1023-
c.included = in_bom
1015+
if c.included and not c.in_bom:
1016+
c.included = c.in_bom
10241017
logger.debugl(3, f'- {c.ref} excluded by `{vname}` from schematic')
10251018
if self.exclude_marked_in_pcb:
10261019
# The variant was applied by "get_board_comps_data"
@@ -1029,15 +1022,11 @@ def kicad_var_cb(self, c):
10291022
logger.debugl(3, f'- {c.ref} excluded from PCB')
10301023
# DNP (aka DNF)
10311024
if self._kicad_dnp_applied_solved:
1032-
dnp = v.dnp if v is not None and v.dnp is not None else c.kicad_dnp
1025+
# dnp = v.dnp if v is not None and v.dnp is not None else c.kicad_dnp
1026+
dnp = c.kicad_dnp
10331027
if dnp:
10341028
c.set_fitted(False)
10351029
logger.debugl(3, f'- {c.ref} DNP by `{vname}`')
1036-
# Fields
1037-
if v is not None:
1038-
for name, value in v.fields.items():
1039-
c.set_field(name, value)
1040-
logger.debugl(3, f'- {c.ref} field `{name}` set to `{value}` by `{vname}`')
10411030

10421031
def run(self, output):
10431032
format = self._format

0 commit comments

Comments
 (0)