Skip to content

Commit f100cdf

Browse files
committed
fix(loop): support color and proper pin when un-ordered
1 parent afc1405 commit f100cdf

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

examples/ex11.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ connectors:
88
- first: 1
99
second: 2
1010
side: LEFT
11+
color: PK
1112
- first: LB3
1213
second: LB4
1314
side: LEFT
1415
X2:
1516
type: Stewart Connector SS-37000-002
1617
subtype: male
17-
pinlabels: [LB5,LB6,DA+,DD+,DD-,DA-,LB7,LB8]
18+
pins: [3, 4, 5, 6, 1, 2, 7, 8]
19+
pinlabels: [DA+, D+, D-, A-, LB5, LB6, LB7, LB8]
1820
loops:
1921
- first: 1
2022
second: 2
2123
side: RIGHT
2224
show_label: false
25+
color: RD
2326
- first: LB7
2427
second: LB8
2528
side: LEFT
29+
color: GN
2630

2731
cables:
2832
W1:

src/wireviz/wv_dataclasses.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def __str__(self):
7979
]
8080
return ":".join([snip for snip in snippets if snip != ""])
8181

82+
@property
83+
def pin(self):
84+
return self.index+1
85+
8286
@property
8387
def category(self):
8488
return BomCategory.PIN
@@ -216,20 +220,26 @@ class Loop():
216220
second: PinClass = None
217221
side: Side = None
218222
show_label: bool = True
223+
color: Optional[MultiColor] = None
219224

220225
def __post_init__(self):
221226
if self.side.upper() == 'LEFT':
222227
self.side = Side.LEFT
223228
elif self.side.upper() == 'RIGHT':
224229
self.side = Side.RIGHT
225230

231+
self.color = MultiColor(self.color)
232+
226233
@property
227234
def label(self):
228235
if self.show_label:
229-
return f'{self.first}<->{self.second}'
236+
return f'{self.first}{self.second}'
230237
else:
231238
return ''
232239

240+
def html_color(self):
241+
return self.color[0].html
242+
233243

234244
@dataclass
235245
class Connector(GraphicalComponent):
@@ -354,38 +364,32 @@ def to_int_pin(pin):
354364
self.show_pincount = self.style != "simple"
355365

356366
def get_pin_object(value):
357-
pin_id = None
358-
if value in self.pinlabels:
359-
pin_id = self.pins[self.pinlabels.index(value)]
360-
else:
361-
err = f'{value} not found in {self.pinlabels}'
362-
try:
363-
value = int(value)
364-
except ValueError as exc:
365-
raise ValueError(f'{err} and is not an int')
367+
# is label?
368+
pin_match_label = [p for p in self.pin_objects.values() if p.label == value]
369+
if pin_match_label:
370+
return pin_match_label[0]
371+
err = f'{value} not found in {self.pinlabels}'
366372

367-
if value in self.pins:
368-
pin_id = value
369-
370-
if pin_id is not None:
371-
return self.pin_objects[pin_id]
373+
try:
374+
value = int(value)
375+
except ValueError as exc:
376+
raise ValueError(f'{err} and is not an int')
372377

373-
raise ValueError(f'{err} and is not one of the pins {self.pins}')
378+
pin_match_id = [p for p in self.pin_objects.values() if p.id == value]
379+
if not pin_match_id:
380+
raise ValueError(f'{err} and is not one of the pins {self.pins}')
381+
return pin_match_id[0]
374382

375383
self.loops = [Loop(
376384
first=get_pin_object(loop['first']),
377385
second=get_pin_object(loop['second']),
378386
side=loop.get('side'),
379387
show_label=loop.get('show_label', True),
388+
color=loop.get('color'),
380389
) for loop in self.loops]
381390

382391

383-
#self.loops = [[to_int_pin(p) for p in loop] for loop in self.loops]
384392
for loop in self.loops:
385-
# TODO: check that pins to connect actually exist
386-
# TODO: allow using pin labels in addition to pin numbers,
387-
# just like when defining regular connections
388-
# TODO: include properties of wire used to create the loop
389393
self.activate_pin(loop.first.id, side=loop.side, is_connection=True)
390394
self.activate_pin(loop.second.id, side=loop.side, is_connection=True)
391395

src/wireviz/wv_graphviz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def gv_connector_loops(connector: Connector) -> List:
5454
this_loop_side = 'l'
5555
this_loop_dir = 'w'
5656

57-
head = f"{connector.designator}:p{loop.first.id}{this_loop_side}:{this_loop_dir}"
58-
tail = f"{connector.designator}:p{loop.second.id}{this_loop_side}:{this_loop_dir}"
57+
head = f"{connector.designator}:p{loop.first.pin}{this_loop_side}:{this_loop_dir}"
58+
tail = f"{connector.designator}:p{loop.second.pin}{this_loop_side}:{this_loop_dir}"
5959
loop_edges.append((loop, head, tail))
6060
return loop_edges
6161

src/wireviz/wv_harness.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,9 @@ def create_graph(self) -> Graph:
315315
)
316316
# generate edges for connector loops
317317
if len(connector.loops) > 0:
318-
dot.attr("edge", color="#000000")
319318
loops = gv_connector_loops(connector)
320319
for loop, head, tail in loops:
321-
dot.edge(head, tail, xlabel=loop.label)
320+
dot.edge(head, tail, xlabel=loop.label, color=loop.html_color())
322321

323322
# determine if there are double- or triple-colored wires in the harness;
324323
# if so, pad single-color wires to make all wires of equal thickness

0 commit comments

Comments
 (0)