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)
|
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):
|
def apply_fitted_filter(comps, filter):
|
||||||
if filter:
|
if filter:
|
||||||
logger.debug('Applying filter `{}` to fitted'.format(filter.name))
|
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
|
# Encapsulate file/line
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
from copy import deepcopy
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from .config import KiConf, un_quote
|
from .config import KiConf, un_quote
|
||||||
from ..gs import GS
|
from ..gs import GS
|
||||||
|
|
@ -855,6 +856,19 @@ class SchematicComponent(object):
|
||||||
self.fields.append(field)
|
self.fields.append(field)
|
||||||
self.dfields[field.name.lower()] = 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):
|
def _solve_ref(self, path):
|
||||||
""" Look fo the correct reference for this path.
|
""" Look fo the correct reference for this path.
|
||||||
Returns the default reference if no paths defined.
|
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"
|
# F field_number "text" orientation posX posY size Flags (see below) hjustify vjustify/italic/bold "name"
|
||||||
comp.fields = []
|
comp.fields = []
|
||||||
comp.dfields = {}
|
comp.dfields = {}
|
||||||
|
comp.fields_bkp = None
|
||||||
|
comp.dfields_bkp = None
|
||||||
while line[0] == 'F':
|
while line[0] == 'F':
|
||||||
field = SchematicField.parse(line, f)
|
field = SchematicField.parse(line, f)
|
||||||
name_lc = field.name.lower()
|
name_lc = field.name.lower()
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
# Copyright (c) 2020 Instituto Nacional de Tecnología Industrial
|
# Copyright (c) 2020 Instituto Nacional de Tecnología Industrial
|
||||||
# License: GPL-3.0
|
# License: GPL-3.0
|
||||||
# Project: KiBot (formerly KiPlot)
|
# Project: KiBot (formerly KiPlot)
|
||||||
from copy import deepcopy
|
|
||||||
from .gs import GS
|
from .gs import GS
|
||||||
from .kiplot import load_sch
|
from .kiplot import load_sch
|
||||||
from .misc import Rect, KICAD_VERSION_5_99, W_WRONGPASTE
|
from .misc import Rect, KICAD_VERSION_5_99, W_WRONGPASTE
|
||||||
|
|
@ -14,7 +13,7 @@ else:
|
||||||
from pcbnew import EDGE_MODULE, wxPoint, LSET
|
from pcbnew import EDGE_MODULE, wxPoint, LSET
|
||||||
from .registrable import RegOutput
|
from .registrable import RegOutput
|
||||||
from .optionable import Optionable, BaseOptions
|
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 .macros import macros, document # noqa: F401
|
||||||
from . import log
|
from . import log
|
||||||
|
|
||||||
|
|
@ -260,9 +259,9 @@ class VariantOptions(BaseOptions):
|
||||||
return
|
return
|
||||||
load_sch()
|
load_sch()
|
||||||
# Get the components list from the schematic
|
# Get the components list from the schematic
|
||||||
# Note: we work with a copy to avoid changes by filters affecting other outputs
|
comps = GS.sch.get_components()
|
||||||
comps = deepcopy(GS.sch.get_components())
|
|
||||||
# Apply the filter
|
# Apply the filter
|
||||||
|
reset_filters(comps)
|
||||||
apply_fitted_filter(comps, self.dnf_filter)
|
apply_fitted_filter(comps, self.dnf_filter)
|
||||||
# Apply the variant
|
# Apply the variant
|
||||||
if self.variant:
|
if self.variant:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ Internal BoM (Bill of Materials) output for KiBot.
|
||||||
This is somehow compatible with KiBoM.
|
This is somehow compatible with KiBoM.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from copy import deepcopy
|
|
||||||
from .gs import GS
|
from .gs import GS
|
||||||
from .optionable import Optionable, BaseOptions
|
from .optionable import Optionable, BaseOptions
|
||||||
from .registrable import RegOutput
|
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.columnlist import ColumnList, BoMError
|
||||||
from .bom.bom import do_bom
|
from .bom.bom import do_bom
|
||||||
from .var_kibom import KiBoM
|
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
|
from . import log
|
||||||
# To debug the `with document` we can use:
|
# To debug the `with document` we can use:
|
||||||
# from .mcpyrate.debug import macros, step_expansion
|
# from .mcpyrate.debug import macros, step_expansion
|
||||||
|
|
@ -374,9 +373,8 @@ class BoMOptions(BaseOptions):
|
||||||
# Get the components list from the schematic
|
# Get the components list from the schematic
|
||||||
comps = GS.sch.get_components()
|
comps = GS.sch.get_components()
|
||||||
get_board_comps_data(comps)
|
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
|
# Apply all the filters
|
||||||
|
reset_filters(comps)
|
||||||
apply_exclude_filter(comps, self.exclude_filter)
|
apply_exclude_filter(comps, self.exclude_filter)
|
||||||
apply_fitted_filter(comps, self.dnf_filter)
|
apply_fitted_filter(comps, self.dnf_filter)
|
||||||
apply_fixed_filter(comps, self.dnc_filter)
|
apply_fixed_filter(comps, self.dnc_filter)
|
||||||
|
|
|
||||||
|
|
@ -1244,7 +1244,6 @@ def test_int_bom_variant_rename_1():
|
||||||
ctx.run(extra_debug=True)
|
ctx.run(extra_debug=True)
|
||||||
rows, header, info = ctx.load_csv(prj+'-bom_(PROD).csv')
|
rows, header, info = ctx.load_csv(prj+'-bom_(PROD).csv')
|
||||||
ref_column = header.index(REF_COLUMN_NAME)
|
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'])
|
check_kibom_test_netlist(rows, ref_column, 2, ['R2', 'D2'], ['R1', 'D1'])
|
||||||
rows, header, info = ctx.load_csv(prj+'-bom_(DEV).csv')
|
rows, header, info = ctx.load_csv(prj+'-bom_(DEV).csv')
|
||||||
check_kibom_test_netlist(rows, ref_column, 3, None, ['R1', 'R2', 'D1', 'D2'])
|
check_kibom_test_netlist(rows, ref_column, 3, None, ['R1', 'R2', 'D1', 'D2'])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue