Fixed the components fields reset mechanism.
My previous approach was incomplete.
This commit is contained in:
parent
9f8ecff5d1
commit
007fc36d1e
|
|
@ -80,6 +80,15 @@ def apply_exclude_filter(comps, filter):
|
|||
c.included = filter.filter(c)
|
||||
|
||||
|
||||
def reset_filters(comps):
|
||||
logger.debug('Filters reset')
|
||||
for c in comps:
|
||||
c.included = True
|
||||
c.fitted = True
|
||||
c.fixed = False
|
||||
c.back_up_fields()
|
||||
|
||||
|
||||
def apply_fitted_filter(comps, filter):
|
||||
if filter:
|
||||
logger.debug('Applying filter `{}` to fitted'.format(filter.name))
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ Currently oriented to collect the components for the BoM.
|
|||
# Encapsulate file/line
|
||||
import re
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from collections import OrderedDict
|
||||
from .config import KiConf, un_quote
|
||||
from ..gs import GS
|
||||
|
|
@ -855,6 +856,19 @@ class SchematicComponent(object):
|
|||
self.fields.append(field)
|
||||
self.dfields[field.name.lower()] = field
|
||||
|
||||
def back_up_fields(self):
|
||||
""" First call makes a back-up of the fields.
|
||||
Next calls restores the back-up. """
|
||||
if self.fields_bkp:
|
||||
# We have a back-up, restore from it
|
||||
self.fields = deepcopy(self.fields_bkp)
|
||||
self.dfields = {f.name.lower(): f for f in self.fields}
|
||||
self._solve_fields(LineReader(None, '**Internal**'))
|
||||
else:
|
||||
# No back-up. Make one for the next reset
|
||||
self.fields_bkp = deepcopy(self.fields)
|
||||
self.dfields_bkp = {f.name.lower(): f for f in self.fields_bkp}
|
||||
|
||||
def _solve_ref(self, path):
|
||||
""" Look fo the correct reference for this path.
|
||||
Returns the default reference if no paths defined.
|
||||
|
|
@ -966,6 +980,8 @@ class SchematicComponent(object):
|
|||
# F field_number "text" orientation posX posY size Flags (see below) hjustify vjustify/italic/bold "name"
|
||||
comp.fields = []
|
||||
comp.dfields = {}
|
||||
comp.fields_bkp = None
|
||||
comp.dfields_bkp = None
|
||||
while line[0] == 'F':
|
||||
field = SchematicField.parse(line, f)
|
||||
name_lc = field.name.lower()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
# Copyright (c) 2020 Instituto Nacional de Tecnología Industrial
|
||||
# License: GPL-3.0
|
||||
# Project: KiBot (formerly KiPlot)
|
||||
from copy import deepcopy
|
||||
from .gs import GS
|
||||
from .kiplot import load_sch
|
||||
from .misc import Rect, KICAD_VERSION_5_99, W_WRONGPASTE
|
||||
|
|
@ -14,7 +13,7 @@ else:
|
|||
from pcbnew import EDGE_MODULE, wxPoint, LSET
|
||||
from .registrable import RegOutput
|
||||
from .optionable import Optionable, BaseOptions
|
||||
from .fil_base import BaseFilter, apply_fitted_filter
|
||||
from .fil_base import BaseFilter, apply_fitted_filter, reset_filters
|
||||
from .macros import macros, document # noqa: F401
|
||||
from . import log
|
||||
|
||||
|
|
@ -260,9 +259,9 @@ class VariantOptions(BaseOptions):
|
|||
return
|
||||
load_sch()
|
||||
# Get the components list from the schematic
|
||||
# Note: we work with a copy to avoid changes by filters affecting other outputs
|
||||
comps = deepcopy(GS.sch.get_components())
|
||||
comps = GS.sch.get_components()
|
||||
# Apply the filter
|
||||
reset_filters(comps)
|
||||
apply_fitted_filter(comps, self.dnf_filter)
|
||||
# Apply the variant
|
||||
if self.variant:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ Internal BoM (Bill of Materials) output for KiBot.
|
|||
This is somehow compatible with KiBoM.
|
||||
"""
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from .gs import GS
|
||||
from .optionable import Optionable, BaseOptions
|
||||
from .registrable import RegOutput
|
||||
|
|
@ -18,7 +17,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, apply_exclude_filter, apply_fitted_filter, apply_fixed_filter
|
||||
from .fil_base import BaseFilter, apply_exclude_filter, apply_fitted_filter, apply_fixed_filter, reset_filters
|
||||
from . import log
|
||||
# To debug the `with document` we can use:
|
||||
# from .mcpyrate.debug import macros, step_expansion
|
||||
|
|
@ -374,9 +373,8 @@ class BoMOptions(BaseOptions):
|
|||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
get_board_comps_data(comps)
|
||||
# We work with a copy to avoid changes by filters affecting other outputs
|
||||
comps = deepcopy(comps)
|
||||
# Apply all the filters
|
||||
reset_filters(comps)
|
||||
apply_exclude_filter(comps, self.exclude_filter)
|
||||
apply_fitted_filter(comps, self.dnf_filter)
|
||||
apply_fixed_filter(comps, self.dnc_filter)
|
||||
|
|
|
|||
|
|
@ -1244,7 +1244,6 @@ def test_int_bom_variant_rename_1():
|
|||
ctx.run(extra_debug=True)
|
||||
rows, header, info = ctx.load_csv(prj+'-bom_(PROD).csv')
|
||||
ref_column = header.index(REF_COLUMN_NAME)
|
||||
val_column = header.index(VALUE_COLUMN_NAME)
|
||||
check_kibom_test_netlist(rows, ref_column, 2, ['R2', 'D2'], ['R1', 'D1'])
|
||||
rows, header, info = ctx.load_csv(prj+'-bom_(DEV).csv')
|
||||
check_kibom_test_netlist(rows, ref_column, 3, None, ['R1', 'R2', 'D1', 'D2'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue