Skip to content

Commit

Permalink
Merge pull request #1 from Tyler-Ward/feature/part_number
Browse files Browse the repository at this point in the history
Feature/part number
  • Loading branch information
aakatz3 authored Jun 24, 2020
2 parents 66a4716 + 0aa1392 commit ffafbda
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 359 deletions.
8 changes: 4 additions & 4 deletions examples/ex02.bom.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Item Qty Unit Designators
Molex Micro-Fit, female, 2 pins 3 X2, X3, X4
Molex Micro-Fit, male, 2 pins 1 X1
Cable 2 x 0.25 mm² 0.6 m W1, W2, W3
Item Qty Unit Designators Part number
Connector, Molex Micro-Fit, female, 2 pins 3 X2, X3, X4 436450200
Connector, Molex Micro-Fit, male, 2 pins 1 X1 436400200
Cable, 2 x 0.25 mm² 0.6 m W1, W2, W3
8 changes: 4 additions & 4 deletions examples/ex02.gv
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ graph {
graph [bgcolor=white fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor=white fontname=arial shape=record style=filled]
edge [fontname=arial style=bold]
X1 [label="X1|{Molex Micro-Fit|male|2-pin}|{{GND|VCC}|{<p1r>1|<p2r>2}}"]
X2 [label="X2|{Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
X3 [label="X3|{Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
X4 [label="X4|{Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
X1 [label="X1|{436400200|Molex Micro-Fit|male|2-pin}|{{GND|VCC}|{<p1r>1|<p2r>2}}"]
X2 [label="X2|{436450200|Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
X3 [label="X3|{436450200|Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
X4 [label="X4|{436450200|Molex Micro-Fit|female|2-pin}|{{<p1l>1|<p2l>2}|{GND|VCC}}"]
edge [color="#000000:#000000:#000000"]
X1:p1r:e -- W1:w1:w
W1:w1:e -- X2:p1l:w
Expand Down
359 changes: 184 additions & 175 deletions examples/ex02.html

Large diffs are not rendered by default.

Binary file modified examples/ex02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
357 changes: 183 additions & 174 deletions examples/ex02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/ex02.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ connectors:
type: Molex Micro-Fit
subtype: male
pinout: [GND, VCC]
part_number: 436400200
X2: &con_power_f # define template
type: Molex Micro-Fit
subtype: female
pinout: [GND, VCC]
part_number: 436450200
X3:
<<: *con_power_f # create from template
X4:
Expand Down
16 changes: 14 additions & 2 deletions src/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create_graph(self):

else: # not a ferrule
# a = attributes
a = [n.type,
a = [n.part_number, n.type,
n.subtype,
'{}-pin'.format(len(n.pinout)) if n.show_pincount else '']
# p = pinout
Expand Down Expand Up @@ -111,7 +111,8 @@ def create_graph(self):

for k, c in self.cables.items():
# a = attributes
a = ['{}x'.format(len(c.colors)) if c.show_wirecount else '',
a = [c.part_number,
'{}x'.format(len(c.colors)) if c.show_wirecount else '',
'{} {}{}'.format(c.gauge, c.gauge_unit, ' ({} AWG)'.format(awg_equiv(c.gauge)) if c.gauge_unit == 'mm\u00B2' and c.show_equiv else '') if c.gauge else '', # TODO: show equiv
'+ S' if c.shield else '',
'{} m'.format(c.length) if c.length > 0 else '']
Expand Down Expand Up @@ -241,11 +242,14 @@ def bom(self):
shared = next(iter(items.values()))
designators = list(items.keys())
designators.sort()
part_number = shared.part_number
name = 'Connector{type}{subtype}{pincount}{color}'.format(type = ', {}'.format(shared.type) if shared.type else '',
subtype = ', {}'.format(shared.subtype) if shared.subtype else '',
pincount = ', {} pins'.format(shared.pincount) if shared.category != 'ferrule' else '',
color = ', {}'.format(shared.color) if shared.color else '')
item = {'item': name, 'qty': len(designators), 'unit': '', 'designators': designators if shared.category != 'ferrule' else ''}
if part_number is not None: # set part number only if it exists
item['part number'] = part_number
bom_connectors.append(item)
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
bom.extend(bom_connectors)
Expand All @@ -257,11 +261,14 @@ def bom(self):
if shared.category != 'bundle':
designators = list(items.keys())
designators.sort()
part_number = shared.part_number
total_length = sum(i.length for i in items.values())
name = 'Cable, {wirecount}{gauge}{shield}'.format(wirecount = shared.wirecount,
gauge = ' x {} {}'.format(shared.gauge, shared.gauge_unit) if shared.gauge else ' wires',
shield = ' shielded' if shared.shield else '')
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators}
if part_number is not None: # set part number only if it exists
item['part number'] = part_number
bom_cables.append(item)
# bundles (ignores wirecount)
wirelist = []
Expand Down Expand Up @@ -299,6 +306,9 @@ def bom(self):
def bom_list(self):
bom = self.bom()
keys = ['item', 'qty', 'unit', 'designators']
# check if any part numbers are set
if any("part number" in x for x in bom):
keys.append("part number")
bom_list = []
bom_list.append([k.capitalize() for k in keys]) # create header row with keys
for item in bom:
Expand All @@ -312,6 +322,7 @@ def bom_list(self):
@dataclass
class Connector:
name: str
part_number: str = None
category: str = None
type: str = None
subtype: str = None
Expand Down Expand Up @@ -343,6 +354,7 @@ def loop(self, from_pin, to_pin):
@dataclass
class Cable:
name: str
part_number: str = None
category : str = None
type: str = None
gauge: float = None
Expand Down

0 comments on commit ffafbda

Please sign in to comment.