Optimized the list of fields reported by the components.

Avoiding to iterate on fields that we'll reject and also providing the
value in the same operation.
This commit is contained in:
Salvador E. Tropea 2020-08-01 19:11:58 -03:00
parent f062eca7aa
commit 71c87bf2ea
2 changed files with 8 additions and 5 deletions

View File

@ -4,7 +4,6 @@ This code is adapted from https://github.com/SchrodingersGat/KiBoM by Oliver Hen
Here is all the logic to convert a list of components into the rows and columns used to create the BoM.
"""
# TODO Sheetpath
from .units import compare_values, comp_match
from .bom_writer import write_bom
from .columnlist import ColumnList
@ -237,10 +236,8 @@ class ComponentGroup(object):
def update_fields(self, usealt=False):
for c in self.components:
for f in c.get_field_names():
# TODO optimize the list is simple and positions fixed
# Value and datasheet aren't special
self.update_field(f, c.get_field_value(f))
for f, v in c.get_user_fields():
self.update_field(f, v)
# Update 'global' fields
if usealt:
self.fields[ColumnList.COL_REFERENCE_L] = self.get_alt_refs()

View File

@ -583,6 +583,12 @@ class SchematicComponent(object):
def get_field_names(self):
return [f.name for f in self.fields]
def get_user_fields(self):
""" Returns a list of tuples with the user defined fields (name, value) """
if len(self.fields) < 4:
return []
return [(f.name, f.value) for f in self.fields[4:]]
def add_field(self, field):
self.fields.append(field)
self.dfields[field.name.lower()] = field