Added filters to the variants.
So they have the same functionality than internal BoM. I keep the (redundant) filters in internal BoM so users doesn't need to create a variant just to apply a filter.
This commit is contained in:
parent
7882cb0f4f
commit
4cc8a0916f
|
|
@ -4,6 +4,8 @@
|
||||||
# License: GPL-3.0
|
# License: GPL-3.0
|
||||||
# Project: KiBot (formerly KiPlot)
|
# Project: KiBot (formerly KiPlot)
|
||||||
from .registrable import RegVariant
|
from .registrable import RegVariant
|
||||||
|
from .optionable import Optionable
|
||||||
|
from .fil_base import BaseFilter
|
||||||
from .macros import macros, document # noqa: F401
|
from .macros import macros, document # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,3 +22,34 @@ class BaseVariant(RegVariant):
|
||||||
""" A comment for documentation purposes """
|
""" A comment for documentation purposes """
|
||||||
self.file_id = ''
|
self.file_id = ''
|
||||||
""" Text to use as the """
|
""" Text to use as the """
|
||||||
|
# * Filters
|
||||||
|
self.exclude_filter = Optionable
|
||||||
|
""" [string|list(string)=''] Name of the filter to exclude components from BoM processing.
|
||||||
|
Use '_mechanical' for the default KiBoM behavior """
|
||||||
|
self.dnf_filter = Optionable
|
||||||
|
""" [string|list(string)=''] Name of the filter to mark components as 'Do Not Fit'.
|
||||||
|
Use '_kibom_dnf' for the default KiBoM behavior """
|
||||||
|
self.dnc_filter = Optionable
|
||||||
|
""" [string|list(string)=''] Name of the filter to mark components as 'Do Not Change'.
|
||||||
|
Use '_kibom_dnc' for the default KiBoM behavior """
|
||||||
|
|
||||||
|
def config(self):
|
||||||
|
super().config()
|
||||||
|
# exclude_filter
|
||||||
|
self.exclude_filter = BaseFilter.solve_filter(self.exclude_filter, 'exclude_filter')
|
||||||
|
# dnf_filter
|
||||||
|
self.dnf_filter = BaseFilter.solve_filter(self.dnf_filter, 'dnf_filter')
|
||||||
|
# dnc_filter
|
||||||
|
self.dnc_filter = BaseFilter.solve_filter(self.dnc_filter, 'dnc_filter')
|
||||||
|
|
||||||
|
def filter(self, comps):
|
||||||
|
# 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)
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ class IBoM(BaseVariant): # noqa: F821
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def filter(self, comps):
|
def filter(self, comps):
|
||||||
|
super().filter(comps)
|
||||||
logger.debug("Applying IBoM style variants `{}`".format(self.name))
|
logger.debug("Applying IBoM style variants `{}`".format(self.name))
|
||||||
# Make black/white lists case insensitive
|
# Make black/white lists case insensitive
|
||||||
self.variants_whitelist = [v.lower() for v in self.variants_whitelist]
|
self.variants_whitelist = [v.lower() for v in self.variants_whitelist]
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ class KiBoM(BaseVariant): # noqa: F821
|
||||||
return not exclusive
|
return not exclusive
|
||||||
|
|
||||||
def filter(self, comps):
|
def filter(self, comps):
|
||||||
|
super().filter(comps)
|
||||||
logger.debug("Applying KiBoM style variants `{}`".format(self.name))
|
logger.debug("Applying KiBoM style variants `{}`".format(self.name))
|
||||||
for c in comps:
|
for c in comps:
|
||||||
if not (c.fitted and c.in_bom):
|
if not (c.fitted and c.in_bom):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue