diff --git a/kibom/component.py b/kibom/component.py index bbef31f..673315e 100644 --- a/kibom/component.py +++ b/kibom/component.py @@ -201,6 +201,22 @@ def setValue(self, value): def getValue(self): return self.element.get("value") + # Try to better sort R, L and C components + def getValueSort(self): + pref = self.getPrefix() + if pref in 'RLC' or pref == 'RV': + res = units.compMatch(self.getValue()) + if res: + value, mult, unit = res + if pref in "CL": + # fempto Farads + value = "{0:15d}".format(int(value * 1e15 * mult + 0.1)) + else: + # milli Ohms + value = "{0:15d}".format(int(value * 1000 * mult + 0.1)) + return value + return self.element.get("value") + def getField(self, name, ignoreCase=True, libraryToo=True): """Return the value of a field named name. The component is first checked for the field, and then the components library part is checked diff --git a/kibom/netlist_reader.py b/kibom/netlist_reader.py index 7fe15d3..328c278 100644 --- a/kibom/netlist_reader.py +++ b/kibom/netlist_reader.py @@ -358,7 +358,7 @@ def groupComponents(self, components): # Sort the groups # First priority is the Type of component (e.g. R?, U?, L?) - groups = sorted(groups, key=lambda g: [g.components[0].getPrefix(), g.components[0].getValue()]) + groups = sorted(groups, key=lambda g: [g.components[0].getPrefix(), g.components[0].getValueSort()]) return groups diff --git a/kibom/units.py b/kibom/units.py index 19dc243..f8b598e 100644 --- a/kibom/units.py +++ b/kibom/units.py @@ -139,9 +139,7 @@ def compMatch(component): except: return None - val = "{0:.15f}".format(val * 1.0 * getPrefix(prefix)) - - return (val, getUnit(units)) + return (val, getPrefix(prefix), getUnit(units)) def componentValue(valString): @@ -168,8 +166,11 @@ def compareValues(c1, c2): if not r1 or not r2: return False - (v1, u1) = r1 - (v2, u2) = r2 + (v1, p1, u1) = r1 + (v2, p2, u2) = r2 + + v1 = "{0:.15f}".format(v1 * 1.0 * p1) + v2 = "{0:.15f}".format(v2 * 1.0 * p2) if v1 == v2: # Values match