diff --git a/examples/ex02.bom.tsv b/examples/ex02.bom.tsv index 4c8d11e3..a85de3ed 100644 --- a/examples/ex02.bom.tsv +++ b/examples/ex02.bom.tsv @@ -1,4 +1,5 @@ Item Qty Unit Designators Connector, Molex Micro-Fit, female, 2 pins 3 X2, X3, X4 Connector, Molex Micro-Fit, male, 2 pins 1 X1 -Cable, 2 x 0.25 mm² 0.6 m W1, W2, W3 +Cable, 2 x 0.25 mm² 0.4 m W1, W2 +Cable, 2 x 20 awg 0.2 m W3 diff --git a/examples/ex02.gv b/examples/ex02.gv index b914864f..030934da 100644 --- a/examples/ex02.gv +++ b/examples/ex02.gv @@ -28,5 +28,5 @@ graph { edge [color="#000000:#ff0000:#000000"] X1:p2r:e -- W3:w2:w W3:w2:e -- X4:p2l:w - W3 [label=<
W3
2x0.25 mm² (24 AWG)0.2 m
 
X1:1BKX4:1
X1:2RDX4:2
 
> fillcolor=white margin=0 shape=box style=""] + W3 [label=<
W3
2x20 awg (0.75 mm²)0.2 m
 
X1:1BKX4:1
X1:2RDX4:2
 
> fillcolor=white margin=0 shape=box style=""] } diff --git a/examples/ex02.html b/examples/ex02.html index 148fa572..aafa0e9d 100644 --- a/examples/ex02.html +++ b/examples/ex02.html @@ -1,7 +1,7 @@

Diagram

- W3 - - -W3 - -2x - -0.25 mm² (24 AWG) - -0.2 m -  -X1:1 -BK -X4:1 - - - -X1:2 -RD -X4:2 - - - -  + + +W3 + +2x + +20 awg (0.75 mm²) + +0.2 m +  +X1:1 +BK +X4:1 + + + +X1:2 +RD +X4:2 + + + +  X1:e--W3:w - - - + + + X1:e--W3:w - - - + + + @@ -242,17 +242,17 @@ W3:e--X4:w - - - + + + W3:e--X4:w - - - + + + -

Bill of Materials

ItemQtyUnitDesignators
Connector, Molex Micro-Fit, female, 2 pins3X2, X3, X4
Connector, Molex Micro-Fit, male, 2 pins1X1
Cable, 2 x 0.25 mm²0.6mW1, W2, W3
\ No newline at end of file +

Bill of Materials

ItemQtyUnitDesignators
Connector, Molex Micro-Fit, female, 2 pins3X2, X3, X4
Connector, Molex Micro-Fit, male, 2 pins1X1
Cable, 2 x 0.25 mm²0.4mW1, W2
Cable, 2 x 20 awg0.2mW3
\ No newline at end of file diff --git a/examples/ex02.png b/examples/ex02.png index 7dbb395b..0a989728 100644 Binary files a/examples/ex02.png and b/examples/ex02.png differ diff --git a/examples/ex02.svg b/examples/ex02.svg index 6ddeb7b1..fe7e3a19 100644 --- a/examples/ex02.svg +++ b/examples/ex02.svg @@ -1,7 +1,7 @@ - W3 - - -W3 - -2x - -0.25 mm² (24 AWG) - -0.2 m -  -X1:1 -BK -X4:1 - - - -X1:2 -RD -X4:2 - - - -  + + +W3 + +2x + +20 awg (0.75 mm²) + +0.2 m +  +X1:1 +BK +X4:1 + + + +X1:2 +RD +X4:2 + + + +  X1:e--W3:w - - - + + + X1:e--W3:w - - - + + + @@ -242,16 +242,16 @@ W3:e--X4:w - - - + + + W3:e--X4:w - - - + + + diff --git a/examples/ex02.yml b/examples/ex02.yml index 056e6fe4..8a671e67 100644 --- a/examples/ex02.yml +++ b/examples/ex02.yml @@ -22,6 +22,7 @@ cables: <<: *wire_power # create from template W3: <<: *wire_power # create from template + gauge: 20 awg connections: - diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index a2f2a9ee..6bc9eb87 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -83,7 +83,12 @@ def __post_init__(self): except Exception: raise Exception('Gauge must be a number, or number and unit separated by a space') self.gauge = g - self.gauge_unit = u.replace('mm2', 'mm\u00B2') + + if u.upper() == 'AWG': + self.gauge_unit = u.upper() + else: + self.gauge_unit = u.replace('mm2', 'mm\u00B2') + elif self.gauge is not None: # gauge specified, assume mm2 if self.gauge_unit is None: self.gauge_unit = 'mm\u00B2' diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c11ad9a5..c50384e1 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -4,7 +4,7 @@ from wireviz.DataClasses import Connector, Cable from graphviz import Graph from wireviz import wv_colors -from wireviz.wv_helper import awg_equiv, tuplelist2tsv, nested, flatten2d +from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d from collections import Counter from typing import List @@ -113,9 +113,19 @@ def create_graph(self): f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}') for _, cable in self.cables.items(): - awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)' if cable.gauge_unit == 'mm\u00B2' and cable.show_equiv else '' + + awg_fmt = '' + if cable.show_equiv: + # Only convert units we actually know about, i.e. currently + # mm2 and awg --- other units _are_ technically allowed, + # and passed through as-is. + if cable.gauge_unit =='mm\u00B2': + awg_fmt = f' ({awg_equiv(cable.gauge)} AWG)' + elif cable.gauge_unit.upper() == 'AWG': + awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' + attributes = [f'{len(cable.colors)}x' if cable.show_wirecount else '', - f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', # TODO: show equiv + f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', '+ S' if cable.shield else '', f'{cable.length} m' if cable.length > 0 else ''] attributes = list(filter(None, attributes)) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 65ccdb34..222fd744 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -3,32 +3,32 @@ from typing import List +awg_equiv_table = { + '0.09': '28', + '0.14': '26', + '0.25': '24', + '0.34': '22', + '0.5': '21', + '0.75': '20', + '1': '18', + '1.5': '16', + '2.5': '14', + '4': '12', + '6': '10', + '10': '8', + '16': '6', + '25': '4', + '35': '2', + '50': '1', +} + +mm2_equiv_table = {v:k for k,v in awg_equiv_table.items()} def awg_equiv(mm2): - awg_equiv_table = { - '0.09': 28, - '0.14': 26, - '0.25': 24, - '0.34': 22, - '0.5': 21, - '0.75': 20, - '1': 18, - '1.5': 16, - '2.5': 14, - '4': 12, - '6': 10, - '10': 8, - '16': 6, - '25': 4, - '35': 2, - '50': 1, - } - k = str(mm2) - if k in awg_equiv_table: - return awg_equiv_table[k] - else: - return 'unknown' + return awg_equiv_table.get(str(mm2), 'Unknown') +def mm2_equiv(awg): + return mm2_equiv_table.get(str(awg), 'Unknown') def nested(inp): l = []