Merge branch 'dev'
This commit is contained in:
commit
3ae3fff15b
@ -3,7 +3,6 @@ nodes:
|
|||||||
type: D-Sub
|
type: D-Sub
|
||||||
gender: female
|
gender: female
|
||||||
pinout: [DCD, RX, TX, DTR, GND, DSR, RTS, CTS, RI]
|
pinout: [DCD, RX, TX, DTR, GND, DSR, RTS, CTS, RI]
|
||||||
random: yes
|
|
||||||
X2:
|
X2:
|
||||||
type: Molex KK 254
|
type: Molex KK 254
|
||||||
gender: female
|
gender: female
|
||||||
|
|||||||
36
examples/ferrules.yml
Normal file
36
examples/ferrules.yml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
nodes:
|
||||||
|
X1:
|
||||||
|
type: D-Sub
|
||||||
|
gender: female
|
||||||
|
num_pins: 4
|
||||||
|
X2:
|
||||||
|
type: Molex KK 254
|
||||||
|
gender: female
|
||||||
|
num_pins: 3
|
||||||
|
|
||||||
|
wires:
|
||||||
|
W1:
|
||||||
|
mm2: 0.25
|
||||||
|
length: 0.2
|
||||||
|
color_code: IEC
|
||||||
|
num_wires: 10
|
||||||
|
shield: true
|
||||||
|
|
||||||
|
ferrules:
|
||||||
|
F_test:
|
||||||
|
type: crimp
|
||||||
|
|
||||||
|
connections:
|
||||||
|
-
|
||||||
|
- X1: [1-3]
|
||||||
|
- W1: [1-3]
|
||||||
|
- X2: [1-3]
|
||||||
|
-
|
||||||
|
- X1: 4
|
||||||
|
- W1: s
|
||||||
|
-
|
||||||
|
- F_test
|
||||||
|
- W1: [4-10]
|
||||||
|
-
|
||||||
|
- W1: [10-4]
|
||||||
|
- F_test
|
||||||
164
src/wireviz.py
164
src/wireviz.py
@ -1,3 +1,5 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Any, List
|
||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
|
|
||||||
COLOR_CODES = {'DIN': ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT'], # ,'GYPK','RDBU','WHGN','BNGN','WHYE','YEBN','WHGY','GYBN','WHPK','PKBN'],
|
COLOR_CODES = {'DIN': ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT'], # ,'GYPK','RDBU','WHGN','BNGN','WHYE','YEBN','WHGY','GYBN','WHPK','PKBN'],
|
||||||
@ -8,14 +10,14 @@ COLOR_CODES = {'DIN': ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT'], # ,'G
|
|||||||
color_hex = {
|
color_hex = {
|
||||||
'BK': '#000000',
|
'BK': '#000000',
|
||||||
'WH': '#ffffff',
|
'WH': '#ffffff',
|
||||||
'GY': '#808080',
|
'GY': '#999999',
|
||||||
'PK': '#ff80c0',
|
'PK': '#ff66cc',
|
||||||
'RD': '#ff0000',
|
'RD': '#ff0000',
|
||||||
'OG': '#ff8000',
|
'OG': '#ff8000',
|
||||||
'YE': '#ffff00',
|
'YE': '#ffff00',
|
||||||
'GN': '#00ff00',
|
'GN': '#009900',
|
||||||
'TQ': '#00ffff',
|
'TQ': '#00ffff',
|
||||||
'BU': '#0000ff',
|
'BU': '#0066ff',
|
||||||
'VT': '#8000ff',
|
'VT': '#8000ff',
|
||||||
'BN': '#666600',
|
'BN': '#666600',
|
||||||
}
|
}
|
||||||
@ -57,11 +59,11 @@ class Harness:
|
|||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
self.cables = {}
|
self.cables = {}
|
||||||
|
|
||||||
def add_node(self, name, type=None, gender=None, show_name=True, num_pins=None, show_num_pins=True, pinout=None, ports_left=False, ports_right=False):
|
def add_node(self, name, *args, **kwargs):
|
||||||
self.nodes[name] = Node(name, type, gender, show_name, num_pins, show_num_pins, pinout, ports_left, ports_right)
|
self.nodes[name] = Node(name, *args, **kwargs)
|
||||||
|
|
||||||
def add_cable(self, name, mm2=None, awg=None, show_equiv=False, length=0, show_name=False, show_pinout=False, num_wires=None, show_num_wires=True, colors=None, color_code=None, shield=False):
|
def add_cable(self, name, *args, **kwargs):
|
||||||
self.cables[name] = Cable(name, mm2, awg, show_equiv, length, show_name, show_pinout, num_wires, show_num_wires, colors, color_code, shield)
|
self.cables[name] = Cable(name, *args, **kwargs)
|
||||||
|
|
||||||
def loop(self, node_name, from_pin, to_pin):
|
def loop(self, node_name, from_pin, to_pin):
|
||||||
self.nodes[node_name].loop(from_pin, to_pin)
|
self.nodes[node_name].loop(from_pin, to_pin)
|
||||||
@ -82,38 +84,36 @@ class Harness:
|
|||||||
dot.attr('edge', style='bold', fontname=font)
|
dot.attr('edge', style='bold', fontname=font)
|
||||||
|
|
||||||
# prepare ports on connectors depending on which side they will connect
|
# prepare ports on connectors depending on which side they will connect
|
||||||
for k in self.cables:
|
for k, c in self.cables.items():
|
||||||
c = self.cables[k]
|
|
||||||
for x in c.connections:
|
for x in c.connections:
|
||||||
if x[1] is not None: # connect to left
|
if x[1] is not None: # connect to left
|
||||||
self.nodes[x[0]].ports_right = True
|
self.nodes[x[0]].ports_right = True
|
||||||
if x[4] is not None: # connect to right
|
if x[4] is not None: # connect to right
|
||||||
self.nodes[x[3]].ports_left = True
|
self.nodes[x[3]].ports_left = True
|
||||||
|
|
||||||
for k in self.nodes:
|
for k, n in self.nodes.items():
|
||||||
n = self.nodes[k]
|
|
||||||
# a = attributes
|
# a = attributes
|
||||||
a = [n.type,
|
a = [n.type,
|
||||||
n.gender,
|
n.gender,
|
||||||
'{}-pin'.format(len(n.pinout)) if n.show_num_pins == True else '']
|
'{}-pin'.format(len(n.pinout)) if n.show_num_pins else '']
|
||||||
# p = pinout
|
# p = pinout
|
||||||
p = [[],[],[]]
|
p = [[],[],[]]
|
||||||
p[1] = list(n.pinout)
|
p[1] = list(n.pinout)
|
||||||
for i,x in enumerate(n.pinout, 1):
|
for i, x in enumerate(n.pinout, 1):
|
||||||
if n.ports_left == True:
|
if n.ports_left:
|
||||||
p[0].append('<p{portno}l>{portno}'.format(portno=i))
|
p[0].append('<p{portno}l>{portno}'.format(portno=i))
|
||||||
if n.ports_right == True:
|
if n.ports_right:
|
||||||
p[2].append('<p{portno}r>{portno}'.format(portno=i))
|
p[2].append('<p{portno}r>{portno}'.format(portno=i))
|
||||||
# l = label
|
# l = label
|
||||||
l = [n.name if n.show_name == True else '', a, p]
|
l = [n.name if n.show_name else '', a, p]
|
||||||
dot.node(k, label=nested(l))
|
dot.node(k, label=nested(l))
|
||||||
|
|
||||||
if len(n.loops) > 0:
|
if len(n.loops) > 0:
|
||||||
dot.attr('edge',color='#000000')
|
dot.attr('edge',color='#000000')
|
||||||
if n.ports_left == True:
|
if n.ports_left:
|
||||||
loop_side = 'l'
|
loop_side = 'l'
|
||||||
loop_dir = 'w'
|
loop_dir = 'w'
|
||||||
elif n.ports_right == True:
|
elif n.ports_right:
|
||||||
loop_side = 'r'
|
loop_side = 'r'
|
||||||
loop_dir = 'e'
|
loop_dir = 'e'
|
||||||
else:
|
else:
|
||||||
@ -122,24 +122,23 @@ class Harness:
|
|||||||
dot.edge('{name}:p{port_from}{loop_side}:{loop_dir}'.format(name=n.name, port_from=x[0], port_to=x[1], loop_side=loop_side, loop_dir=loop_dir),
|
dot.edge('{name}:p{port_from}{loop_side}:{loop_dir}'.format(name=n.name, port_from=x[0], port_to=x[1], loop_side=loop_side, loop_dir=loop_dir),
|
||||||
'{name}:p{port_to}{loop_side}:{loop_dir}'.format(name=n.name, port_from=x[0], port_to=x[1], loop_side=loop_side, loop_dir=loop_dir))
|
'{name}:p{port_to}{loop_side}:{loop_dir}'.format(name=n.name, port_from=x[0], port_to=x[1], loop_side=loop_side, loop_dir=loop_dir))
|
||||||
|
|
||||||
for k in self.cables:
|
for k, c in self.cables.items():
|
||||||
c = self.cables[k]
|
|
||||||
# a = attributes
|
# a = attributes
|
||||||
a = ['{}x'.format(len(c.colors)) if c.show_num_wires == True else '',
|
a = ['{}x'.format(len(c.colors)) if c.show_num_wires else '',
|
||||||
'{} mm\u00B2{}'.format(c.mm2, ' ({} AWG)'.format(awg_equiv(c.mm2)) if c.show_equiv == True else '') if c.mm2 is not None else '',
|
'{} mm\u00B2{}'.format(c.mm2, ' ({} AWG)'.format(awg_equiv(c.mm2)) if c.show_equiv else '') if c.mm2 is not None else '',
|
||||||
c.awg,
|
c.awg,
|
||||||
'+ S' if c.shield == True else '',
|
'+ S' if c.shield else '',
|
||||||
'{} m'.format(c.length) if c.length > 0 else '']
|
'{} m'.format(c.length) if c.length > 0 else '']
|
||||||
# p = pinout
|
# p = pinout
|
||||||
p = [[],[],[]]
|
p = [[],[],[]]
|
||||||
for i,x in enumerate(c.colors,1):
|
for i, x in enumerate(c.colors,1):
|
||||||
if c.show_pinout:
|
if c.show_pinout:
|
||||||
p[0].append('<w{wireno}i>{wireno}'.format(wireno=i))
|
p[0].append('<w{wireno}i>{wireno}'.format(wireno=i))
|
||||||
p[1].append('{wirecolor}'.format(wirecolor=translate_color(x, self.color_mode)))
|
p[1].append('{wirecolor}'.format(wirecolor=translate_color(x, self.color_mode)))
|
||||||
p[2].append('<w{wireno}o>{wireno}'.format(wireno=i))
|
p[2].append('<w{wireno}o>{wireno}'.format(wireno=i))
|
||||||
else:
|
else:
|
||||||
p[1].append('<w{wireno}>{wirecolor}'.format(wireno=i,wirecolor=translate_color(x, self.color_mode)))
|
p[1].append('<w{wireno}>{wirecolor}'.format(wireno=i,wirecolor=translate_color(x, self.color_mode)))
|
||||||
if c.shield == True:
|
if c.shield:
|
||||||
if c.show_pinout:
|
if c.show_pinout:
|
||||||
p[0].append('<wsi>')
|
p[0].append('<wsi>')
|
||||||
p[1].append('Shield')
|
p[1].append('Shield')
|
||||||
@ -147,7 +146,7 @@ class Harness:
|
|||||||
else:
|
else:
|
||||||
p[1].append('<ws>Shield')
|
p[1].append('<ws>Shield')
|
||||||
# l = label
|
# l = label
|
||||||
l = [c.name if c.show_name == True else '', a, p]
|
l = [c.name if c.show_name else '', a, p]
|
||||||
dot.node(k, label=nested(l))
|
dot.node(k, label=nested(l))
|
||||||
|
|
||||||
# connections
|
# connections
|
||||||
@ -162,10 +161,10 @@ class Harness:
|
|||||||
dot.attr('edge',color='#000000')
|
dot.attr('edge',color='#000000')
|
||||||
if x[1] is not None: # connect to left
|
if x[1] is not None: # connect to left
|
||||||
dot.edge('{from_name}:p{from_port}r'.format(from_name=x[0],from_port=x[1]),
|
dot.edge('{from_name}:p{from_port}r'.format(from_name=x[0],from_port=x[1]),
|
||||||
'{via_name}:w{via_wire}{via_subport}'.format(via_name=c.name, via_wire=x[2], via_subport='i' if c.show_pinout == True else ''))
|
'{via_name}:w{via_wire}{via_subport}'.format(via_name=c.name, via_wire=x[2], via_subport='i' if c.show_pinout else ''))
|
||||||
# self.nodes[x[0]].ports_right = True
|
# self.nodes[x[0]].ports_right = True
|
||||||
if x[4] is not None: # connect to right
|
if x[4] is not None: # connect to right
|
||||||
dot.edge('{via_name}:w{via_wire}{via_subport}'.format(via_name=c.name, via_wire=x[2], via_subport='o' if c.show_pinout == True else ''),
|
dot.edge('{via_name}:w{via_wire}{via_subport}'.format(via_name=c.name, via_wire=x[2], via_subport='o' if c.show_pinout else ''),
|
||||||
'{to_name}:p{to_port}l'.format(to_name=x[3], to_port=x[4]))
|
'{to_name}:p{to_port}l'.format(to_name=x[3], to_port=x[4]))
|
||||||
# self.nodes[x[3]].ports_left = True
|
# self.nodes[x[3]].ports_left = True
|
||||||
|
|
||||||
@ -178,74 +177,73 @@ class Harness:
|
|||||||
d.render(filename=filename, directory=directory, view=view, cleanup=cleanup)
|
d.render(filename=filename, directory=directory, view=view, cleanup=cleanup)
|
||||||
d.save(filename='{}.gv'.format(filename), directory=directory)
|
d.save(filename='{}.gv'.format(filename), directory=directory)
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Node:
|
class Node:
|
||||||
|
name: str
|
||||||
|
type: str = None
|
||||||
|
gender: str = None
|
||||||
|
num_pins: int = None
|
||||||
|
pinout: List[Any] = field(default_factory=list)
|
||||||
|
show_name: bool = False
|
||||||
|
show_num_pins: bool = False
|
||||||
|
|
||||||
def __init__(self, name, type=None, gender=None, show_name=True, num_pins=None, show_num_pins=True, pinout=None, ports_left=False, ports_right=False):
|
def __post_init__(self):
|
||||||
self.name = name
|
self.ports_left = False
|
||||||
self.type = type
|
self.ports_right = False
|
||||||
self.gender = gender
|
|
||||||
self.show_name = show_name
|
|
||||||
self.show_num_pins = show_num_pins
|
|
||||||
self.ports_left = ports_left
|
|
||||||
self.ports_right = ports_right
|
|
||||||
self.loops = []
|
self.loops = []
|
||||||
|
|
||||||
if pinout is None:
|
if self.pinout:
|
||||||
if num_pins is None:
|
if self.num_pins is not None:
|
||||||
num_pins = 1
|
raise Exception('You cannot specify both pinout and num_pins')
|
||||||
self.pinout = ('',) * num_pins
|
|
||||||
else:
|
else:
|
||||||
if num_pins is None:
|
if not self.num_pins:
|
||||||
if pinout is None:
|
self.num_pins = 1
|
||||||
raise Exception('Must provide num_pins or pinout')
|
self.pinout = ['',] * self.num_pins
|
||||||
else:
|
|
||||||
self.pinout = pinout
|
|
||||||
|
|
||||||
def loop(self, from_pin, to_pin):
|
def loop(self, from_pin, to_pin):
|
||||||
self.loops.append((from_pin, to_pin))
|
self.loops.append((from_pin, to_pin))
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Cable:
|
class Cable:
|
||||||
|
name: str
|
||||||
|
mm2: float = None
|
||||||
|
awg: int = None
|
||||||
|
show_equiv: bool = False
|
||||||
|
length: float = 0
|
||||||
|
num_wires: int = None
|
||||||
|
shield: bool = False
|
||||||
|
colors: List[Any] = field(default_factory=list)
|
||||||
|
color_code: str = None
|
||||||
|
show_name: bool = False
|
||||||
|
show_pinout: bool = False
|
||||||
|
show_num_wires: bool = True
|
||||||
|
|
||||||
def __init__(self, name, mm2=None, awg=None, show_equiv=False, length=0, show_name=False, show_pinout=False, num_wires=None, show_num_wires=True, colors=None, color_code=None, shield=False):
|
def __post_init__(self):
|
||||||
self.name = name
|
if self.mm2 and self.awg:
|
||||||
if mm2 is not None and awg is not None:
|
|
||||||
raise Exception('You cannot define both mm2 and awg!')
|
raise Exception('You cannot define both mm2 and awg!')
|
||||||
self.mm2 = mm2
|
|
||||||
self.awg = awg
|
|
||||||
self.show_equiv = show_equiv
|
|
||||||
self.length = length
|
|
||||||
self.show_name = show_name
|
|
||||||
self.show_pinout = show_pinout
|
|
||||||
self.show_num_wires = show_num_wires
|
|
||||||
self.shield = shield
|
|
||||||
self.connections = []
|
self.connections = []
|
||||||
if color_code is None and colors is None:
|
|
||||||
self.colors = ('',) * num_wires
|
|
||||||
else:
|
|
||||||
if colors is None: # no custom color pallet was specified
|
|
||||||
if num_wires is None:
|
|
||||||
raise Exception('Unknown number of wires')
|
|
||||||
else:
|
|
||||||
if color_code is None:
|
|
||||||
raise Exception('No color code')
|
|
||||||
# choose color code
|
|
||||||
if color_code not in COLOR_CODES:
|
|
||||||
raise Exception('Unknown color code')
|
|
||||||
else:
|
|
||||||
cc = COLOR_CODES[color_code]
|
|
||||||
n = num_wires
|
|
||||||
else: # custom color pallet was specified
|
|
||||||
cc = colors
|
|
||||||
if num_wires is None: # assume number of wires = number of items in custom pallet
|
|
||||||
n = len(cc)
|
|
||||||
else: # number of wires was specified
|
|
||||||
n = num_wires
|
|
||||||
|
|
||||||
cc = tuple(cc)
|
if self.num_wires: # number of wires explicitly defined
|
||||||
if n > len(cc):
|
if self.colors: # use custom color palette (partly or looped if needed)
|
||||||
m = num_wires // len(cc) + 1
|
pass
|
||||||
cc = cc * int(m)
|
elif self.color_code: # use standard color palette (partly or looped if needed)
|
||||||
self.colors = cc[:n]
|
if self.color_code not in COLOR_CODES:
|
||||||
|
raise Exception('Unknown color code')
|
||||||
|
self.colors = COLOR_CODES[self.color_code]
|
||||||
|
else: # no colors defined, add dummy colors
|
||||||
|
self.colors = [''] * self.num_wires
|
||||||
|
|
||||||
|
# make color code loop around if more wires than colors
|
||||||
|
if self.num_wires > len(self.colors):
|
||||||
|
m = self.num_wires // len(self.colors) + 1
|
||||||
|
self.colors = self.colors * int(m)
|
||||||
|
# cut off excess after looping
|
||||||
|
self.colors = self.colors[:self.num_wires]
|
||||||
|
|
||||||
|
else: # num_wires implicit in length of color list
|
||||||
|
if not self.colors:
|
||||||
|
raise Exception('Unknown number of wires. Must specify num_wires or colors (implicit length)')
|
||||||
|
self.num_wires = len(self.colors)
|
||||||
|
|
||||||
def connect(self, from_name, from_pin, via_pin, to_name, to_pin):
|
def connect(self, from_name, from_pin, via_pin, to_name, to_pin):
|
||||||
from_pin = int2tuple(from_pin)
|
from_pin = int2tuple(from_pin)
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import yaml
|
import yaml
|
||||||
import wireviz
|
import wireviz
|
||||||
|
|
||||||
|
filename = '../examples/example1.yml'
|
||||||
filename = '../examples/example2.yml'
|
filename = '../examples/example2.yml'
|
||||||
|
filename = '../examples/ferrules.yml'
|
||||||
|
|
||||||
def check_designators(what, where):
|
def check_designators(what, where):
|
||||||
for i,x in enumerate(what):
|
for i, x in enumerate(what):
|
||||||
# print('Looking for {} in {}'.format(x,where[i]))
|
# print('Looking for {} in {}'.format(x,where[i]))
|
||||||
if x not in input[where[i]]:
|
if x not in input[where[i]]:
|
||||||
return False
|
return False
|
||||||
@ -45,24 +47,33 @@ with open(filename, 'r') as stream:
|
|||||||
print(exc)
|
print(exc)
|
||||||
|
|
||||||
h = wireviz.Harness()
|
h = wireviz.Harness()
|
||||||
# add nodes
|
|
||||||
for k, o in input['nodes'].items():
|
# add items
|
||||||
h.add_node(k, type=o.get('type'),
|
sections = ['nodes','wires','ferrules','connections']
|
||||||
gender=o.get('gender'),
|
types = [dict, dict, dict, list]
|
||||||
num_pins=o.get('num_pins'),
|
for sec, ty in zip(sections, types):
|
||||||
pinout=o.get('pinout'))
|
if sec in input and type(input[sec]) == ty:
|
||||||
# add wires
|
if len(input[sec]) > 0:
|
||||||
for k, o in input['wires'].items():
|
if ty == dict:
|
||||||
h.add_cable(k, mm2=o.get('mm2'),
|
for k, o in input[sec].items():
|
||||||
awg=o.get('awg'),
|
if sec == 'nodes':
|
||||||
length=o.get('length'),
|
h.add_node(name=k, **o)
|
||||||
num_wires=o.get('num_wires'),
|
elif sec == 'wires':
|
||||||
colors=o.get('colors'),
|
h.add_cable(name=k, **o)
|
||||||
color_code=o.get('color_code'),
|
elif sec == 'ferrules':
|
||||||
shield=o.get('shield'))
|
pass
|
||||||
|
else:
|
||||||
|
print('{} section empty'.format(sec))
|
||||||
|
else:
|
||||||
|
print('No {} section found'.format(sec))
|
||||||
|
if ty == dict:
|
||||||
|
input[sec] = {}
|
||||||
|
elif ty == list:
|
||||||
|
input[sec] = []
|
||||||
|
|
||||||
# add connections
|
# add connections
|
||||||
conlist = input['connections']
|
ferrule_counter = 0
|
||||||
for con in conlist:
|
for con in input['connections']:
|
||||||
if len(con) == 3: # format: connector -- wire -- conector
|
if len(con) == 3: # format: connector -- wire -- conector
|
||||||
|
|
||||||
for c in con:
|
for c in con:
|
||||||
@ -89,38 +100,79 @@ for con in conlist:
|
|||||||
elif len(con) == 2:
|
elif len(con) == 2:
|
||||||
|
|
||||||
for c in con:
|
for c in con:
|
||||||
if len(list(c.keys())) != 1: # check that each entry in con has only one key, which is the designator
|
if type(c) is dict:
|
||||||
raise Exception('Too many keys')
|
if len(list(c.keys())) != 1: # check that each entry in con has only one key, which is the designator
|
||||||
|
raise Exception('Too many keys')
|
||||||
|
|
||||||
|
# hack to make the format for ferrules compatible with the formats for connectors and wires
|
||||||
|
if type(con[0]) == str:
|
||||||
|
name = con[0]
|
||||||
|
con[0] = {}
|
||||||
|
con[0][name] = name
|
||||||
|
if type(con[1]) == str:
|
||||||
|
name = con[1]
|
||||||
|
con[1] = {}
|
||||||
|
con[1][name] = name
|
||||||
|
|
||||||
from_name = list(con[0].keys())[0]
|
from_name = list(con[0].keys())[0]
|
||||||
to_name = list(con[1].keys())[0]
|
to_name = list(con[1].keys())[0]
|
||||||
|
|
||||||
n_w = check_designators([from_name, to_name],('nodes','wires'))
|
n_w = check_designators([from_name, to_name],('nodes','wires'))
|
||||||
w_n = check_designators([from_name, to_name],('wires','nodes'))
|
w_n = check_designators([from_name, to_name],('wires','nodes'))
|
||||||
n_n = check_designators([from_name, to_name],('nodes','nodes'))
|
n_n = check_designators([from_name, to_name],('nodes','nodes'))
|
||||||
|
|
||||||
if not n_w and not w_n and not n_n:
|
|
||||||
|
f_w = check_designators([from_name, to_name],('ferrules','wires'))
|
||||||
|
w_f = check_designators([from_name, to_name],('wires','ferrules'))
|
||||||
|
|
||||||
|
if not n_w and not w_n and not n_n and not f_w and not w_f:
|
||||||
raise Exception('Wrong designators')
|
raise Exception('Wrong designators')
|
||||||
|
|
||||||
from_pins = expand(con[0][from_name])
|
from_pins = expand(con[0][from_name])
|
||||||
to_pins = expand(con[1][to_name])
|
to_pins = expand(con[1][to_name])
|
||||||
|
|
||||||
if len(from_pins) != len(to_pins):
|
if n_w or w_n or n_n:
|
||||||
raise Exception('List length mismatch')
|
if len(from_pins) != len(to_pins):
|
||||||
|
raise Exception('List length mismatch')
|
||||||
|
|
||||||
if n_w == True or w_n == True:
|
if n_w or w_n:
|
||||||
for (from_pin, to_pin) in zip(from_pins, to_pins):
|
for (from_pin, to_pin) in zip(from_pins, to_pins):
|
||||||
if n_w:
|
if n_w:
|
||||||
h.connect(from_name, from_pin, to_name, to_pin, None, None)
|
h.connect(from_name, from_pin, to_name, to_pin, None, None)
|
||||||
else: # w_n
|
else: # w_n
|
||||||
h.connect(None, None, from_name, from_pin, to_name, to_pin)
|
h.connect(None, None, from_name, from_pin, to_name, to_pin)
|
||||||
elif n_n == True:
|
elif n_n:
|
||||||
con_name = list(con[0].keys())[0]
|
con_name = list(con[0].keys())[0]
|
||||||
from_pins = expand(con[0][from_name])
|
from_pins = expand(con[0][from_name])
|
||||||
to_pins = expand(con[1][to_name])
|
to_pins = expand(con[1][to_name])
|
||||||
|
|
||||||
for (from_pin, to_pin) in zip(from_pins, to_pins):
|
for (from_pin, to_pin) in zip(from_pins, to_pins):
|
||||||
h.loop(con_name, from_pin, to_pin)
|
h.loop(con_name, from_pin, to_pin)
|
||||||
|
if f_w or w_f:
|
||||||
|
from_pins = expand(con[0][from_name])
|
||||||
|
to_pins = expand(con[1][to_name])
|
||||||
|
|
||||||
|
if f_w:
|
||||||
|
ferrule_name = from_name
|
||||||
|
wire_name = to_name
|
||||||
|
wire_pins = to_pins
|
||||||
|
else:
|
||||||
|
ferrule_name = to_name
|
||||||
|
wire_name = from_name
|
||||||
|
wire_pins = from_pins
|
||||||
|
|
||||||
|
ferrule_params = input['ferrules'][ferrule_name]
|
||||||
|
for wire_pin in wire_pins:
|
||||||
|
ferrule_counter = ferrule_counter + 1
|
||||||
|
ferrule_id = 'F{}'.format(ferrule_counter)
|
||||||
|
h.add_node(ferrule_id, **ferrule_params)
|
||||||
|
|
||||||
|
if f_w:
|
||||||
|
h.connect(ferrule_id, 1, wire_name, wire_pin, None, None)
|
||||||
|
else:
|
||||||
|
h.connect(None, None, wire_name, wire_pin, ferrule_id, 1)
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('Wrong number of connection parameters')
|
raise Exception('Wrong number of connection parameters')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user