Add option to add colors to connector pins (#141)
This commit is contained in:
parent
64bd34a7c6
commit
feff47f47b
@ -96,6 +96,7 @@ class Connector:
|
||||
notes: Optional[MultilineHypertext] = None
|
||||
pinlabels: List[Pin] = field(default_factory=list)
|
||||
pins: List[Pin] = field(default_factory=list)
|
||||
pincolors: List[Color] = field(default_factory=list)
|
||||
color: Optional[Color] = None
|
||||
show_name: Optional[bool] = None
|
||||
show_pincount: Optional[bool] = None
|
||||
@ -119,23 +120,14 @@ class Connector:
|
||||
raise Exception('Connectors with style set to simple may only have one pin')
|
||||
self.pincount = 1
|
||||
|
||||
if self.pincount is None:
|
||||
if self.pinlabels:
|
||||
self.pincount = len(self.pinlabels)
|
||||
elif self.pins:
|
||||
self.pincount = len(self.pins)
|
||||
else:
|
||||
raise Exception('You need to specify at least one, pincount, pins or pinlabels')
|
||||
if not self.pincount:
|
||||
self.pincount = max(len(self.pins), len(self.pinlabels), len(self.pincolors))
|
||||
if not self.pincount:
|
||||
raise Exception('You need to specify at least one, pincount, pins, pinlabels, or pincolors')
|
||||
|
||||
if self.pinlabels and self.pins:
|
||||
if len(self.pinlabels) != len(self.pins):
|
||||
raise Exception('Given pins and pinlabels size mismatch')
|
||||
|
||||
# create default lists for pins (sequential) and pinlabels (blank) if not specified
|
||||
# create default list for pins (sequential) if not specified
|
||||
if not self.pins:
|
||||
self.pins = list(range(1, self.pincount + 1))
|
||||
if not self.pinlabels:
|
||||
self.pinlabels = [''] * self.pincount
|
||||
|
||||
if len(self.pins) != len(set(self.pins)):
|
||||
raise Exception('Pins are not unique')
|
||||
|
||||
@ -12,6 +12,7 @@ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
|
||||
from collections import Counter
|
||||
from typing import List, Union
|
||||
from pathlib import Path
|
||||
from itertools import zip_longest
|
||||
import re
|
||||
|
||||
|
||||
@ -110,7 +111,7 @@ class Harness:
|
||||
pinhtml = []
|
||||
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
|
||||
|
||||
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
|
||||
for pin, pinlabel, pincolor in zip_longest(connector.pins, connector.pinlabels, connector.pincolors):
|
||||
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
|
||||
continue
|
||||
pinhtml.append(' <tr>')
|
||||
@ -118,6 +119,17 @@ class Harness:
|
||||
pinhtml.append(f' <td port="p{pin}l">{pin}</td>')
|
||||
if pinlabel:
|
||||
pinhtml.append(f' <td>{pinlabel}</td>')
|
||||
if connector.pincolors:
|
||||
if pincolor in wv_colors._color_hex.keys():
|
||||
pinhtml.append(f' <td sides="tbl">{pincolor}</td>')
|
||||
pinhtml.append( ' <td sides="tbr">')
|
||||
pinhtml.append( ' <table border="0" cellborder="1"><tr>')
|
||||
pinhtml.append(f' <td bgcolor="{wv_colors.translate_color(pincolor, "HEX")}" width="8" height="8" fixedsize="true"></td>')
|
||||
pinhtml.append( ' </tr></table>')
|
||||
pinhtml.append( ' </td>')
|
||||
else:
|
||||
pinhtml.append( ' <td colspan="2"></td>')
|
||||
|
||||
if connector.ports_right:
|
||||
pinhtml.append(f' <td port="p{pin}r">{pin}</td>')
|
||||
pinhtml.append(' </tr>')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user