diff --git a/examples/ex15.html b/examples/ex15.html index d149cc2..b8886d2 100644 --- a/examples/ex15.html +++ b/examples/ex15.html @@ -33,267 +33,308 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 + +Short + +Manufacturer + +M.P.N. + +Length + +Description + +SH1 + +WireViz + +42XCD42A5 + + +shortPart + +SH2 + +WireViz + +42XCD42A5 + +42mm + +shortPart X1:c--X1:c - + X1:c--X1:c - + X1:c--X1:c - + W1 - - -W1 - -Serial - -4x - -0.25 mm² (24 AWG) - -+ S - -0.2 m -  -X1:1:GND -     1:BN     -X2:1:GND - - - -X1:2:VCC -     2:RD     -X2:2:VCC - - - -X1:3:RX -     3:OG     -X2:4:TX - - - -X1:4:TX -     4:YE     -X2:3:RX - - - -  -X1:1:GND -Shield - -  + + +W1 + +Serial + +4x + +0.25 mm² (24 AWG) + ++ S + +0.2 m +  +X1:1:GND +     1:BN     +X2:1:GND + + + +X1:2:VCC +     2:RD     +X2:2:VCC + + + +X1:3:RX +     3:OG     +X2:4:TX + + + +X1:4:TX +     4:YE     +X2:3:RX + + + +  +X1:1:GND +Shield + +  X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - + X2 - - -X2 - -Molex KK 254 - -female - -7-pin - -1 - -GND - - - - -2 - -VCC - - - - -3 - -RX - - - -4 - -TX - - - -5 - -GND - - - - -6 - -VCC - - - - -7 - -GND - - - + + +X2 + +Molex KK 254 + +female + +7-pin + + + +SH1 + +SH2 + +1 + +GND + + + + +2 + +VCC + + + + +3 + +RX + + + +4 + +TX + + + +5 + +GND + + + + +6 + +VCC + + + + +7 + +GND + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:c--X2:c - + X2:c--X2:c - + X2:c--X2:c - + diff --git a/examples/ex15.png b/examples/ex15.png index 1fe560e..0462c09 100644 Binary files a/examples/ex15.png and b/examples/ex15.png differ diff --git a/examples/ex15.svg b/examples/ex15.svg index d006211..4335e40 100644 --- a/examples/ex15.svg +++ b/examples/ex15.svg @@ -4,267 +4,308 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 + +Short + +Manufacturer + +M.P.N. + +Length + +Description + +SH1 + +WireViz + +42XCD42A5 + + +shortPart + +SH2 + +WireViz + +42XCD42A5 + +42mm + +shortPart X1:c--X1:c - + X1:c--X1:c - + X1:c--X1:c - + W1 - - -W1 - -Serial - -4x - -0.25 mm² (24 AWG) - -+ S - -0.2 m -  -X1:1:GND -     1:BN     -X2:1:GND - - - -X1:2:VCC -     2:RD     -X2:2:VCC - - - -X1:3:RX -     3:OG     -X2:4:TX - - - -X1:4:TX -     4:YE     -X2:3:RX - - - -  -X1:1:GND -Shield - -  + + +W1 + +Serial + +4x + +0.25 mm² (24 AWG) + ++ S + +0.2 m +  +X1:1:GND +     1:BN     +X2:1:GND + + + +X1:2:VCC +     2:RD     +X2:2:VCC + + + +X1:3:RX +     3:OG     +X2:4:TX + + + +X1:4:TX +     4:YE     +X2:3:RX + + + +  +X1:1:GND +Shield + +  X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - + X2 - - -X2 - -Molex KK 254 - -female - -7-pin - -1 - -GND - - - - -2 - -VCC - - - - -3 - -RX - - - -4 - -TX - - - -5 - -GND - - - - -6 - -VCC - - - - -7 - -GND - - - + + +X2 + +Molex KK 254 + +female + +7-pin + + + +SH1 + +SH2 + +1 + +GND + + + + +2 + +VCC + + + + +3 + +RX + + + +4 + +TX + + + +5 + +GND + + + + +6 + +VCC + + + + +7 + +GND + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:c--X2:c - + X2:c--X2:c - + X2:c--X2:c - + diff --git a/examples/ex15.yml b/examples/ex15.yml index a5e346c..f2c9b1a 100644 --- a/examples/ex15.yml +++ b/examples/ex15.yml @@ -3,13 +3,30 @@ connectors: type: Molex KK 254 # more information subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] # pincount is implicit in pinout - internal_shorts: [[1, 5, 7], [2, 6]] - internal_shorts_color: [PK, RD] + shorts: + SH1: + pins: [1, 5, 7] + color: PK + manufacturer: WireViz + mpn: 42XCD42A5 + description: shortPart + SH2: + pins: [2, 6] + color: RD + manufacturer: WireViz + mpn: 42XCD42A5 + description: shortPart + length: 42 + shorts_graph_bom: true X2: type: Molex KK 254 subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] - internal_shorts: [[1, 5, 7], [2, 6]] + shorts: + SH1: + pins: [1, 5, 7] + SH2: + pins: [2, 6] cables: W1: diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 8a14445..9a5496f 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -136,6 +136,17 @@ class AdditionalComponent: t = t + st return t +@dataclass +class Short: + name: Designator + pins: List[Pin] = field(default_factory=list) + color: Optional[Color] = None + manufacturer: Optional[MultilineHypertext] = None + mpn: Optional[MultilineHypertext] = None + description: Optional[str] = None + length: Optional[float] = None + length_unit: Optional[str] = None + @dataclass class Connector: @@ -162,10 +173,10 @@ class Connector: show_pincount: Optional[bool] = None hide_disconnected_pins: bool = False loops: List[List[Pin]] = field(default_factory=list) - ignore_in_bom: bool = False + ignore_in_bom: bool = False#ß additional_components: List[AdditionalComponent] = field(default_factory=list) - internal_shorts: Optional[List[List[Pin]]] = field(default_factory=list) - internal_shorts_color: Optional[List[Color]] = field(default_factory=list) + shorts: List[Short] = field(default_factory=list) + shorts_graph_bom: Optional[bool] = False def __post_init__(self) -> None: @@ -224,6 +235,10 @@ class Connector: if isinstance(item, dict): self.additional_components[i] = AdditionalComponent(**item) + for i, item in enumerate(self.shorts): + if isinstance(item, dict): + self.shorts[i] = Short(**item) + def activate_pin(self, pin: Pin, side: Side) -> None: self.visible_pins[pin] = True if side == Side.LEFT: diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 5fb84f0..30426b9 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -205,6 +205,7 @@ class Harness: translate_color(connector.color, self.options.color_mode) if connector.color else None, html_colorbar(connector.color)], '' if connector.style != 'simple' else None, + '' if connector.shorts_graph_bom else None, [html_image(connector.image)], [html_caption(connector.image)]] # fmt: on @@ -219,6 +220,21 @@ class Harness: '' ) + if len(connector.shorts) > 0: + pinhtml.append(" ") + if connector.ports_left: + pinhtml.append(f' ') + if connector.pinlabels: + pinhtml.append(f" ") + + for shortName in connector.shorts: + pinhtml.append(f' ') + + if connector.ports_right: + pinhtml.append(f' ') + pinhtml.append(" ") + + for pinindex, (pinname, pinlabel, pincolor) in enumerate( zip_longest( connector.pins, connector.pinlabels, connector.pincolors @@ -248,12 +264,19 @@ class Harness: else: pinhtml.append(' ') - for short, short_color in zip_longest(connector.internal_shorts, connector.internal_shorts_color): - if short_color == None: - short_color = "BK" + for shortName in connector.shorts: + short = connector.shorts[shortName] + shPins = short.get('pins'); + shColor = short.get('color'); + # shManufacturer = short.get('manufacturer'); + # shMpn = short.get('mpn'); + # shDescription = short.get('description'); + + if shColor == None: + shColor = "BK" - if pinindex+1 in short: - pinhtml.append(f' ') + if pinindex+1 in shPins: + pinhtml.append(f' ') else: pinhtml.append(f' ') @@ -269,14 +292,71 @@ class Harness: for row in html ] - for short, short_color in zip_longest(connector.internal_shorts, connector.internal_shorts_color): - if short_color == None: - short_color = "BK" - dot.attr("edge", color=str(wv_colors.translate_color(short_color, "HEX")), headclip="false", tailclip="false", style="solid,bold") - for i in range(1, len(short)): + if connector.shorts_graph_bom: + shorthtml = [] + shorthtml.append( + '
{shortName}
' + ) + + + shorthtml.append(" ") + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(" ") + + for shortName in connector.shorts: + short = connector.shorts[shortName] + shPins = short.get('pins'); + shColor = short.get('color'); + shManufacturer = short.get('manufacturer') if short.get('manufacturer') != None else ""; + shMpn = short.get('mpn') if short.get('mpn') != None else ""; + shDescription = short.get('description') if short.get('description') != None else ""; + length = short.get('length') if short.get('length') != None else ""; + if short.get('length_unit') != None and short.get('length') != None: + length_unit = short.get('length_unit') + elif short.get('length') == None: + length_unit = "" + else: + length_unit = "mm" + + if shColor == None: + shColor = "BK" + + shorthtml.append(" ") + + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + shorthtml.append(f' ') + + shorthtml.append(" ") + + shorthtml.append("
ShortManufacturerM.P.N.LengthDescription
{shortName}{shManufacturer}{shMpn}{length}{length_unit}{shDescription}
") + + html = [ + row.replace("", "\n".join(shorthtml)) + for row in html + ] + + for shortName in connector.shorts: + short = connector.shorts[shortName] + shPins = short.get('pins'); + shColor = short.get('color'); + # shManufacturer = short.get('manufacturer'); + # shMpn = short.get('mpn'); + # shDescription = short.get('description'); + + if shColor == None: + shColor = "BK" + dot.attr("edge", color=str(wv_colors.translate_color(shColor, "HEX")), headclip="false", tailclip="false", style="solid,bold") + for i in range(1, len(shPins)): dot.edge( - f"{connector.name}:p{short[i - 1]}j:c", - f"{connector.name}:p{short[i]}j:c", + f"{connector.name}:p{shPins[i - 1]}j:c", + f"{connector.name}:p{shPins[i]}j:c", straight="straight" )