Fixed: if no filters are applied we must reset the fields.
Added funtions to apply the filters Moved code from bom.py to out_bom.py
This commit is contained in:
parent
2fabf6da0c
commit
712d135df5
|
|
@ -362,18 +362,6 @@ def group_components(cfg, components):
|
|||
|
||||
|
||||
def do_bom(file_name, ext, comps, cfg):
|
||||
# Apply all the filters
|
||||
if cfg.exclude_filter:
|
||||
for c in comps:
|
||||
c.in_bom = cfg.exclude_filter.filter(c)
|
||||
if cfg.dnf_filter:
|
||||
for c in comps:
|
||||
c.fitted = cfg.dnf_filter.filter(c)
|
||||
if cfg.dnc_filter:
|
||||
for c in comps:
|
||||
c.fixed = cfg.dnc_filter.filter(c)
|
||||
# Apply the variant
|
||||
cfg.variant.filter(comps)
|
||||
# Group components according to group_fields
|
||||
groups = group_components(cfg, comps)
|
||||
# Create the BoM
|
||||
|
|
|
|||
|
|
@ -65,6 +65,36 @@ class NotFilter(Registrable):
|
|||
return not self._filter.filter(comp)
|
||||
|
||||
|
||||
def apply_in_bom_filter(comps, filter, reset=True):
|
||||
if filter:
|
||||
logger.debug('Applying filter `{}` to in_bom'.format(filter.name))
|
||||
for c in comps:
|
||||
c.in_bom = filter.filter(c)
|
||||
elif reset: # Reset the field
|
||||
for c in comps:
|
||||
c.in_bom = True
|
||||
|
||||
|
||||
def apply_fitted_filter(comps, filter, reset=True):
|
||||
if filter:
|
||||
logger.debug('Applying filter `{}` to fitted'.format(filter.name))
|
||||
for c in comps:
|
||||
c.fitted = filter.filter(c)
|
||||
elif reset: # Reset the field
|
||||
for c in comps:
|
||||
c.fitted = True
|
||||
|
||||
|
||||
def apply_fixed_filter(comps, filter, reset=True):
|
||||
if filter:
|
||||
logger.debug('Applying filter `{}` to fixed'.format(filter.name))
|
||||
for c in comps:
|
||||
c.fixed = filter.filter(c)
|
||||
elif reset: # Reset the field
|
||||
for c in comps:
|
||||
c.fixed = False
|
||||
|
||||
|
||||
class BaseFilter(RegFilter):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from .macros import macros, document, output_class # noqa: F401
|
|||
from .bom.columnlist import ColumnList, BoMError
|
||||
from .bom.bom import do_bom
|
||||
from .var_kibom import KiBoM
|
||||
from .fil_base import BaseFilter
|
||||
from .fil_base import BaseFilter, apply_in_bom_filter, apply_fitted_filter, apply_fixed_filter
|
||||
from . import log
|
||||
|
||||
logger = log.get_logger(__name__)
|
||||
|
|
@ -366,6 +366,12 @@ class BoMOptions(BaseOptions):
|
|||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
get_board_comps_data(comps)
|
||||
# Apply all the filters
|
||||
apply_in_bom_filter(comps, self.exclude_filter)
|
||||
apply_fitted_filter(comps, self.dnf_filter)
|
||||
apply_fixed_filter(comps, self.dnc_filter)
|
||||
# Apply the variant
|
||||
self.variant.filter(comps)
|
||||
try:
|
||||
do_bom(output, format, comps, self)
|
||||
except BoMError as e:
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from .misc import (CMD_EESCHEMA_DO, PDF_SCH_PRINT)
|
|||
from .optionable import BaseOptions, Optionable
|
||||
from .registrable import RegOutput
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from .fil_base import BaseFilter
|
||||
from .fil_base import BaseFilter, apply_fitted_filter
|
||||
from . import log
|
||||
|
||||
logger = log.get_logger(__name__)
|
||||
|
|
@ -41,9 +41,7 @@ class PDF_Sch_PrintOptions(BaseOptions):
|
|||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
# Apply the filter
|
||||
if self.dnf_filter:
|
||||
for c in comps:
|
||||
c.fitted = self.dnf_filter.filter(c)
|
||||
apply_fitted_filter(comps, self.dnf_filter)
|
||||
# Apply the variant
|
||||
if self.variant:
|
||||
self.variant.filter(comps)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from .gs import GS
|
|||
from .optionable import BaseOptions, Optionable
|
||||
from .registrable import RegOutput
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from .fil_base import BaseFilter
|
||||
from .fil_base import BaseFilter, apply_fitted_filter
|
||||
from . import log
|
||||
|
||||
logger = log.get_logger(__name__)
|
||||
|
|
@ -33,9 +33,7 @@ class Sch_Variant_Options(BaseOptions):
|
|||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
# Apply the filter
|
||||
if self.dnf_filter:
|
||||
for c in comps:
|
||||
c.fitted = self.dnf_filter.filter(c)
|
||||
apply_fitted_filter(comps, self.dnf_filter)
|
||||
# Apply the variant
|
||||
if self.variant:
|
||||
# Apply the variant
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
# Project: KiBot (formerly KiPlot)
|
||||
from .registrable import RegVariant
|
||||
from .optionable import Optionable
|
||||
from .fil_base import BaseFilter
|
||||
from .fil_base import BaseFilter, apply_in_bom_filter, apply_fitted_filter, apply_fixed_filter
|
||||
from .macros import macros, document # noqa: F401
|
||||
|
||||
|
||||
|
|
@ -42,14 +42,8 @@ class BaseVariant(RegVariant):
|
|||
# dnc_filter
|
||||
self.dnc_filter = BaseFilter.solve_filter(self.dnc_filter, 'dnc_filter')
|
||||
|
||||
def filter(self, comps):
|
||||
def filter(self, comps, reset):
|
||||
# Apply all the filters
|
||||
if self.exclude_filter:
|
||||
for c in comps:
|
||||
c.in_bom = self.exclude_filter.filter(c)
|
||||
if self.dnf_filter:
|
||||
for c in comps:
|
||||
c.fitted = self.dnf_filter.filter(c)
|
||||
if self.dnc_filter:
|
||||
for c in comps:
|
||||
c.fixed = self.dnc_filter.filter(c)
|
||||
apply_in_bom_filter(comps, self.exclude_filter, reset)
|
||||
apply_fitted_filter(comps, self.dnf_filter, reset)
|
||||
apply_fixed_filter(comps, self.dnc_filter, reset)
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ class IBoM(BaseVariant): # noqa: F821
|
|||
return True
|
||||
return False
|
||||
|
||||
def filter(self, comps):
|
||||
super().filter(comps)
|
||||
def filter(self, comps, reset=False):
|
||||
super().filter(comps, reset)
|
||||
logger.debug("Applying IBoM style variants `{}`".format(self.name))
|
||||
# Make black/white lists case insensitive
|
||||
self.variants_whitelist = [v.lower() for v in self.variants_whitelist]
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ class KiBoM(BaseVariant): # noqa: F821
|
|||
# No match
|
||||
return not exclusive
|
||||
|
||||
def filter(self, comps):
|
||||
super().filter(comps)
|
||||
def filter(self, comps, reset=False):
|
||||
super().filter(comps, reset)
|
||||
logger.debug("Applying KiBoM style variants `{}`".format(self.name))
|
||||
for c in comps:
|
||||
if not (c.fitted and c.in_bom):
|
||||
|
|
|
|||
Loading…
Reference in New Issue