Feature: bidirectional AWG/mm2 unit conversion (#41)

* Fix AWG<-> mm2 conversions

Add an inverted dictionary and a lookup function from awg -> mm2. Also
do some minor refactoring. Both sides of the conversion table were
converted to strings, since '0000' and '2/0' are perfectly valid AWG
values.

* Update example ex02 with awg -> mm2 conversion

Show conversions for ex02, and make sure it displays conversions in both
directions. Rebuild the example files.

* Fix faulty conversion of non-(mm2,AWG) units

The parsing allows arbitrary units to be used for cable dimensions --
this might be valid units, e.g. square inches, or invalid, e.g. bananas.
We only allow conversion between mm2 and AWG, so check that the
gauge_unit is either of those before conversion. If not, pass through as
is.

* Fix AWG string casing in output

Convert e.g. 'awg, 'AwG' to upper case for consistent rendering. Leave
any other input gauge units as they were.

Co-authored-by: Daniel Rojas <github@danielrojas.net>
This commit is contained in:
Andreas Nordin 2020-06-29 14:41:45 +02:00 committed by GitHub
parent c7014a2ea0
commit 08e53bcd48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 119 additions and 102 deletions

View File

@ -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

1 Item Qty Unit Designators
2 Connector, Molex Micro-Fit, female, 2 pins 3 X2, X3, X4
3 Connector, Molex Micro-Fit, male, 2 pins 1 X1
4 Cable, 2 x 0.25 mm² 0.6 0.4 m W1, W2, W3 W1, W2
5 Cable, 2 x 20 awg 0.2 m W3

View File

@ -28,5 +28,5 @@ graph {
edge [color="#000000:#ff0000:#000000"]
X1:p2r:e -- W3:w2:w
W3:w2:e -- X4:p2l:w
W3 [label=<<table border="0" cellspacing="0" cellpadding="0"><tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr><td colspan="3">W3</td></tr><tr><td>2x</td><td>0.25 mm² (24 AWG)</td><td>0.2 m</td></tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table border="0" cellspacing="0" cellborder="0"><tr><td>X1:1</td><td>BK</td><td>X4:1</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#000000" border="2" sides="tb" port="w1"></td></tr><tr><td>X1:2</td><td>RD</td><td>X4:2</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ff0000" border="2" sides="tb" port="w2"></td></tr><tr><td>&nbsp;</td></tr></table></td></tr></table>> fillcolor=white margin=0 shape=box style=""]
W3 [label=<<table border="0" cellspacing="0" cellpadding="0"><tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr><td colspan="3">W3</td></tr><tr><td>2x</td><td>20 awg (0.75 mm²)</td><td>0.2 m</td></tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table border="0" cellspacing="0" cellborder="0"><tr><td>X1:1</td><td>BK</td><td>X4:1</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#000000" border="2" sides="tb" port="w1"></td></tr><tr><td>X1:2</td><td>RD</td><td>X4:2</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ff0000" border="2" sides="tb" port="w2"></td></tr><tr><td>&nbsp;</td></tr></table></td></tr></table>> fillcolor=white margin=0 shape=box style=""]
}

View File

@ -1,7 +1,7 @@
<html><body style="font-family:Arial"><h1>Diagram</h1><?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.44.0 (20200408.0750)
<!-- Generated by graphviz version 2.44.0 (0)
-->
<!-- Pages: 1 -->
<svg width="913pt" height="446pt"
@ -113,43 +113,43 @@
<!-- W3 -->
<g id="node7" class="node">
<title>W3</title>
<polygon fill="none" stroke="black" points="546,-130 348,-130 348,0 546,0 546,-130"/>
<polygon fill="none" stroke="black" points="348,-107 348,-130 546,-130 546,-107 348,-107"/>
<text text-anchor="start" x="436" y="-114.8" font-family="arial" font-size="14.00">W3</text>
<polygon fill="none" stroke="black" points="348,-84 348,-107 371,-107 371,-84 348,-84"/>
<text text-anchor="start" x="352" y="-91.8" font-family="arial" font-size="14.00">2x</text>
<polygon fill="none" stroke="black" points="371,-84 371,-107 503,-107 503,-84 371,-84"/>
<text text-anchor="start" x="375" y="-91.8" font-family="arial" font-size="14.00">0.25 mm² (24 AWG)</text>
<polygon fill="none" stroke="black" points="503,-84 503,-107 546,-107 546,-84 503,-84"/>
<text text-anchor="start" x="507" y="-91.8" font-family="arial" font-size="14.00">0.2 m</text>
<text text-anchor="start" x="445" y="-72.8" font-family="arial" font-size="14.00"> </text>
<text text-anchor="start" x="368.5" y="-55.8" font-family="arial" font-size="14.00">X1:1</text>
<text text-anchor="start" x="438" y="-55.8" font-family="arial" font-size="14.00">BK</text>
<text text-anchor="start" x="498" y="-55.8" font-family="arial" font-size="14.00">X4:1</text>
<polygon fill="#000000" stroke="transparent" points="348,-44 348,-50 546,-50 546,-44 348,-44"/>
<polyline fill="none" stroke="black" stroke-width="2" points="349,-45 545,-45 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="545,-49 349,-49 "/>
<text text-anchor="start" x="368.5" y="-30.8" font-family="arial" font-size="14.00">X1:2</text>
<text text-anchor="start" x="437.5" y="-30.8" font-family="arial" font-size="14.00">RD</text>
<text text-anchor="start" x="498" y="-30.8" font-family="arial" font-size="14.00">X4:2</text>
<polygon fill="#ff0000" stroke="transparent" stroke-width="2" points="348,-19 348,-25 546,-25 546,-19 348,-19"/>
<polyline fill="none" stroke="black" stroke-width="2" points="349,-20 545,-20 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="545,-24 349,-24 "/>
<text text-anchor="start" x="380.5" y="-5.8" font-family="arial" font-size="14.00"> </text>
<polygon fill="none" stroke="black" points="541.5,-130 352.5,-130 352.5,0 541.5,0 541.5,-130"/>
<polygon fill="none" stroke="black" points="353,-107 353,-130 542,-130 542,-107 353,-107"/>
<text text-anchor="start" x="436.5" y="-114.8" font-family="arial" font-size="14.00">W3</text>
<polygon fill="none" stroke="black" points="353,-84 353,-107 376,-107 376,-84 353,-84"/>
<text text-anchor="start" x="357" y="-91.8" font-family="arial" font-size="14.00">2x</text>
<polygon fill="none" stroke="black" points="376,-84 376,-107 499,-107 499,-84 376,-84"/>
<text text-anchor="start" x="380" y="-91.8" font-family="arial" font-size="14.00">20 awg (0.75 mm²)</text>
<polygon fill="none" stroke="black" points="499,-84 499,-107 542,-107 542,-84 499,-84"/>
<text text-anchor="start" x="503" y="-91.8" font-family="arial" font-size="14.00">0.2 m</text>
<text text-anchor="start" x="445.5" y="-72.8" font-family="arial" font-size="14.00"> </text>
<text text-anchor="start" x="372" y="-55.8" font-family="arial" font-size="14.00">X1:1</text>
<text text-anchor="start" x="438.5" y="-55.8" font-family="arial" font-size="14.00">BK</text>
<text text-anchor="start" x="495.5" y="-55.8" font-family="arial" font-size="14.00">X4:1</text>
<polygon fill="#000000" stroke="transparent" points="353,-44 353,-50 542,-50 542,-44 353,-44"/>
<polyline fill="none" stroke="black" stroke-width="2" points="354,-45 541,-45 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="541,-49 354,-49 "/>
<text text-anchor="start" x="372" y="-30.8" font-family="arial" font-size="14.00">X1:2</text>
<text text-anchor="start" x="438" y="-30.8" font-family="arial" font-size="14.00">RD</text>
<text text-anchor="start" x="495.5" y="-30.8" font-family="arial" font-size="14.00">X4:2</text>
<polygon fill="#ff0000" stroke="transparent" stroke-width="2" points="353,-19 353,-25 542,-25 542,-19 353,-19"/>
<polyline fill="none" stroke="black" stroke-width="2" points="354,-20 541,-20 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="541,-24 354,-24 "/>
<text text-anchor="start" x="384" y="-5.8" font-family="arial" font-size="14.00"> </text>
</g>
<!-- X1&#45;&#45;W3 -->
<g id="edge9" class="edge">
<title>X1:e&#45;&#45;W3:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-198C295.45,-200.54 252.69,-47.54 348,-45"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-200C297.38,-200 254.62,-47 348,-47"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-202C299.31,-199.46 256.55,-46.46 348,-49"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-198C296.68,-200.52 255.46,-47.52 352,-45"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-200C298.61,-200 257.39,-47 352,-47"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-202C300.54,-199.48 259.32,-46.48 352,-49"/>
</g>
<!-- X1&#45;&#45;W3 -->
<g id="edge11" class="edge">
<title>X1:e&#45;&#45;W3:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-175C296.11,-177.55 252.05,-22.55 348,-20"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M204,-177C298.03,-177 253.97,-22 348,-22"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-179C299.95,-176.45 255.89,-21.45 348,-24"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-175C297.32,-177.53 254.82,-22.53 352,-20"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M204,-177C299.25,-177 256.75,-22 352,-22"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-179C301.18,-176.47 258.68,-21.47 352,-24"/>
</g>
<!-- X2 -->
<g id="node2" class="node">
@ -242,17 +242,17 @@
<!-- W3&#45;&#45;X4 -->
<g id="edge10" class="edge">
<title>W3:e&#45;&#45;X4:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-45C609.88,-45 625.87,-44 690,-44"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-47C610,-47 626,-46 690,-46"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-49C610.13,-49 626.12,-48 690,-48"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-45C608.21,-45 624.54,-44 690,-44"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-47C608.33,-47 624.67,-46 690,-46"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-49C608.46,-49 624.79,-48 690,-48"/>
</g>
<!-- W3&#45;&#45;X4 -->
<g id="edge12" class="edge">
<title>W3:e&#45;&#45;X4:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-20C610.13,-20 626.12,-21 690,-21"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M546,-22C610,-22 626,-23 690,-23"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-24C609.88,-24 625.87,-25 690,-25"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-20C608.46,-20 624.79,-21 690,-21"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M543,-22C608.33,-22 624.67,-23 690,-23"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-24C608.21,-24 624.54,-25 690,-25"/>
</g>
</g>
</svg>
<h1>Bill of Materials</h1><table style="border:1px solid #000000; font-size: 14pt; border-spacing: 0px"><tr><th align="left" style="border:1px solid #000000; padding: 8px">Item</th><th align="left" style="border:1px solid #000000; padding: 8px">Qty</th><th align="left" style="border:1px solid #000000; padding: 8px">Unit</th><th align="left" style="border:1px solid #000000; padding: 8px">Designators</th></tr><tr><td style="border:1px solid #000000; padding: 4px">Connector, Molex Micro-Fit, female, 2 pins</td><td align="right" style="border:1px solid #000000; padding: 4px">3</td><td style="border:1px solid #000000; padding: 4px"></td><td style="border:1px solid #000000; padding: 4px">X2, X3, X4</td></tr><tr><td style="border:1px solid #000000; padding: 4px">Connector, Molex Micro-Fit, male, 2 pins</td><td align="right" style="border:1px solid #000000; padding: 4px">1</td><td style="border:1px solid #000000; padding: 4px"></td><td style="border:1px solid #000000; padding: 4px">X1</td></tr><tr><td style="border:1px solid #000000; padding: 4px">Cable, 2 x 0.25 mm²</td><td align="right" style="border:1px solid #000000; padding: 4px">0.6</td><td style="border:1px solid #000000; padding: 4px">m</td><td style="border:1px solid #000000; padding: 4px">W1, W2, W3</td></tr></table></body></html>
<h1>Bill of Materials</h1><table style="border:1px solid #000000; font-size: 14pt; border-spacing: 0px"><tr><th align="left" style="border:1px solid #000000; padding: 8px">Item</th><th align="left" style="border:1px solid #000000; padding: 8px">Qty</th><th align="left" style="border:1px solid #000000; padding: 8px">Unit</th><th align="left" style="border:1px solid #000000; padding: 8px">Designators</th></tr><tr><td style="border:1px solid #000000; padding: 4px">Connector, Molex Micro-Fit, female, 2 pins</td><td align="right" style="border:1px solid #000000; padding: 4px">3</td><td style="border:1px solid #000000; padding: 4px"></td><td style="border:1px solid #000000; padding: 4px">X2, X3, X4</td></tr><tr><td style="border:1px solid #000000; padding: 4px">Connector, Molex Micro-Fit, male, 2 pins</td><td align="right" style="border:1px solid #000000; padding: 4px">1</td><td style="border:1px solid #000000; padding: 4px"></td><td style="border:1px solid #000000; padding: 4px">X1</td></tr><tr><td style="border:1px solid #000000; padding: 4px">Cable, 2 x 0.25 mm²</td><td align="right" style="border:1px solid #000000; padding: 4px">0.4</td><td style="border:1px solid #000000; padding: 4px">m</td><td style="border:1px solid #000000; padding: 4px">W1, W2</td></tr><tr><td style="border:1px solid #000000; padding: 4px">Cable, 2 x 20 awg</td><td align="right" style="border:1px solid #000000; padding: 4px">0.2</td><td style="border:1px solid #000000; padding: 4px">m</td><td style="border:1px solid #000000; padding: 4px">W3</td></tr></table></body></html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.44.0 (20200408.0750)
<!-- Generated by graphviz version 2.44.0 (0)
-->
<!-- Pages: 1 -->
<svg width="913pt" height="446pt"
@ -113,43 +113,43 @@
<!-- W3 -->
<g id="node7" class="node">
<title>W3</title>
<polygon fill="none" stroke="black" points="546,-130 348,-130 348,0 546,0 546,-130"/>
<polygon fill="none" stroke="black" points="348,-107 348,-130 546,-130 546,-107 348,-107"/>
<text text-anchor="start" x="436" y="-114.8" font-family="arial" font-size="14.00">W3</text>
<polygon fill="none" stroke="black" points="348,-84 348,-107 371,-107 371,-84 348,-84"/>
<text text-anchor="start" x="352" y="-91.8" font-family="arial" font-size="14.00">2x</text>
<polygon fill="none" stroke="black" points="371,-84 371,-107 503,-107 503,-84 371,-84"/>
<text text-anchor="start" x="375" y="-91.8" font-family="arial" font-size="14.00">0.25 mm² (24 AWG)</text>
<polygon fill="none" stroke="black" points="503,-84 503,-107 546,-107 546,-84 503,-84"/>
<text text-anchor="start" x="507" y="-91.8" font-family="arial" font-size="14.00">0.2 m</text>
<text text-anchor="start" x="445" y="-72.8" font-family="arial" font-size="14.00"> </text>
<text text-anchor="start" x="368.5" y="-55.8" font-family="arial" font-size="14.00">X1:1</text>
<text text-anchor="start" x="438" y="-55.8" font-family="arial" font-size="14.00">BK</text>
<text text-anchor="start" x="498" y="-55.8" font-family="arial" font-size="14.00">X4:1</text>
<polygon fill="#000000" stroke="transparent" points="348,-44 348,-50 546,-50 546,-44 348,-44"/>
<polyline fill="none" stroke="black" stroke-width="2" points="349,-45 545,-45 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="545,-49 349,-49 "/>
<text text-anchor="start" x="368.5" y="-30.8" font-family="arial" font-size="14.00">X1:2</text>
<text text-anchor="start" x="437.5" y="-30.8" font-family="arial" font-size="14.00">RD</text>
<text text-anchor="start" x="498" y="-30.8" font-family="arial" font-size="14.00">X4:2</text>
<polygon fill="#ff0000" stroke="transparent" stroke-width="2" points="348,-19 348,-25 546,-25 546,-19 348,-19"/>
<polyline fill="none" stroke="black" stroke-width="2" points="349,-20 545,-20 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="545,-24 349,-24 "/>
<text text-anchor="start" x="380.5" y="-5.8" font-family="arial" font-size="14.00"> </text>
<polygon fill="none" stroke="black" points="541.5,-130 352.5,-130 352.5,0 541.5,0 541.5,-130"/>
<polygon fill="none" stroke="black" points="353,-107 353,-130 542,-130 542,-107 353,-107"/>
<text text-anchor="start" x="436.5" y="-114.8" font-family="arial" font-size="14.00">W3</text>
<polygon fill="none" stroke="black" points="353,-84 353,-107 376,-107 376,-84 353,-84"/>
<text text-anchor="start" x="357" y="-91.8" font-family="arial" font-size="14.00">2x</text>
<polygon fill="none" stroke="black" points="376,-84 376,-107 499,-107 499,-84 376,-84"/>
<text text-anchor="start" x="380" y="-91.8" font-family="arial" font-size="14.00">20 awg (0.75 mm²)</text>
<polygon fill="none" stroke="black" points="499,-84 499,-107 542,-107 542,-84 499,-84"/>
<text text-anchor="start" x="503" y="-91.8" font-family="arial" font-size="14.00">0.2 m</text>
<text text-anchor="start" x="445.5" y="-72.8" font-family="arial" font-size="14.00"> </text>
<text text-anchor="start" x="372" y="-55.8" font-family="arial" font-size="14.00">X1:1</text>
<text text-anchor="start" x="438.5" y="-55.8" font-family="arial" font-size="14.00">BK</text>
<text text-anchor="start" x="495.5" y="-55.8" font-family="arial" font-size="14.00">X4:1</text>
<polygon fill="#000000" stroke="transparent" points="353,-44 353,-50 542,-50 542,-44 353,-44"/>
<polyline fill="none" stroke="black" stroke-width="2" points="354,-45 541,-45 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="541,-49 354,-49 "/>
<text text-anchor="start" x="372" y="-30.8" font-family="arial" font-size="14.00">X1:2</text>
<text text-anchor="start" x="438" y="-30.8" font-family="arial" font-size="14.00">RD</text>
<text text-anchor="start" x="495.5" y="-30.8" font-family="arial" font-size="14.00">X4:2</text>
<polygon fill="#ff0000" stroke="transparent" stroke-width="2" points="353,-19 353,-25 542,-25 542,-19 353,-19"/>
<polyline fill="none" stroke="black" stroke-width="2" points="354,-20 541,-20 "/>
<polyline fill="none" stroke="black" stroke-width="2" points="541,-24 354,-24 "/>
<text text-anchor="start" x="384" y="-5.8" font-family="arial" font-size="14.00"> </text>
</g>
<!-- X1&#45;&#45;W3 -->
<g id="edge9" class="edge">
<title>X1:e&#45;&#45;W3:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-198C295.45,-200.54 252.69,-47.54 348,-45"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-200C297.38,-200 254.62,-47 348,-47"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-202C299.31,-199.46 256.55,-46.46 348,-49"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-198C296.68,-200.52 255.46,-47.52 352,-45"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-200C298.61,-200 257.39,-47 352,-47"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-202C300.54,-199.48 259.32,-46.48 352,-49"/>
</g>
<!-- X1&#45;&#45;W3 -->
<g id="edge11" class="edge">
<title>X1:e&#45;&#45;W3:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-175C296.11,-177.55 252.05,-22.55 348,-20"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M204,-177C298.03,-177 253.97,-22 348,-22"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-179C299.95,-176.45 255.89,-21.45 348,-24"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-175C297.32,-177.53 254.82,-22.53 352,-20"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M204,-177C299.25,-177 256.75,-22 352,-22"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M204,-179C301.18,-176.47 258.68,-21.47 352,-24"/>
</g>
<!-- X2 -->
<g id="node2" class="node">
@ -242,16 +242,16 @@
<!-- W3&#45;&#45;X4 -->
<g id="edge10" class="edge">
<title>W3:e&#45;&#45;X4:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-45C609.88,-45 625.87,-44 690,-44"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-47C610,-47 626,-46 690,-46"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-49C610.13,-49 626.12,-48 690,-48"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-45C608.21,-45 624.54,-44 690,-44"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-47C608.33,-47 624.67,-46 690,-46"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-49C608.46,-49 624.79,-48 690,-48"/>
</g>
<!-- W3&#45;&#45;X4 -->
<g id="edge12" class="edge">
<title>W3:e&#45;&#45;X4:w</title>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-20C610.13,-20 626.12,-21 690,-21"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M546,-22C610,-22 626,-23 690,-23"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M546,-24C609.88,-24 625.87,-25 690,-25"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-20C608.46,-20 624.79,-21 690,-21"/>
<path fill="none" stroke="#ff0000" stroke-width="2" d="M543,-22C608.33,-22 624.67,-23 690,-23"/>
<path fill="none" stroke="#000000" stroke-width="2" d="M543,-24C608.21,-24 624.54,-25 690,-25"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -22,6 +22,7 @@ cables:
<<: *wire_power # create from template
W3:
<<: *wire_power # create from template
gauge: 20 awg
connections:
-

View File

@ -83,7 +83,12 @@ class Cable:
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'

View File

@ -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 @@ class Harness:
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))

View File

@ -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 = []