Skip to content

Commit

Permalink
Modified the R/L/C sort to try to make sense of the multiplier (kilo,…
Browse files Browse the repository at this point in the history
… nano, etc.)
  • Loading branch information
set-soft committed Jul 18, 2020
1 parent 02407b9 commit 65b841b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 16 additions & 0 deletions kibom/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kibom/netlist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions kibom/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 65b841b

Please sign in to comment.