Added fallback for values+units we can't understand
This commit is contained in:
parent
3eebc04e4b
commit
5e20206da4
|
|
@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
https://forum.kicad.info/t/fab-drawing-for-only-through-hole-parts/
|
https://forum.kicad.info/t/fab-drawing-for-only-through-hole-parts/
|
||||||
- Internal BoM: option to avoid merging components with empty fields.
|
- Internal BoM: option to avoid merging components with empty fields.
|
||||||
Is named `merge_both_blank` and defaults to true.
|
Is named `merge_both_blank` and defaults to true.
|
||||||
|
- Internal BoM: when a `Value` field can't be interpreted as a `number+unit`,
|
||||||
|
and it contain at least one space, now we try to use the text before the
|
||||||
|
space. This helps for cases like "10K 1%".
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Internal BoM: now components with different Tolerance, Voltage, Current
|
- Internal BoM: now components with different Tolerance, Voltage, Current
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ All the logic to convert a list of components into the rows and columns used to
|
||||||
import locale
|
import locale
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from .units import compare_values, comp_match
|
from .units import compare_values, comp_match, get_last_warning
|
||||||
from .bom_writer import write_bom
|
from .bom_writer import write_bom
|
||||||
from .columnlist import ColumnList
|
from .columnlist import ColumnList
|
||||||
from ..misc import DNF, W_FIELDCONF
|
from ..misc import DNF, W_FIELDCONF, W_BADVAL1
|
||||||
from .. import log
|
from .. import log
|
||||||
|
|
||||||
logger = log.get_logger(__name__)
|
logger = log.get_logger(__name__)
|
||||||
|
|
@ -403,7 +403,14 @@ def group_components(cfg, components):
|
||||||
continue
|
continue
|
||||||
# Cache the value used to sort
|
# Cache the value used to sort
|
||||||
if c.ref_prefix in RLC_PREFIX and c.value.lower() not in DNF:
|
if c.ref_prefix in RLC_PREFIX and c.value.lower() not in DNF:
|
||||||
c.value_sort = comp_match(c.value, c.ref_prefix)
|
c.value_sort = comp_match(c.value, c.ref_prefix, c.ref)
|
||||||
|
if c.value_sort is None and (' ' in c.value):
|
||||||
|
# Try with the data before a space
|
||||||
|
value = c.value.split(' ')[0]
|
||||||
|
value_sort = comp_match(value, c.ref_prefix)
|
||||||
|
if value_sort is not None:
|
||||||
|
c.value_sort = value_sort
|
||||||
|
logger.warning(get_last_warning() + "Using `{}` for {} instead".format(value, c.ref))
|
||||||
else:
|
else:
|
||||||
c.value_sort = None
|
c.value_sort = None
|
||||||
# Try to add the component to an existing group
|
# Try to add the component to an existing group
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ UNIT_ALL = UNIT_R + UNIT_C + UNIT_L
|
||||||
match = None
|
match = None
|
||||||
# Current locale decimal point value
|
# Current locale decimal point value
|
||||||
decimal_point = None
|
decimal_point = None
|
||||||
|
# Last warning
|
||||||
|
last_warning = ''
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_warning():
|
||||||
|
return last_warning
|
||||||
|
|
||||||
|
|
||||||
def get_unit(unit, ref_prefix):
|
def get_unit(unit, ref_prefix):
|
||||||
|
|
@ -98,12 +104,13 @@ def match_string():
|
||||||
return r"(\d*\.?\d*)\s*(" + group_string(PREFIX_ALL) + ")*(" + group_string(UNIT_ALL) + r")*(\d*)$"
|
return r"(\d*\.?\d*)\s*(" + group_string(PREFIX_ALL) + ")*(" + group_string(UNIT_ALL) + r")*(\d*)$"
|
||||||
|
|
||||||
|
|
||||||
def comp_match(component, ref_prefix):
|
def comp_match(component, ref_prefix, ref=None):
|
||||||
"""
|
"""
|
||||||
Return a normalized value and units for a given component value string
|
Return a normalized value and units for a given component value string
|
||||||
e.g. comp_match('10R2') returns (10, R)
|
e.g. comp_match('10R2') returns (10, R)
|
||||||
e.g. comp_match('3.3mOhm') returns (0.0033, R)
|
e.g. comp_match('3.3mOhm') returns (0.0033, R)
|
||||||
"""
|
"""
|
||||||
|
global last_warning
|
||||||
original = component
|
original = component
|
||||||
# Remove useless spaces
|
# Remove useless spaces
|
||||||
component = component.strip()
|
component = component.strip()
|
||||||
|
|
@ -130,14 +137,17 @@ def comp_match(component, ref_prefix):
|
||||||
# Ignore case
|
# Ignore case
|
||||||
match = re.compile(match_string(), flags=re.IGNORECASE)
|
match = re.compile(match_string(), flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
where = ' in {}'.format(ref) if ref is not None else ''
|
||||||
result = match.match(component)
|
result = match.match(component)
|
||||||
if not result:
|
if not result:
|
||||||
logger.warning(W_BADVAL1 + "Malformed value: `{}` (no match)".format(original))
|
last_warning = W_BADVAL1
|
||||||
|
logger.warning(W_BADVAL1 + "Malformed value: `{}` (no match{})".format(original, where))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
value, prefix, units, post = result.groups()
|
value, prefix, units, post = result.groups()
|
||||||
if value == '.':
|
if value == '.':
|
||||||
logger.warning(W_BADVAL2 + "Malformed value: `{}` (reduced to decimal point)".format(original))
|
last_warning = W_BADVAL2
|
||||||
|
logger.warning(W_BADVAL2 + "Malformed value: `{}` (reduced to decimal point{})".format(original, where))
|
||||||
return None
|
return None
|
||||||
if value == '':
|
if value == '':
|
||||||
value = '0'
|
value = '0'
|
||||||
|
|
@ -148,7 +158,8 @@ def comp_match(component, ref_prefix):
|
||||||
# We will also have a trailing number
|
# We will also have a trailing number
|
||||||
if post:
|
if post:
|
||||||
if "." in value:
|
if "." in value:
|
||||||
logger.warning(W_BADVAL3 + "Malformed value: `{}` (unit split, but contains decimal point)".format(original))
|
last_warning = W_BADVAL3
|
||||||
|
logger.warning(W_BADVAL3 + "Malformed value: `{}` (unit split, but contains decimal point)".format(original, where))
|
||||||
return None
|
return None
|
||||||
value = float(value)
|
value = float(value)
|
||||||
postValue = float(post) / (10 ** len(post))
|
postValue = float(post) / (10 ** len(post))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue